[jboss-cvs] JBossAS SVN: r76848 - in projects/ejb3/trunk/proxy/src/test: java/org/jboss/ejb3/test/proxy/common/container/unit and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Aug 9 06:55:15 EDT 2008


Author: jaikiran
Date: 2008-08-09 06:55:15 -0400 (Sat, 09 Aug 2008)
New Revision: 76848

Added:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/unit/
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBLocal.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBean.java
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/container/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/container/unit/
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase-beans.xml
Modified:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java
Log:
EJBTHREE-1453 Invoking a bean method which accepts a superclass param throws NoSuchMethodException

The (mock) SessionContainer.invoke threw 

1) NoSuchMethodException - When the object passed as a param to a bean method, was subclass of what the bean method accepted in its signature.
2) NullPointerException - When an NULL object was passed as a param to the bean method.

The fix involved, changing the implementation of SessionContainer.invoke to do away with the Java Reflection API usage and instead use the SerializableMethod.toMethod API. Appropriate test cases have also been commited.


Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java	2008-08-08 21:08:56 UTC (rev 76847)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java	2008-08-09 10:55:15 UTC (rev 76848)
@@ -25,9 +25,7 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -168,26 +166,8 @@
     */
    public Object invoke(Object proxy, SerializableMethod method, Object[] args) throws Throwable
    {
-      // Initialize
-      Class<?>[] argTypes = new Class<?>[]
-      {};
+      Method m = method.toMethod(this.getClassLoader());
 
-      // Get the types from the arguments, if present
-      if (args != null)
-      {
-         List<Class<?>> types = new ArrayList<Class<?>>();
-         for (Object arg : args)
-         {
-            types.add(arg.getClass());
-         }
-         argTypes = types.toArray(new Class<?>[]
-         {});
-      }
-
-      // Obtain the method for invocation
-      Method m = this.getClassLoader().loadClass(method.getDeclaringClassName()).getDeclaredMethod(method.getName(),
-            argTypes);
-
       // Invoke on the bean
       return invokeBean(proxy, m, args);
    }

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase.java	2008-08-09 10:55:15 UTC (rev 76848)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.proxy.common.container.unit;
+
+import static org.junit.Assert.assertNotNull;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.common.registrar.spi.NotBoundException;
+import org.jboss.ejb3.test.mc.bootstrap.EmbeddedTestMcBootstrap;
+import org.jboss.ejb3.test.proxy.common.Utils;
+import org.jboss.ejb3.test.proxy.common.container.SessionContainer;
+import org.jboss.ejb3.test.proxy.common.container.StatefulContainer;
+import org.jboss.ejb3.test.proxy.common.container.StatelessContainer;
+import org.jboss.ejb3.test.proxy.common.ejb.slsb.SimpleSLSBLocal;
+import org.jboss.ejb3.test.proxy.common.ejb.slsb.SimpleSLSBean;
+import org.jboss.ejb3.test.proxy.jndiregistrar.unit.JndiSessionRegistrarBaseTestCase;
+import org.jboss.logging.Logger;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test case for {@link SessionContainer}
+ * 
+ * SessionContainerTestCase
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class SessionContainerTestCase
+{
+
+   /**
+    * Bootstrap
+    */
+   private static EmbeddedTestMcBootstrap bootstrap;
+
+   /**
+    * The {@link SessionContainer} which is instantiated by each test. Depending
+    * on the test, its either a {@link StatefulContainer} or a {@link StatelessContainer}
+    */
+   private SessionContainer sessionContainer;
+
+   /**
+    * Instance of logger
+    */
+   private static Logger logger = Logger.getLogger(SessionContainerTestCase.class);
+
+   /**
+    * Initializes the required services
+    * 
+    * @throws Throwable
+    */
+   @BeforeClass
+   public static void setUpBeforeClass() throws Throwable
+   {
+      bootstrap = new EmbeddedTestMcBootstrap();
+      bootstrap.run();
+
+      // Bind the Registrar
+      Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel()));
+
+      bootstrap.deploy(JndiSessionRegistrarBaseTestCase.class);
+
+   }
+
+   /**
+    * Shutdown the services
+    * 
+    * @throws Throwable
+    */
+   @AfterClass
+   public static void tearDownAfterClass() throws Throwable
+   {
+      if (bootstrap != null)
+      {
+         bootstrap.shutdown();
+      }
+      bootstrap = null;
+   }
+
+   /**
+    * This method takes care of any cleanup required after each test.
+    */
+   @After
+   public void cleanupAfterEachTest()
+   {
+
+      if (sessionContainer != null)
+      {
+         logger.info("Unbinding: " + sessionContainer.getName());
+         try
+         {
+            Ejb3RegistrarLocator.locateRegistrar().unbind(sessionContainer.getName());
+         }
+         catch (NotBoundException nbe)
+         {
+            // we are ok with this exception, which indicates that the test case had 
+            // already unbound the ejb related bindings.
+            logger.debug(sessionContainer.getName() + " was already unbound");
+
+         }
+      }
+
+   }
+
+   /**
+    * Test the {@link SessionContainer#invoke(Object, org.jboss.ejb3.common.lang.SerializableMethod, Object[])}
+    * method.
+    * 
+    * This test will check the invoke method by passing different "types" of parameters
+    * to a bean's method. Ex: Pass a subclass param when the bean method accepts a superclass
+    * param
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBeanMethodInvocation() throws Throwable
+   {
+      // create the SLSB container
+      this.sessionContainer = Utils.createSlsb(SimpleSLSBean.class);
+
+      // bind to JNDI
+      Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer);
+
+      Context ctx = new InitialContext();
+      // lookup the local bean
+      String localJndiName = sessionContainer.getMetaData().getLocalJndiName();
+      SimpleSLSBLocal local = (SimpleSLSBLocal) ctx.lookup(localJndiName);
+
+      assertNotNull("Local bean is null", local);
+
+      //call the method with various different parameters
+      Object object = new String("I am some object");
+      String string = new String("AnotherString");
+
+      // method which accepts object/string
+      local.printObject(object);
+      local.printObject(string);
+      // now pass an java.lang.Integer
+      local.printObject(new Integer(34));
+      // no param method
+      local.noop();
+      // method with return type
+      int i = local.someMethodWithReturnType();
+      // method with multiple different type of params
+      local.printMultipleObjects(string, 2, 2.3f, new Float(34.2), 44.2d, new Double(22.234));
+
+   }
+
+   /**
+    * 
+    * Test the {@link SessionContainer#invoke(Object, org.jboss.ejb3.common.lang.SerializableMethod, Object[])}
+    * method.
+    * 
+    * This test will check the invoke method by passing null value to the bean methods.
+    * The intention of this test case is to ensure that there are no exceptions (especially
+    * {@link NullPointerException} when the params being passed to bean methods are null)
+    * 
+    * @throws Throwable
+    */
+   @Test
+   public void testBeanMethodInvocationForNullParams() throws Throwable
+   {
+      // create the SLSB container
+      this.sessionContainer = Utils.createSlsb(SimpleSLSBean.class);
+
+      // bind to JNDI
+      Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer);
+
+      Context ctx = new InitialContext();
+      // lookup the local bean
+      String localJndiName = sessionContainer.getMetaData().getLocalJndiName();
+      SimpleSLSBLocal local = (SimpleSLSBLocal) ctx.lookup(localJndiName);
+
+      assertNotNull("Local bean is null", local);
+
+      // pass null to some params
+      local.printMultipleObjects("hello", 2, 2.2f, null, 3.2, new Double(4.4));
+      // pass null
+      local.printObject(null);
+      // pass null to all object params
+      local.printMultipleObjects(null, 0, 0.0f, null, 0.0, null);
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBLocal.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBLocal.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBLocal.java	2008-08-09 10:55:15 UTC (rev 76848)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.proxy.common.ejb.slsb;
+
+/**
+ * 
+ * SimpleSLSBLocal
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface SimpleSLSBLocal
+{
+   void printObject(Object obj);
+   
+   int someMethodWithReturnType();
+   
+   void printObject(String string);
+   
+   void printMultipleObjects(String string, int val, float f, Float objF, double d, Double objD);
+   
+   void noop();
+
+}

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBean.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBean.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/slsb/SimpleSLSBean.java	2008-08-09 10:55:15 UTC (rev 76848)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.ejb3.test.proxy.common.ejb.slsb;
+
+import javax.ejb.Local;
+import javax.ejb.Stateless;
+
+import org.jboss.logging.Logger;
+
+
+
+
+/**
+ * 
+ * SimpleSLSBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+ at Local (SimpleSLSBLocal.class)
+public class SimpleSLSBean implements SimpleSLSBLocal
+{
+   
+   /**
+    * Instance of logger
+    */
+   private static Logger logger = Logger.getLogger(SimpleSLSBean.class);
+
+   public void printObject(Object obj)
+   {
+      logger.info("Printing an object ---> " + obj);
+    
+   }
+
+   public void printMultipleObjects(String string, int val, float f, Float objF, double d, Double objD)
+   {
+      // No need to do anything
+      
+      
+   }
+
+   public void printObject(String string)
+   {
+      logger.info("Printing a string ---> " + string);
+      
+   }
+
+   public int someMethodWithReturnType()
+   {
+      // just return some value
+      return -1;
+   }
+
+   public void noop()
+   {
+      // do nothing
+      
+   }
+
+}

Added: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase-beans.xml	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/common/container/unit/SessionContainerTestCase-beans.xml	2008-08-09 10:55:15 UTC (rev 76848)
@@ -0,0 +1,72 @@
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+  xmlns="urn:jboss:bean-deployer:2.0">
+
+  <!-- 
+    
+    JNDI 
+    
+    The requisite Naming Server
+    
+  -->
+  <bean name="NameServer" class="org.jnp.server.SingletonNamingServer" />
+
+  <!-- 
+    
+    JNDI Registrars
+    
+  -->
+
+  <!-- SLSB JNDI Registrar -->
+  <bean name="org.jboss.ejb3.JndiRegistrar.Session.SLSBJndiRegistrar"
+    class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatelessSessionRegistrar">
+    <constructor>
+      <parameter>
+        org.jboss.ejb3.proxy.objectfactory.session.stateless.StatelessSessionProxyObjectFactory
+      </parameter>
+    </constructor>
+    <depends>NameServer</depends>
+  </bean>
+  
+  <!-- SFSB JNDI Registrar -->
+  <bean name="org.jboss.ejb3.JndiRegistrar.Session.SFSBJndiRegistrar"
+    class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatefulSessionRegistrar">
+    <constructor>
+      <parameter>
+        org.jboss.ejb3.proxy.objectfactory.session.stateful.StatefulSessionProxyObjectFactory
+      </parameter>
+    </constructor>
+    <depends>NameServer</depends>
+  </bean>
+
+  <!-- 
+    
+    Remoting
+    
+  -->
+
+  <!-- Remoting  Configuration -->
+  <bean name="ServerConfiguration"
+    class="org.jboss.remoting.ServerConfiguration">
+    <property name="invocationHandlers">
+      <map keyClass="java.lang.String" valueClass="java.lang.String">
+        <entry>
+          <key>AOP</key>
+          <value>
+            org.jboss.aspects.remoting.AOPRemotingInvocationHandler
+          </value>
+        </entry>
+      </map>
+    </property>
+  </bean>
+
+  <!-- Remoting Connector -->
+  <bean name="Connector"
+    class="org.jboss.remoting.transport.Connector">
+    <property name="invokerLocator">socket://0.0.0.0:3873</property>
+    <property name="serverConfiguration">
+      <inject bean="ServerConfiguration" />
+    </property>
+  </bean>
+
+</deployment>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list