[jboss-cvs] JBossAS SVN: r76156 - in projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test: proxy and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jul 23 21:14:58 EDT 2008
Author: ron_sigal
Date: 2008-07-23 21:14:57 -0400 (Wed, 23 Jul 2008)
New Revision: 76156
Added:
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/AddendInterceptor.java
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/FactorInterceptor.java
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/RemotingProxyFactoryTestCase.java
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface1.java
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface2.java
projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleTarget.java
Log:
JBAS-4456: New unit test.
Added: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/AddendInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/AddendInterceptor.java (rev 0)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/AddendInterceptor.java 2008-07-24 01:14:57 UTC (rev 76156)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aspects.remoting.test.proxy;
+
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 23, 2008
+ * </p>
+ */
+public final class AddendInterceptor implements org.jboss.aop.advice.Interceptor, java.io.Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 848334758912489404L;
+
+ public String getName() { return "AddendInterceptor"; }
+
+ public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable
+ {
+ if (invocation instanceof MethodInvocation)
+ {
+ MethodInvocation mi = (MethodInvocation) invocation;
+ Object[] args = mi.getArguments();
+ if (args[0] instanceof Integer)
+ {
+ int i = (Integer) args[0];
+ args[0] = i + 3;
+ mi.setArguments(args);
+ }
+ else if (args[0] instanceof String)
+ {
+ String s = (String) args[0];
+ args[0] = s + "xyz";
+ mi.setArguments(args);
+ }
+ }
+ return invocation.invokeNext();
+ }
+}
Added: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/FactorInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/FactorInterceptor.java (rev 0)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/FactorInterceptor.java 2008-07-24 01:14:57 UTC (rev 76156)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.aspects.remoting.test.proxy;
+
+import org.jboss.aop.joinpoint.MethodInvocation;
+
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jul 23, 2008
+ * </p>
+ */
+public final class FactorInterceptor implements org.jboss.aop.advice.Interceptor, java.io.Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -3545598088483755508L;
+ public static final FactorInterceptor singleton = new FactorInterceptor();
+
+ public String getName() { return "FactorInterceptor"; }
+
+ public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable
+ {
+ if (invocation instanceof MethodInvocation)
+ {
+ MethodInvocation mi = (MethodInvocation) invocation;
+ Object[] args = mi.getArguments();
+ if (args[0] instanceof Integer)
+ {
+ int i = (Integer) args[0];
+ args[0] = 2 * i;
+ mi.setArguments(args);
+ }
+ else if (args[0] instanceof String)
+ {
+ String s = (String) args[0];
+ args[0] = s + s;
+ mi.setArguments(args);
+ }
+ }
+ return invocation.invokeNext();
+ }
+}
Added: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/RemotingProxyFactoryTestCase.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/RemotingProxyFactoryTestCase.java (rev 0)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/RemotingProxyFactoryTestCase.java 2008-07-24 01:14:57 UTC (rev 76156)
@@ -0,0 +1,185 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aspects.remoting.test.proxy;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+
+
+public class RemotingProxyFactoryTestCase extends TestCase
+{
+ private static final String DEFAULT_SUFFIX_DEPLOYABLE_XML = "-beans.xml";
+ private static Logger log = Logger.getLogger(RemotingProxyFactoryTestCase.class);
+ private static boolean firstTime = true;
+
+
+ public static void main(String[] args)
+ {
+ RemotingProxyFactoryTestCase test = new RemotingProxyFactoryTestCase();
+ try
+ {
+ test.testRemotingProxy();
+ }
+ catch (Throwable e)
+ {
+ log.error("Error", e);
+ }
+ }
+
+ public void setUp() throws Exception
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
+ Logger.getLogger("org.jboss.aspects.remoting").setLevel(Level.DEBUG);
+ Logger.getLogger("org.jboss.aspects.remoting.test.proxy").setLevel(Level.DEBUG);
+ String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
+ PatternLayout layout = new PatternLayout(pattern);
+ ConsoleAppender consoleAppender = new ConsoleAppender(layout);
+ Logger.getRootLogger().addAppender(consoleAppender);
+ }
+
+ URL url = getDeployableXmlUrl(getClass());
+ new TestBootstrap().deploy(url);
+ }
+
+
+ public void tearDown()
+ {
+ }
+
+
+ public void testRemotingProxy() throws Throwable
+ {
+ log.info("entering " + getName());
+
+ String jndiName = "proxyTestJNDI";
+ Properties env = new Properties();
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
+ env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+ InitialContext ctx = new InitialContext(env);
+ System.out.println("getting SampleTarget");
+ Object o = ctx.lookup(jndiName);
+ Class<?>[] interfaces = o.getClass().getInterfaces();
+ log.info("number of proxy interfaces: " + interfaces.length);
+ for (int i = 0; i < interfaces.length; i++)
+ {
+ log.info("proxy interface[" + i + "]: " + interfaces[i]);
+ }
+ SampleInterface1 t1 = (SampleInterface1) o;
+ System.out.println("got SampleInterface1");
+ SampleInterface2 t2 = (SampleInterface2) o;
+ System.out.println("got SampleInterface2");
+ Object r1 = t1.method1(new Integer(7));
+ log.info("first response: " + r1);
+ Object r2 = t2.method2("abc");
+ log.info("second response: " + r2);
+ assertTrue(r1 instanceof Integer);
+ int i1 = (Integer) r1;
+ assertEquals(((7 * 2) + 3) * 2 + 1, i1);
+ assertTrue(r2 instanceof String);
+ String s2 = (String) r2;
+ assertEquals("abc" + "abc" + "xyz" + "|" + "abc" + "abc" + "xyz", s2);
+ log.info(getName() + " PASSES");
+ }
+
+
+ private URL getDeployableXmlUrl(Class<?> clazz) throws MalformedURLException
+ {
+ // Initialize
+// StringBuffer url = new StringBuffer(clazz.getName());
+
+ // Make a String
+ String flatten = clazz.getSimpleName().toString();
+
+ // Adjust for filename structure instead of package structure
+// flatten = flatten.replace('.', '/');
+
+ // Append Suffix
+ flatten = flatten + DEFAULT_SUFFIX_DEPLOYABLE_XML;
+
+ // Return
+// return new URL(flatten);
+ URL url = clazz.getResource(flatten);
+ return url;
+ }
+
+
+ static class TestBootstrap extends BasicBootstrap
+ {
+ private static Logger log = Logger.getLogger(TestBootstrap.class);
+
+ private BasicXMLDeployer deployer;
+ private Thread shutdownHook;
+
+ public TestBootstrap()
+ {
+ super();
+ log.debug("Starting " + this + "...");
+ run();
+
+ // Create and set an XML Deployer
+ deployer = new BasicXMLDeployer(getKernel());
+
+ // Add a shutdown hook
+ shutdownHook = new Thread()
+ {
+ public void run()
+ {
+ deployer.shutdown();
+ }
+ };
+
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+ log.info("Started: " + this);
+ }
+
+ public void deploy(URL url)
+ {
+ try
+ {
+ log.debug("Deploying " + url.toString() + "...");
+ deployer.deploy(url);
+ log.info("Deployed: " + url.toString());
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException("Could not deploy " + url.toString(), e);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface1.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface1.java (rev 0)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface1.java 2008-07-24 01:14:57 UTC (rev 76156)
@@ -0,0 +1,37 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aspects.remoting.test.proxy;
+
+/**
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 6, 2008
+ * </p>
+ */
+public interface SampleInterface1
+{
+ public Integer method1(Integer i) throws Exception;
+}
+
Added: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface2.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface2.java (rev 0)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleInterface2.java 2008-07-24 01:14:57 UTC (rev 76156)
@@ -0,0 +1,37 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aspects.remoting.test.proxy;
+
+/**
+ *
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 6, 2008
+ * </p>
+ */
+public interface SampleInterface2
+{
+ public String method2(String s) throws Exception;
+}
+
Added: projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleTarget.java
===================================================================
--- projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleTarget.java (rev 0)
+++ projects/jboss-aspects/trunk/remoting/src/test/java/org/jboss/aspects/remoting/test/proxy/SampleTarget.java 2008-07-24 01:14:57 UTC (rev 76156)
@@ -0,0 +1,50 @@
+
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.aspects.remoting.test.proxy;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author <a href="ron.sigal at jboss.com">Ron Sigal</a>
+ * @version $Revision: 1.1 $
+ * <p>
+ * Copyright Jun 6, 2008
+ * </p>
+ */
+public class SampleTarget implements SampleInterface1, SampleInterface2
+{
+ private static Logger log = Logger.getLogger(SampleTarget.class);
+
+ public Integer method1(Integer i) throws Exception
+ {
+ log.info("TestTarget processing argument: " + i);
+ return new Integer(i.intValue() * 2 + 1);
+ }
+
+ public String method2(String s) throws Exception
+ {
+ log.info("TestTarget processing argument: " + s);
+ return s + "|" + s;
+ }
+}
+
More information about the jboss-cvs-commits
mailing list