dain 2005/02/10 01:38:32
Added: modules/openejb-builder/src/test/org/openejb/deployment
AbstractDeploymentTest.java
DeploymentTestContants.java
DeploymentTestSuite.java EarDeploymentTest.java
EjbJarModuleDeploymentTest.java
UnpackedModuleDeploymentTest.java
Removed: modules/openejb-builder/src/test/org/openejb/deployment
EJBConfigBuilderTest.java
Log:
Rework the serialization code a bit
Changed EJBConfigbuilderTest so the verifiy method is broken into several
test method
Revision Changes Path
1.1
openejb/modules/openejb-builder/src/test/org/openejb/deployment/AbstractDeploymentTest.java
Index: AbstractDeploymentTest.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment;
import java.util.Set;
import javax.ejb.EJBHome;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.management.State;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/10 06:38:32 $
*/
public abstract class AbstractDeploymentTest extends TestCase implements
DeploymentTestContants {
public abstract Kernel getKernel();
public abstract ClassLoader getApplicationClassLoader();
public abstract String getJ2eeApplicationName();
public abstract String getJ2eeModuleName();
public void testEJBModuleObject() throws Exception {
ObjectName moduleName = ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=EJBModule,J2EEServer=" + SERVER_NAME + ",J2EEApplication=" +
getJ2eeApplicationName() + ",name=" + getJ2eeModuleName());
assertRunning(getKernel(), moduleName);
}
public void testApplicationObject() throws Exception {
ObjectName applicationObjectName = ObjectName.getInstance(DOMAIN_NAME
+ ":j2eeType=J2EEApplication,name=" + getJ2eeApplicationName() + ",J2EEServer="
+ SERVER_NAME);
if (!getJ2eeApplicationName().equals("null")) {
assertRunning(getKernel(), applicationObjectName);
} else {
Set applications = getKernel().listGBeans(applicationObjectName);
assertTrue("No application object should be registered for a
standalone module", applications.isEmpty());
}
}
public void testStatelessContainer() throws Exception {
ObjectName statelessBeanName = ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=StatelessSessionBean,J2EEServer=" + SERVER_NAME +
",J2EEApplication=" + getJ2eeApplicationName() + ",EJBModule=" +
getJ2eeModuleName() + ",name=SimpleStatelessSession");
assertRunning(getKernel(), statelessBeanName);
// use reflection to invoke a method on the stateless bean, because
we don't have access to the classes here
Object statelessHome = getKernel().getAttribute(statelessBeanName,
"ejbHome");
assertTrue("Home is not an instance of EJBHome", statelessHome
instanceof EJBHome);
Object stateless = statelessHome.getClass().getMethod("create",
null).invoke(statelessHome, null);
assertEquals("TestResult", stateless.getClass().getMethod("echo", new
Class[]{String.class}).invoke(stateless, new Object[]{"TestResult"}));
Object statelessLocalHome =
getKernel().getAttribute(statelessBeanName, "ejbLocalHome");
Object statelessLocal =
statelessLocalHome.getClass().getMethod("create",
null).invoke(statelessLocalHome, null);
statelessLocal.getClass().getMethod("startTimer",
null).invoke(statelessLocal, null);
Thread.sleep(200L);
assertEquals(new Integer(1),
statelessLocal.getClass().getMethod("getTimeoutCount",
null).invoke(statelessLocal, null));
// TODO causes ClassCastException
// EJBProxyReference proxyReference =
EJBProxyReference.createRemote(statelessBeanName.getCanonicalName(),
// true,
//
"org.openejb.test.simple.slsb.SimpleStatelessSession",
//
"org.openejb.test.simple.slsb.SimpleStatelessSessionHome");
// proxyReference.setKernel(getKernel());
// proxyReference.setClassLoader(getApplicationClassLoader());
// statelessHome = proxyReference.getContent();
// assertTrue("Home is not an instance of EJBHome", statelessHome
instanceof EJBHome);
// stateless = statelessHome.getClass().getMethod("create",
null).invoke(statelessHome, null);
// assertEquals("TestResult", stateless.getClass().getMethod("echo",
new Class[]{String.class}).invoke(stateless, new Object[]{"TestResult"}));
}
public void testStatefulContainer() throws Exception {
ObjectName statefulBeanName = ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=StatefulSessionBean,J2EEServer=" + SERVER_NAME + ",J2EEApplication="
+ getJ2eeApplicationName() + ",EJBModule=" + getJ2eeModuleName() +
",name=SimpleStatefulSession");
assertRunning(getKernel(), statefulBeanName);
Object statefulHome = getKernel().getAttribute(statefulBeanName,
"ejbHome");
assertTrue("Home is not an instance of EJBHome", statefulHome
instanceof EJBHome);
Object stateful = statefulHome.getClass().getMethod("create",
null).invoke(statefulHome, null);
stateful.getClass().getMethod("setValue", new
Class[]{String.class}).invoke(stateful, new Object[]{"SomeValue"});
assertEquals("SomeValue", stateful.getClass().getMethod("getValue",
null).invoke(stateful, null));
}
public void testBMPContainer() throws Exception {
ObjectName bmpBeanName = ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=EntityBean,J2EEServer=" + SERVER_NAME + ",J2EEApplication=" +
getJ2eeApplicationName() + ",EJBModule=" + getJ2eeModuleName() +
",name=SimpleBMPEntity");
assertRunning(getKernel(), bmpBeanName);
Object bmpHome = getKernel().getAttribute(bmpBeanName, "ejbHome");
assertTrue("Home is not an instance of EJBHome", bmpHome instanceof
EJBHome);
Object bmp = bmpHome.getClass().getMethod("create",
null).invoke(bmpHome, null);
bmp.getClass().getMethod("setName", new
Class[]{String.class}).invoke(bmp, new Object[]{"MyNameValue"});
assertEquals("MyNameValue", bmp.getClass().getMethod("getName",
null).invoke(bmp, null));
}
public void testCMPContainer() throws Exception {
ObjectName cmpBeanName = ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=EntityBean,J2EEServer=" + SERVER_NAME + ",J2EEApplication=" +
getJ2eeApplicationName() + ",EJBModule=" + getJ2eeModuleName() +
",name=SimpleCMPEntity");
assertRunning(getKernel(), cmpBeanName);
Object cmpHome = getKernel().getAttribute(cmpBeanName, "ejbHome");
assertTrue("Home is not an instance of EJBHome", cmpHome instanceof
EJBHome);
Object cmp = cmpHome.getClass().getMethod("create", new
Class[]{Integer.class}).invoke(cmpHome, new Object[]{new Integer(42)});
cmp.getClass().getMethod("setFirstName", new
Class[]{String.class}).invoke(cmp, new Object[]{"MyFistName"});
assertEquals("MyFistName", cmp.getClass().getMethod("getFirstName",
null).invoke(cmp, null));
}
public void testMDBContainer() throws Exception {
ObjectName mdbBeanName = ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=MessageDrivenBean,J2EEServer=" + SERVER_NAME + ",J2EEApplication=" +
getJ2eeApplicationName() + ",EJBModule=" + getJ2eeModuleName() +
",name=SimpleMessageDriven");
assertRunning(getKernel(), mdbBeanName);
}
public static void assertRunning(Kernel kernel, ObjectName objectName)
throws Exception {
int state = ((Integer) kernel.getAttribute(objectName,
"state")).intValue();
assertEquals("should be running: " + objectName, State.RUNNING_INDEX,
state);
}
}
1.1
openejb/modules/openejb-builder/src/test/org/openejb/deployment/DeploymentTestContants.java
Index: DeploymentTestContants.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment;
import java.net.URI;
import java.util.Map;
import java.util.List;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import javax.naming.Reference;
import javax.xml.namespace.QName;
import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
import org.apache.geronimo.j2ee.deployment.ResourceReferenceBuilder;
import org.apache.geronimo.j2ee.deployment.ServiceReferenceBuilder;
import org.apache.geronimo.j2ee.deployment.Module;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.deployment.DeploymentContext;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/10 06:38:32 $
*/
public interface DeploymentTestContants {
public static final ObjectName CONFIGURATION_OBJECT_NAME =
IGNORE.createConfigurationObjectName();
public static final ObjectName CONNECTION_OBJECT_NAME =
IGNORE.createConnectionObjectName();
public static final String DOMAIN_NAME = "test";
public static final String SERVER_NAME = "bar";
public static final ResourceReferenceBuilder resourceReferenceBuilder =
new ResourceReferenceBuilder() {
public Reference createResourceRef(String containerId, Class iface) {
return null;
}
public Reference createAdminObjectRef(String containerId, Class
iface) {
return null;
}
public ObjectName locateResourceName(ObjectName query) {
return DeploymentHelper.RESOURCE_ADAPTER_NAME;
}
public GBeanData locateActivationSpecInfo(ObjectName
resourceAdapterModuleName, String messageListenerInterface) {
return DeploymentHelper.ACTIVATION_SPEC_INFO;
}
public GBeanData locateResourceAdapterGBeanData(ObjectName
resourceAdapterModuleName) {
return null;
}
public GBeanData locateAdminObjectInfo(ObjectName
resourceAdapterModuleName, String adminObjectInterfaceName) {
return null;
}
public GBeanData locateConnectionFactoryInfo(ObjectName
resourceAdapterModuleName, String connectionFactoryInterfaceName) {
return null;
}
};
public static final ServiceReferenceBuilder serviceReferenceBuilder = new
ServiceReferenceBuilder() {
//it could return a Service or a Reference, we don't care
public Object createService(Class serviceInterface, URI wsdlURI, URI
jaxrpcMappingURI, QName serviceQName, Map portComponentRefMap, List handlers,
DeploymentContext deploymentContext, Module module, ClassLoader classLoader) {
return null;
}
};
public static class IGNORE {
private static ObjectName createConfigurationObjectName() {
try {
return
Configuration.getConfigurationObjectName(URI.create("test-ejb-jar"));
} catch (MalformedObjectNameException e) {
return null;
}
}
private static ObjectName createConnectionObjectName() {
try {
J2eeContext j2eeContext = new J2eeContextImpl(DOMAIN_NAME,
SERVER_NAME, NameFactory.NULL, "testejbmodule", "testapp",
NameFactory.J2EE_APPLICATION);
return NameFactory.getResourceComponentName(null, null,
NameFactory.NULL, "org/apache/geronimo/DefaultDatabase", "DefaultDatasource",
NameFactory.JCA_MANAGED_CONNECTION_FACTORY, j2eeContext);
} catch (MalformedObjectNameException e) {
return null;
}
}
}
}
1.1
openejb/modules/openejb-builder/src/test/org/openejb/deployment/DeploymentTestSuite.java
Index: DeploymentTestSuite.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.Connection;
import java.sql.Statement;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarFile;
import javax.management.ObjectName;
import javax.sql.DataSource;
import junit.extensions.TestDecorator;
import junit.framework.Protectable;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.apache.geronimo.deployment.util.DeploymentUtil;
import org.apache.geronimo.gbean.GBeanData;
import org.apache.geronimo.j2ee.deployment.EARConfigBuilder;
import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl;
import org.apache.geronimo.kernel.GBeanNotFoundException;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.management.State;
import org.apache.geronimo.system.serverinfo.ServerInfo;
import org.openejb.ContainerIndex;
import org.openejb.corba.compiler.OpenORBSkeletonGenerator;
import org.tranql.sql.jdbc.JDBCUtil;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/10 06:38:32 $
*/
public class DeploymentTestSuite extends TestDecorator implements
DeploymentTestContants {
private final File moduleFile;
private File tempDir;
private Kernel kernel;
private DataSource dataSource;
private ClassLoader applicationClassLoader;
protected DeploymentTestSuite(Class testClass, File moduleFile) {
super(new TestSuite(testClass));
this.moduleFile = moduleFile;
}
public Kernel getKernel() {
return kernel;
}
public ClassLoader getApplicationClassLoader() {
return applicationClassLoader;
}
public void run(final TestResult result) {
Protectable p = new Protectable() {
public void protect() throws Exception {
try {
setUp();
basicRun(result);
} finally {
tearDown();
}
}
};
result.runProtected(this, p);
}
private void setUp() throws Exception {
ClassLoader testClassLoader = getClass().getClassLoader();
String str =
System.getProperty(javax.naming.Context.URL_PKG_PREFIXES);
if (str == null) {
str = ":org.apache.geronimo.naming";
} else {
str = str + ":org.apache.geronimo.naming";
}
System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, str);
kernel = DeploymentHelper.setUpKernelWithTransactionManager();
DeploymentHelper.setUpTimer(kernel);
ObjectName serverInfoObjectName = ObjectName.getInstance(DOMAIN_NAME
+ ":type=ServerInfo");
GBeanData serverInfoGBean = new GBeanData(serverInfoObjectName,
ServerInfo.GBEAN_INFO);
serverInfoGBean.setAttribute("baseDirectory", ".");
kernel.loadGBean(serverInfoGBean, testClassLoader);
kernel.startGBean(serverInfoObjectName);
assertRunning(kernel, serverInfoObjectName);
ObjectName j2eeServerObjectName = ObjectName.getInstance(DOMAIN_NAME
+ ":j2eeType=J2EEServer,name=" + SERVER_NAME);
GBeanData j2eeServerGBean = new GBeanData(j2eeServerObjectName,
J2EEServerImpl.GBEAN_INFO);
j2eeServerGBean.setReferencePatterns("ServerInfo",
Collections.singleton(serverInfoObjectName));
kernel.loadGBean(j2eeServerGBean, testClassLoader);
kernel.startGBean(j2eeServerObjectName);
assertRunning(kernel, j2eeServerObjectName);
//load mock resource adapter for mdb
DeploymentHelper.setUpResourceAdapter(kernel);
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
applicationClassLoader = new URLClassLoader(new
URL[]{moduleFile.toURL()}, oldCl);
Thread.currentThread().setContextClassLoader(applicationClassLoader);
try {
OpenORBSkeletonGenerator skeletonGenerator = new
OpenORBSkeletonGenerator(applicationClassLoader);
skeletonGenerator.doStart();
OpenEJBModuleBuilder moduleBuilder = new
OpenEJBModuleBuilder(KernelHelper.DEFAULT_PARENTID, skeletonGenerator, null);
tempDir = DeploymentUtil.createTempDir();
EARConfigBuilder earConfigBuilder = new
EARConfigBuilder(KernelHelper.DEFAULT_PARENTID,
DeploymentHelper.TRANSACTIONCONTEXTMANAGER_NAME,
DeploymentHelper.TRACKEDCONNECTIONASSOCIATOR_NAME,
DeploymentHelper.TRANSACTIONALTIMER_NAME,
DeploymentHelper.NONTRANSACTIONALTIMER_NAME,
null, // repository
moduleBuilder,
moduleBuilder,
null,// web
null, resourceReferenceBuilder, // connector
null, // app client
serviceReferenceBuilder,
kernel
);
JarFile jarFile = null;
try {
jarFile =DeploymentUtil.createJarFile(moduleFile);
Object plan = earConfigBuilder.getDeploymentPlan(null,
jarFile);
earConfigBuilder.buildConfiguration(plan, jarFile, tempDir);
} finally {
if (jarFile != null) {
jarFile.close();
}
}
// start the configuration
GBeanData config = new GBeanData();
InputStream in = new FileInputStream(new File(tempDir,
"META-INF/config.ser"));
try {
ObjectInputStream ois = new ObjectInputStream(new
BufferedInputStream(in));
config.readExternal(ois);
} finally {
in.close();
}
config.setName(CONFIGURATION_OBJECT_NAME);
config.setAttribute("baseURL", tempDir.toURL());
config.setAttribute("parentID", KernelHelper.DEFAULT_PARENTID);
ObjectName containerIndexObjectName =
ObjectName.getInstance(DOMAIN_NAME + ":type=ContainerIndex");
GBeanData containerIndexGBean = new
GBeanData(containerIndexObjectName, ContainerIndex.GBEAN_INFO);
Set ejbContainerNames = new HashSet();
ejbContainerNames.add(ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=StatelessSessionBean,*"));
ejbContainerNames.add(ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=StatefulSessionBean,*"));
ejbContainerNames.add(ObjectName.getInstance(DOMAIN_NAME +
":j2eeType=EntityBean,*"));
containerIndexGBean.setReferencePatterns("EJBContainers",
ejbContainerNames);
kernel.loadGBean(containerIndexGBean, applicationClassLoader);
kernel.startGBean(containerIndexObjectName);
assertRunning(kernel, containerIndexObjectName);
GBeanData connectionProxyFactoryGBean = new
GBeanData(CONNECTION_OBJECT_NAME, MockConnectionProxyFactory.GBEAN_INFO);
kernel.loadGBean(connectionProxyFactoryGBean,
applicationClassLoader);
kernel.startGBean(CONNECTION_OBJECT_NAME);
assertRunning(kernel, CONNECTION_OBJECT_NAME);
dataSource = (DataSource) kernel.invoke(CONNECTION_OBJECT_NAME,
"$getResource");
Connection connection = null;
Statement statement = null;
try {
connection = dataSource.getConnection();
statement = connection.createStatement();
statement.execute("CREATE TABLE SIMPLECMP(ID INTEGER,
FIRSTNAME VARCHAR(50), LASTNAME VARCHAR(50))");
} finally {
JDBCUtil.close(statement);
JDBCUtil.close(connection);
}
// load the configuration
kernel.loadGBean(config, applicationClassLoader);
// start the configuration
kernel.startRecursiveGBean(CONFIGURATION_OBJECT_NAME);
assertRunning(kernel, CONFIGURATION_OBJECT_NAME);
} catch (Error e) {
DeploymentUtil.recursiveDelete(tempDir);
throw e;
} catch (Exception e) {
DeploymentUtil.recursiveDelete(tempDir);
throw e;
} finally {
Thread.currentThread().setContextClassLoader(oldCl);
}
}
private void tearDown() throws Exception {
try {
kernel.stopGBean(CONFIGURATION_OBJECT_NAME);
} catch (GBeanNotFoundException ignored) {
}
try {
kernel.stopGBean(CONNECTION_OBJECT_NAME);
} catch (GBeanNotFoundException ignored) {
}
DeploymentUtil.recursiveDelete(tempDir);
try {
DeploymentHelper.tearDownAdapter(kernel);
} catch (Exception ignored) {
}
try {
kernel.shutdown();
} catch (Exception ignored) {
}
kernel = null;
if (dataSource != null) {
Connection connection = null;
Statement statement = null;
try {
connection = dataSource.getConnection();
statement = connection.createStatement();
statement.execute("SHUTDOWN");
} finally {
JDBCUtil.close(statement);
JDBCUtil.close(connection);
dataSource = null;
}
}
}
private static void assertRunning(Kernel kernel, ObjectName objectName)
throws Exception {
int state = ((Integer) kernel.getAttribute(objectName,
"state")).intValue();
assertEquals("should be running: " + objectName, State.RUNNING_INDEX,
state);
}
}
1.1
openejb/modules/openejb-builder/src/test/org/openejb/deployment/EarDeploymentTest.java
Index: EarDeploymentTest.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment;
import java.io.File;
import junit.framework.Test;
import org.apache.geronimo.kernel.Kernel;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/10 06:38:32 $
*/
public class EarDeploymentTest extends AbstractDeploymentTest {
private static final DeploymentTestSuite SUITE =
new DeploymentTestSuite(EarDeploymentTest.class, new
File("target/test-ear.ear"));
public static Test suite() {
return SUITE;
}
public String getJ2eeApplicationName() {
return "org/apache/geronimo/j2ee/deployment/test";
}
public String getJ2eeModuleName() {
return "test-ejb-jar.jar";
}
public Kernel getKernel() {
return SUITE.getKernel();
}
public ClassLoader getApplicationClassLoader() {
return SUITE.getApplicationClassLoader();
}
}
1.1
openejb/modules/openejb-builder/src/test/org/openejb/deployment/EjbJarModuleDeploymentTest.java
Index: EjbJarModuleDeploymentTest.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment;
import java.io.File;
import junit.framework.Test;
import org.apache.geronimo.kernel.Kernel;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/10 06:38:32 $
*/
public class EjbJarModuleDeploymentTest extends AbstractDeploymentTest {
private static final DeploymentTestSuite SUITE =
new DeploymentTestSuite(EjbJarModuleDeploymentTest.class, new
File("target/test-ejb-jar.jar"));
public static Test suite() {
return SUITE;
}
public String getJ2eeApplicationName() {
return "null";
}
public String getJ2eeModuleName() {
return "org/openejb/deployment/test";
}
public Kernel getKernel() {
return SUITE.getKernel();
}
public ClassLoader getApplicationClassLoader() {
return SUITE.getApplicationClassLoader();
}
}
1.1
openejb/modules/openejb-builder/src/test/org/openejb/deployment/UnpackedModuleDeploymentTest.java
Index: UnpackedModuleDeploymentTest.java
===================================================================
/* ====================================================================
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce this list of
* conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "OpenEJB" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of The OpenEJB Group. For written permission,
* please contact [EMAIL PROTECTED]
*
* 4. Products derived from this Software may not be called "OpenEJB"
* nor may "OpenEJB" appear in their names without prior written
* permission of The OpenEJB Group. OpenEJB is a registered
* trademark of The OpenEJB Group.
*
* 5. Due credit should be given to the OpenEJB Project
* (http://openejb.org/).
*
* THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the OpenEJB Project. For more information
* please see <http://openejb.org/>.
*
* ====================================================================
*/
package org.openejb.deployment;
import java.io.File;
import junit.framework.Test;
import org.apache.geronimo.kernel.Kernel;
/**
* @version $Revision: 1.1 $ $Date: 2005/02/10 06:38:32 $
*/
public class UnpackedModuleDeploymentTest extends AbstractDeploymentTest {
private static final DeploymentTestSuite SUITE =
new DeploymentTestSuite(UnpackedModuleDeploymentTest.class, new
File("target/test-ejb-jar"));
public static Test suite() {
return SUITE;
}
public String getJ2eeApplicationName() {
return "null";
}
public String getJ2eeModuleName() {
return "org/openejb/deployment/test";
}
public Kernel getKernel() {
return SUITE.getKernel();
}
public ClassLoader getApplicationClassLoader() {
return SUITE.getApplicationClassLoader();
}
}