[jboss-cvs] JBossAS SVN: r73674 - in projects/ejb3/trunk/proxy/src: main/java/org/jboss/ejb3/proxy/jndiregistrar and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 26 01:29:07 EDT 2008


Author: ALRubinger
Date: 2008-05-26 01:29:07 -0400 (Mon, 26 May 2008)
New Revision: 73674

Added:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulLocalHome.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase.java
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase-beans.xml
Removed:
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatelfulLocalHome.java
Modified:
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/container/StatefulSessionInvokableContext.java
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateful/StatefulSessionProxyObjectFactory.java
   projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateless/StatelessSessionProxyObjectFactory.java
   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/StatefulContainer.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBean.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCaseBase.java
   projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase.java
   projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase-beans.xml
Log:
[EJBTHREE-1345] SFSB Invocations and Unit Tests working

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/container/StatefulSessionInvokableContext.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/container/StatefulSessionInvokableContext.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/container/StatefulSessionInvokableContext.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -37,7 +37,16 @@
       extends
          InvokableContext<StatefulSessionContainerMethodInvocation>
 {
+
    /**
+    * The name of the "createSession" method for use in reflection
+    */
+   String METHOD_NAME_CREATESESSION = "createSession";
+
+   String[] METHOD_SIGNATURE_CREATESESSION = new String[]
+   {};
+
+   /**
     * Creates a new user session and returns the unique Session ID
     * 
     * @return

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/jndiregistrar/JndiSessionRegistrarBase.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -124,6 +124,17 @@
       // Set the Proxy Object Factory Type
       assert sessionProxyObjectFactoryType != null && !sessionProxyObjectFactoryType.equals("") : "Session EJB Proxy "
             + ObjectFactory.class.getSimpleName() + " must be specified.";
+
+      try
+      {
+         // See if the specified Session Proxy Object Factory is valid
+         Class.forName(sessionProxyObjectFactoryType);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new RuntimeException("Specified " + ObjectFactory.class.getSimpleName() + " of "
+               + sessionProxyObjectFactoryType + " could not be loaded.", e);
+      }
       this.setSessionProxyObjectFactoryType(sessionProxyObjectFactoryType);
       log.debug("Using Session EJB JNDI " + ObjectFactory.class.getSimpleName() + ": "
             + this.getSessionProxyObjectFactoryType());

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateful/StatefulSessionProxyObjectFactory.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateful/StatefulSessionProxyObjectFactory.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateful/StatefulSessionProxyObjectFactory.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -21,6 +21,8 @@
  */
 package org.jboss.ejb3.proxy.objectfactory.session.stateful;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
 import java.util.List;
 import java.util.Map;
 
@@ -30,7 +32,7 @@
 import org.jboss.ejb3.common.registrar.spi.NotBoundException;
 import org.jboss.ejb3.proxy.container.StatefulSessionInvokableContext;
 import org.jboss.ejb3.proxy.factory.ProxyFactory;
-import org.jboss.ejb3.proxy.intf.StatefulSessionProxy;
+import org.jboss.ejb3.proxy.handler.session.stateful.StatefulProxyInvocationHandler;
 import org.jboss.ejb3.proxy.objectfactory.session.SessionProxyObjectFactory;
 
 /**
@@ -55,8 +57,7 @@
    // --------------------------------------------------------------------------------||
 
    /**
-    * SFSB Object Factories must always create a new SFSB Proxy with every lookup, 
-    * set a new Session ID as obtained by the SFSB Container, and return.
+    * SFSB Object Factories must always create a new SFSB Proxy
     * 
     * @param proxyFactory The ProxyFactory to use
     * @param name The JNDI name looked up
@@ -65,41 +66,35 @@
    @Override
    protected Object getProxy(ProxyFactory proxyFactory, Name name, Map<String, List<String>> referenceAddresses)
    {
-      // Get the Proxy from the Super Implementation
+      // Create a new Proxy Instance
       Object proxy = this.createProxy(proxyFactory, name, referenceAddresses);
 
-      // Get the Container Name
-      String containerName = this.getContainerName(name, referenceAddresses);
+      // Obtain the InvocationHandler
+      InvocationHandler handler = Proxy.getInvocationHandler(proxy);
+      assert handler instanceof StatefulProxyInvocationHandler : "SFSB Proxy must be of type "
+            + StatefulProxyInvocationHandler.class.getName();
+      StatefulProxyInvocationHandler sHandler = (StatefulProxyInvocationHandler) handler;
 
-      // Get the Container
-      Object obj = null;
+      // Get a new Session ID from the Container
+      String containerName = sHandler.getContainerName();
+      Object sessionId = null;
       try
       {
-         obj = Ejb3RegistrarLocator.locateRegistrar().lookup(containerName);
+         sessionId = Ejb3RegistrarLocator.locateRegistrar().invoke(containerName,
+               StatefulSessionInvokableContext.METHOD_NAME_CREATESESSION, null,
+               StatefulSessionInvokableContext.METHOD_SIGNATURE_CREATESESSION);
       }
       catch (NotBoundException e)
       {
-         throw new RuntimeException("Found reference to EJB Container with name " + containerName
-               + " but it could not be found in the object store", e);
+         throw new RuntimeException("Could not obtain a new Session ID from SFSB Container with name \""
+               + containerName + "\"", e);
       }
-      assert obj instanceof StatefulSessionInvokableContext : "Object found registered under name " + containerName
-            + " must be of type " + StatefulSessionInvokableContext.class.getName() + " but was instead " + obj;
-      StatefulSessionInvokableContext<?> container = (StatefulSessionInvokableContext<?>) obj;
 
-      // Create a Session ID from the Container
-      Object sessionId = container.createSession();
+      // Set the Session ID on the Proxy
+      sHandler.setSessionId(sessionId);
 
-      // Ensure Proxy is of expected type
-      assert proxy instanceof StatefulSessionProxy : "Proxy " + proxy + " must be of type "
-            + StatefulSessionProxy.class.getName();
-
-      // Cast
-      StatefulSessionProxy sProxy = (StatefulSessionProxy) proxy;
-
-      // Set the Session ID
-      sProxy.setSessionId(sessionId);
-
-      // Return
+      // Return the Proxy
       return proxy;
    }
+
 }

Modified: projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateless/StatelessSessionProxyObjectFactory.java
===================================================================
--- projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateless/StatelessSessionProxyObjectFactory.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/main/java/org/jboss/ejb3/proxy/objectfactory/session/stateless/StatelessSessionProxyObjectFactory.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -46,6 +46,10 @@
 
    private static final long serialVersionUID = 1L;
 
+   // --------------------------------------------------------------------------------||
+   // Required Implementations -------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
    /*
     * TODO
     * 

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-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/SessionContainer.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -124,31 +124,38 @@
     */
    public Object invoke(Object proxy, SerializableMethod method, Object[] args) throws Throwable
    {
-      // Get the types from the arguments
-      List<Class<?>> types = new ArrayList<Class<?>>();
-      for (Object arg : args)
+      // Initialize
+      Class<?>[] argTypes = new Class<?>[]
+      {};
+
+      // Get the types from the arguments, if present
+      if (args != null)
       {
-         types.add(arg.getClass());
+         List<Class<?>> types = new ArrayList<Class<?>>();
+         for (Object arg : args)
+         {
+            types.add(arg.getClass());
+         }
+         argTypes = types.toArray(new Class<?>[]
+         {});
       }
-      Class<?>[] argTypes = types.toArray(new Class<?>[]
-      {});
 
       // Obtain the method for invocation
       Method m = this.getClassLoader().loadClass(method.getClassName()).getDeclaredMethod(method.getName(), argTypes);
 
       // Invoke on the bean
-      return invokeBean(m, args);
+      return invokeBean(proxy, m, args);
    }
 
-   private Object createInstance() throws InstantiationException, IllegalAccessException
+   protected Object createInstance() throws InstantiationException, IllegalAccessException
    {
       return this.getBeanClass().newInstance();
    }
 
-   public Object invokeBean(Method method, Object args[]) throws Throwable
+   public Object invokeBean(Object proxy, Method method, Object args[]) throws Throwable
    {
-      // Mock up a new instance, traditionally this would be obtained from a Pool
-      Object obj = createInstance();
+      // Get the appropriate instance
+      Object obj = this.getBeanInstance(proxy);
 
       // Invoke
       return method.invoke(obj, args);
@@ -235,6 +242,15 @@
     */
    protected abstract String getJndiRegistrarBindName();
 
+   /**
+    * Obtains the appropriate bean instance for invocation
+    * as called from the specified proxy
+    * 
+    * @param proxy
+    * @return
+    */
+   protected abstract Object getBeanInstance(Object proxy);
+
    // --------------------------------------------------------------------------------||
    // Accessors / Mutators -----------------------------------------------------------||
    // --------------------------------------------------------------------------------||

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatefulContainer.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -21,11 +21,14 @@
  */
 package org.jboss.ejb3.test.proxy.common.container;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
 import org.jboss.ejb3.proxy.container.StatefulSessionInvokableContext;
+import org.jboss.ejb3.proxy.handler.session.stateful.StatefulProxyInvocationHandler;
 import org.jboss.ejb3.proxy.invocation.StatefulSessionContainerMethodInvocation;
 import org.jboss.ejb3.proxy.objectstore.ObjectStoreBindings;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
@@ -84,7 +87,7 @@
       Object instance = null;
       try
       {
-         instance = this.getBeanClass().newInstance();
+         instance = this.createInstance();
       }
       catch (Throwable t)
       {
@@ -119,6 +122,34 @@
       return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SFSB;
    }
 
+   /**
+    * Obtains the appropriate bean instance for invocation
+    * as called from the specified proxy
+    * 
+    * @param proxy
+    * @return
+    */
+   protected Object getBeanInstance(Object proxy)
+   {
+      // Obtain the InvocationHandler
+      InvocationHandler handler = Proxy.getInvocationHandler(proxy);
+      assert handler instanceof StatefulProxyInvocationHandler : "SFSB Proxy must be of type "
+            + StatefulProxyInvocationHandler.class.getName();
+      StatefulProxyInvocationHandler sHandler = (StatefulProxyInvocationHandler) handler;
+
+      // Get the Session ID
+      Object sessionId = sHandler.getSessionId();
+      assert sessionId != null : "Proxy has no Session ID set, and this is required for SFSB Invocation";
+
+      // Get the corresponding instance from the cache
+      Object bean = this.getCache().get(sessionId);
+      assert bean != null : "SFSB Proxy claims Session ID of " + sessionId
+            + ", but no corresponding bean instance could be found";
+
+      // Return
+      return bean;
+   }
+
    // --------------------------------------------------------------------------------||
    // Accessors / Mutators -----------------------------------------------------------||
    // --------------------------------------------------------------------------------||

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/container/StatelessContainer.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -61,4 +61,24 @@
    {
       return ObjectStoreBindings.OBJECTSTORE_BEAN_NAME_JNDI_REGISTRAR_SLSB;
    }
+
+   /**
+    * Obtains the appropriate bean instance for invocation
+    * as called from the specified proxy
+    * 
+    * @param proxy
+    * @return
+    */
+   protected Object getBeanInstance(Object proxy)
+   {
+      // Typically this would be obtained from a Pool
+      try
+      {
+         return this.createInstance();
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error in creating new SLSB Bean Instance", t);
+      }
+   }
 }

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBean.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBean.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulBean.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -34,7 +34,7 @@
  * @version $Revision: $
  */
 @Stateful
- at LocalHome(MyStatelfulLocalHome.class)
+ at LocalHome(MyStatefulLocalHome.class)
 @RemoteHome(MyStatefulRemoteHome.class)
 public class MyStatefulBean implements MyStatefulLocalBusiness, MyStatefulRemoteBusiness
 {

Copied: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulLocalHome.java (from rev 73670, projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatelfulLocalHome.java)
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulLocalHome.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatefulLocalHome.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -0,0 +1,35 @@
+/*
+ * 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.sfsb;
+
+import javax.ejb.EJBLocalHome;
+
+/**
+ * MyStatefulLocalHome
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public interface MyStatefulLocalHome extends EJBLocalHome
+{
+   MyStateful21Local create();
+}

Deleted: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatelfulLocalHome.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatelfulLocalHome.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/common/ejb/sfsb/MyStatelfulLocalHome.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -1,35 +0,0 @@
-/*
- * 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.sfsb;
-
-import javax.ejb.EJBLocalHome;
-
-/**
- * MyStatelfulLocalHome
- *
- * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
- * @version $Revision: $
- */
-public interface MyStatelfulLocalHome extends EJBLocalHome
-{
-   MyStateful21Local create();
-}

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCaseBase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCaseBase.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxySessionTestCaseBase.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -24,12 +24,6 @@
 import org.jboss.ejb3.common.registrar.plugin.mc.Ejb3McRegistrar;
 import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
 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.StatelessContainer;
-import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessBean;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 
 /**
  * ProxySessionTestCaseBase
@@ -46,16 +40,12 @@
    // Class Members ------------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
-   private static EmbeddedTestMcBootstrap bootstrap;
+   protected static EmbeddedTestMcBootstrap bootstrap;
 
    // --------------------------------------------------------------------------------||
    // Lifecycle Methods --------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
-   /**
-    * @throws java.lang.Exception
-    */
-   @BeforeClass
    public static void setUpBeforeClass() throws Throwable
    {
       bootstrap = new EmbeddedTestMcBootstrap();
@@ -63,34 +53,5 @@
 
       // Bind the Registrar
       Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel()));
-
-      bootstrap.deploy(ProxyStatelessSessionTestCase.class);
-
-      // Create a SLSB
-      StatelessContainer container = Utils.createSlsb(MyStatelessBean.class);
-
-      // Install into MC
-      bootstrap.installInstance(container.getName(), container);
    }
-
-   /**
-    * @throws java.lang.Exception
-    */
-   @AfterClass
-   public static void tearDownAfterClass() throws Exception
-   {
-      if (bootstrap != null)
-         bootstrap.shutdown();
-      bootstrap = null;
-   }
-
-   // --------------------------------------------------------------------------------||
-   // Contracts ----------------------------------------------------------------------||
-   // --------------------------------------------------------------------------------||
-
-   /**
-    * Creates and returns a new Session Container
-    */
-   protected abstract SessionContainer createContainer() throws Throwable;
-
 }

Added: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -0,0 +1,194 @@
+/*
+ * 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.session.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
+import org.jboss.ejb3.test.proxy.common.Utils;
+import org.jboss.ejb3.test.proxy.common.container.StatefulContainer;
+import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulBean;
+import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulLocalBusiness;
+import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulLocalHome;
+import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulRemoteBusiness;
+import org.jboss.ejb3.test.proxy.common.ejb.sfsb.MyStatefulRemoteHome;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * ProxyStatefulSessionTestCase
+ * 
+ * Test Cases to ensure proper invocation of SFSBs
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ProxyStatefulSessionTestCase extends ProxySessionTestCaseBase
+{
+
+   // --------------------------------------------------------------------------------||
+   // Class Members ------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * JNDI Context
+    */
+   private static Context context;
+
+   // --------------------------------------------------------------------------------||
+   // Tests --------------------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Test Local Business Binding and Invocation
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testLocalBusiness() throws Exception
+   {
+
+      // Obtain the Proxy
+      Object bean = ProxyStatefulSessionTestCase.context.lookup("MyStatefulBean/local");
+      assertTrue("Bean must be assignable to " + MyStatefulLocalBusiness.class.getSimpleName() + " but was instead "
+            + bean.getClass(), bean instanceof MyStatefulLocalBusiness);
+
+      // Invoke and Test Result
+      int result = ((MyStatefulLocalBusiness) bean).getNextCounter();
+      assertEquals(result, 0);
+   }
+
+   /**
+    * Test Remote Business Binding and Invocation
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testRemoteBusiness() throws Exception
+   {
+
+      // Obtain the Proxy
+      Object bean = ProxyStatefulSessionTestCase.context.lookup("MyStatefulBean/remote");
+      assertTrue("Bean must be assignable to " + MyStatefulRemoteBusiness.class.getSimpleName() + " but was instead "
+            + bean.getClass(), bean instanceof MyStatefulRemoteBusiness);
+
+      // Invoke and Test Result
+      int result = ((MyStatefulRemoteBusiness) bean).getNextCounter();
+      assertEquals(result, 0);
+   }
+
+   /**
+    * Test Local Home Binding
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testLocalHome() throws Exception
+   {
+      Object bean = ProxyStatefulSessionTestCase.context.lookup("MyStatefulBean/localHome");
+      assertTrue(bean instanceof MyStatefulLocalHome);
+   }
+
+   /**
+    * Test Remote Home Binding
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testRemoteHome() throws Exception
+   {
+      Object bean = ProxyStatefulSessionTestCase.context.lookup("MyStatefulBean/home");
+      assertTrue(bean instanceof MyStatefulRemoteHome);
+   }
+
+   /**
+    * Tests that SFSB Proxies invoke within
+    * the scope of their own session only
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testSessionScoping() throws Exception
+   {
+      // Lookup 2 Instances
+      MyStatefulLocalBusiness bean1 = (MyStatefulLocalBusiness) ProxyStatefulSessionTestCase.context
+            .lookup("MyStatefulBean/local");
+      MyStatefulLocalBusiness bean2 = (MyStatefulLocalBusiness) ProxyStatefulSessionTestCase.context
+            .lookup("MyStatefulBean/local");
+
+      // Invoke continuously on instance one 10 times to ensure that the SFSB counter increments properly
+      for (int counter = 0; counter < 10; counter++)
+      {
+         // Invoke
+         int result = bean1.getNextCounter();
+         TestCase.assertEquals("SFSB invocations should have memory of the session", counter, result);
+      }
+
+      // Invoke once on instance two to ensure its scope is separate from that of instance one
+      TestCase
+            .assertEquals("SFSB Session Scopes must not be shared between Proxy instances", 0, bean2.getNextCounter());
+   }
+
+   // --------------------------------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
+   // --------------------------------------------------------------------------------||
+
+   /**
+    * Perform setup before any tests
+    * 
+    * @throws Throwable
+    */
+   @BeforeClass
+   public static void setUpBeforeClass() throws Throwable
+   {
+      // Create Bootstrap 
+      ProxySessionTestCaseBase.setUpBeforeClass();
+
+      // Deploy MC Beans
+      ProxyStatefulSessionTestCase.bootstrap.deploy(ProxyStatefulSessionTestCase.class);
+
+      // Create a SLSB
+      StatefulContainer container = Utils.createSfsb(MyStatefulBean.class);
+
+      // Install
+      Ejb3RegistrarLocator.locateRegistrar().bind(container.getName(), container);
+
+      // Create JNDI Context
+      ProxyStatefulSessionTestCase.context = new InitialContext(); // Props from CP jndi.properties
+
+   }
+
+   @AfterClass
+   public static void tearDownAfterClass() throws Exception
+   {
+      if (bootstrap != null)
+         bootstrap.shutdown();
+      bootstrap = null;
+   }
+}

Modified: projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase.java
===================================================================
--- projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase.java	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/java/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase.java	2008-05-26 05:29:07 UTC (rev 73674)
@@ -26,13 +26,16 @@
 
 import javax.naming.InitialContext;
 
+import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
 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.StatelessContainer;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessBean;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocal;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessLocalHome;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemote;
 import org.jboss.ejb3.test.proxy.common.ejb.slsb.MyStatelessRemoteHome;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -86,14 +89,36 @@
    }
 
    // --------------------------------------------------------------------------------||
-   // Required Implementations -------------------------------------------------------||
+   // Lifecycle Methods --------------------------------------------------------------||
    // --------------------------------------------------------------------------------||
 
    /**
-    * Creates and returns a new Session Container
+    * Perform setup before any tests
+    * 
+    * @throws Throwable
     */
-   protected SessionContainer createContainer() throws Throwable
+   @BeforeClass
+   public static void setUpBeforeClass() throws Throwable
    {
-      return Utils.createSlsb(MyStatelessBean.class);
+      // Create Bootstrap and Deploy
+      ProxySessionTestCaseBase.setUpBeforeClass();
+
+      // Deploy MC Beans
+      ProxyStatelessSessionTestCase.bootstrap.deploy(ProxyStatelessSessionTestCase.class);
+
+      // Create a SLSB
+      StatelessContainer container = Utils.createSlsb(MyStatelessBean.class);
+
+      // Install
+      Ejb3RegistrarLocator.locateRegistrar().bind(container.getName(), container);
+
    }
+   
+   @AfterClass
+   public static void tearDownAfterClass() throws Exception
+   {
+      if (bootstrap != null)
+         bootstrap.shutdown();
+      bootstrap = null;
+   }
 }

Added: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase-beans.xml	                        (rev 0)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatefulSessionTestCase-beans.xml	2008-05-26 05:29:07 UTC (rev 73674)
@@ -0,0 +1,47 @@
+<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
+    
+    
+    The JNDI Registrar is responsible for all JNDI Bindings for
+    an EJB.  Its constructor takes the following arguments, in order:
+    
+    javax.naming.Context (JNDI Context into which to bind objects)
+    org.jboss.ejb3.proxy.spi.registry.ProxyFactoryRegistry (Implementation of ProxyFactoryRegistry)
+    String statelessSessionProxyObjectFactoryType The JNDI ObjectFactory implementation to use for SLSB
+    ...more later when SFSB, @Service, MDB Implemented
+    
+  -->
+
+  <!-- SFSB JNDI Registrar -->
+  <bean name="org.jboss.ejb3.JndiRegistrar.Session.SFSBJndiRegistrar"
+    class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatefulSessionRegistrar">
+    <constructor>
+      <parameter>
+        <inject bean="org.jboss.ejb3.JndiContext" />
+      </parameter>
+      <parameter>
+        org.jboss.ejb3.proxy.objectfactory.session.stateful.StatefulSessionProxyObjectFactory
+      </parameter>
+    </constructor>
+    <depends>NameServer</depends>
+  </bean>
+
+  <!-- JNDI Registrar Configuration -->
+  <bean name="org.jboss.ejb3.JndiContext"
+    class="javax.naming.InitialContext" />
+
+</deployment>
\ No newline at end of file

Modified: projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase-beans.xml
===================================================================
--- projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase-beans.xml	2008-05-26 00:36:10 UTC (rev 73673)
+++ projects/ejb3/trunk/proxy/src/test/resources/org/jboss/ejb3/test/proxy/session/unit/ProxyStatelessSessionTestCase-beans.xml	2008-05-26 05:29:07 UTC (rev 73674)
@@ -40,20 +40,6 @@
     <depends>NameServer</depends>
   </bean>
 
-  <!-- SFSB JNDI Registrar -->
-  <bean name="org.jboss.ejb3.JndiRegistrar.Session.SFSBJndiRegistrar"
-    class="org.jboss.ejb3.proxy.jndiregistrar.JndiStatefulSessionRegistrar">
-    <constructor>
-      <parameter>
-        <inject bean="org.jboss.ejb3.JndiContext" />
-      </parameter>
-      <parameter>
-        org.jboss.ejb3.proxy.objectfactory.session.stateless.StatefulSessionProxyObjectFactory
-      </parameter>
-    </constructor>
-    <depends>NameServer</depends>
-  </bean>
-
   <!-- JNDI Registrar Configuration -->
   <bean name="org.jboss.ejb3.JndiContext"
     class="javax.naming.InitialContext" />




More information about the jboss-cvs-commits mailing list