[jboss-cvs] JBossAS SVN: r76698 - in projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test: stateless/unit and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 6 02:40:05 EDT 2008
Author: ALRubinger
Date: 2008-08-06 02:40:05 -0400 (Wed, 06 Aug 2008)
New Revision: 76698
Modified:
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java
projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/stateless/unit/StatelessContainerTestCase.java
Log:
Add further test setup support for EJB3 Core
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java 2008-08-06 05:39:35 UTC (rev 76697)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/common/AbstractEJB3TestCase.java 2008-08-06 06:40:05 UTC (rev 76698)
@@ -37,6 +37,7 @@
import org.jboss.ejb3.common.registrar.spi.Ejb3RegistrarLocator;
import org.jboss.ejb3.common.registrar.spi.NotBoundException;
import org.jboss.ejb3.session.SessionContainer;
+import org.jboss.ejb3.stateful.StatefulContainer;
import org.jboss.ejb3.stateless.StatelessContainer;
import org.jboss.ejb3.test.cachepassivation.MockDeploymentUnit;
import org.jboss.ejb3.test.cachepassivation.MockEjb3Deployment;
@@ -61,6 +62,13 @@
private static final Logger log = Logger.getLogger(AbstractEJB3TestCase.class);
private static final String DOMAIN_NAME_SLSB = "Stateless Bean";
+
+ /**
+ * Types of Containers Supported
+ */
+ enum ContainerType{
+ SFSB,SLSB
+ }
@AfterClass
public static void afterClass() throws Exception
@@ -123,14 +131,14 @@
throw new IllegalArgumentException("No such domain '" + domainName + "'");
return (Domain) domainDef.getManager();
}
-
+
/**
- * Creates and deploys a SLSB represented by the specified implementation classs
+ * Creates and deploys a Session EJB represented by the specified implementation class
*
* @param beanImplementationClass
* @return
*/
- protected static StatelessContainer deploySlsb(Class<?> beanImplementationClass)
+ public static SessionContainer deploySessionEjb(Class<?> beanImplementationClass)
{
// Obtain TCL
ClassLoader cl = Thread.currentThread().getContextClassLoader();
@@ -148,18 +156,96 @@
// Create metadata
JBossSessionBeanMetaData beanMetaData = MetaDataHelper.getMetadataFromBeanImplClass(beanImplementationClass);
-
- // Create a SLSB Container
- StatelessContainer container = null;
- try
+
+ // Ensure a Session Bean
+ assert beanMetaData.isSession() : "The specified EJB must be a Session Bean";
+
+ /*
+ * Determine type
+ */
+
+ // Initialize as SLSB
+ ContainerType type = ContainerType.SLSB;
+
+ // Set as SFSB if stateful
+ if(beanMetaData.isStateful())
{
- container = new StatelessContainer(cl, beanClassname, ejbName, domain, ctxProperties, deployment, beanMetaData);
+ type = ContainerType.SFSB;
}
- catch (ClassNotFoundException cnfe)
+
+ // Create a Session Container
+ SessionContainer container = instanciateContainer(type, cl, beanClassname, ejbName, domain, ctxProperties,
+ deployment, beanMetaData);
+
+ // Deploy and register
+ registerContainer(container);
+
+ // Return
+ return container;
+ }
+
+ /**
+ * Instanciates the appropriate SessionContainer based on the specified arguments and returns it
+ *
+ * @param type
+ * @param loader
+ * @param beanClassName
+ * @param ejbName
+ * @param domain
+ * @param ctxProperties
+ * @param deployment
+ * @param md
+ * @return
+ */
+ private static SessionContainer instanciateContainer(ContainerType type, ClassLoader loader, String beanClassName,
+ String ejbName, Domain domain, Hashtable<?, ?> ctxProperties, Ejb3Deployment deployment,
+ JBossSessionBeanMetaData md)
+ {
+ // Initialize
+ SessionContainer container = null;
+
+ /*
+ * Instanciate the Container, depending upon the type specified
+ */
+ switch (type)
{
- throw new RuntimeException("Could not create SLSB Container for " + beanClassname, cnfe);
+ case SFSB :
+ try
+ {
+ container = new StatefulContainer(loader, beanClassName, ejbName, domain, ctxProperties, deployment, md);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("Could not create SLSB Container for " + beanClassName, cnfe);
+ }
+ break;
+ case SLSB :
+ try
+ {
+ container = new StatelessContainer(loader, beanClassName, ejbName, domain, ctxProperties, deployment, md);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("Could not create SLSB Container for " + beanClassName, cnfe);
+ }
+ break;
+ default :
+ throw new UnsupportedOperationException("Only SFSB and SLSB currently supported");
}
+ // Return
+ return container;
+ }
+
+
+ /**
+ * Deploys, registers the specified Session Container
+ *
+ * @param beanImplementationClass
+ * @return
+ */
+ private static SessionContainer registerContainer(SessionContainer container)
+ {
//FIXME
// Typically these steps are done by Ejb3Deployment
container.instantiated(); //TODO: Wickeness
@@ -194,13 +280,13 @@
*
* @param container
*/
- protected static void undeployEjb(SessionContainer container)
+ public static void undeployEjb(SessionContainer container)
{
// Igonre a null container (maybe deployment did not succeed)
if (container == null)
return;
- // Unbind and call approproate lifecycle events
+ // Unbind and call appropriate lifecycle events
try
{
Ejb3RegistrarLocator.locateRegistrar().unbind(container.getObjectName().getCanonicalName());
Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/stateless/unit/StatelessContainerTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/stateless/unit/StatelessContainerTestCase.java 2008-08-06 05:39:35 UTC (rev 76697)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/core/test/stateless/unit/StatelessContainerTestCase.java 2008-08-06 06:40:05 UTC (rev 76698)
@@ -28,7 +28,7 @@
import org.jboss.ejb3.core.test.common.AbstractEJB3TestCase;
import org.jboss.ejb3.core.test.stateless.MyStateless;
import org.jboss.ejb3.core.test.stateless.MyStatelessBean;
-import org.jboss.ejb3.stateless.StatelessContainer;
+import org.jboss.ejb3.session.SessionContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -47,7 +47,7 @@
// Class Members ------------------------------------------------------------------||
// --------------------------------------------------------------------------------||
- private static StatelessContainer container;
+ private static SessionContainer container;
// --------------------------------------------------------------------------------||
// Tests --------------------------------------------------------------------------||
@@ -79,7 +79,7 @@
AbstractEJB3TestCase.beforeClass();
// Deploy the test SLSB
- container = deploySlsb(MyStatelessBean.class);
+ container = deploySessionEjb(MyStatelessBean.class);
}
@AfterClass
More information about the jboss-cvs-commits
mailing list