dain 2004/11/30 21:28:21
Modified:
modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr
AbstractCMRTest.java
Log:
Removed unnecessary MBeanServer usage
Revision Changes Path
1.3 +8 -232
openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/AbstractCMRTest.java
Index: AbstractCMRTest.java
===================================================================
RCS file:
/home/projects/openejb/scm/openejb/modules/openejb-builder/src/test/org/openejb/deployment/entity/cmp/cmr/AbstractCMRTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractCMRTest.java 10 Nov 2004 20:25:10 -0000 1.2
+++ AbstractCMRTest.java 1 Dec 2004 02:28:21 -0000 1.3
@@ -95,174 +95,87 @@
package org.openejb.deployment.entity.cmp.cmr;
-
import java.io.File;
-
import java.net.URI;
-
import java.sql.Connection;
-
import java.util.Collections;
-
import java.util.HashMap;
-
import java.util.HashSet;
-
import java.util.Set;
-
import javax.management.MalformedObjectNameException;
-
import javax.management.ObjectName;
-
import javax.sql.DataSource;
-
import javax.transaction.TransactionManager;
-
-
import junit.framework.TestCase;
-
import org.apache.geronimo.deployment.util.DeploymentUtil;
-
import org.apache.geronimo.gbean.jmx.GBeanMBean;
-
import org.apache.geronimo.j2ee.deployment.EARContext;
-
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.kernel.Kernel;
-
import org.apache.geronimo.kernel.config.ConfigurationModuleType;
-
import org.apache.geronimo.kernel.jmx.JMXUtil;
-
-import org.apache.geronimo.kernel.jmx.MBeanProxyFactory;
-
import org.apache.geronimo.naming.java.ReadOnlyContext;
-
import org.apache.geronimo.transaction.context.ContainerTransactionContext;
-
import org.apache.geronimo.xbeans.j2ee.EjbJarDocument;
-
import org.apache.geronimo.xbeans.j2ee.EjbJarType;
-
import org.apache.xmlbeans.XmlObject;
-
import org.axiondb.jdbc.AxionDataSource;
-
import org.openejb.ContainerIndex;
-
import org.openejb.deployment.CMPContainerBuilder;
-
import org.openejb.deployment.CMPEntityBuilderTestUtil;
-
import org.openejb.deployment.DeploymentHelper;
-
import org.openejb.deployment.MockConnectionProxyFactory;
-
import org.openejb.deployment.OpenEJBModuleBuilder;
-
import org.openejb.dispatch.InterfaceMethodSignature;
-
import org.openejb.security.SecurityConfiguration;
-
import org.openejb.transaction.ContainerPolicy;
-
import org.openejb.transaction.TransactionPolicy;
-
import org.openejb.transaction.TransactionPolicySource;
-
import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarDocument;
-
import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarType;
-
import org.tranql.cache.GlobalSchema;
-
import org.tranql.ejb.EJB;
-
import org.tranql.ejb.EJBSchema;
-
import org.tranql.ejb.TransactionManagerDelegate;
-
import org.tranql.sql.sql92.SQL92Schema;
-
-
-//import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
-
-
-
/**
-
- *
-
* @version $Revision$ $Date$
-
*/
-
public abstract class AbstractCMRTest extends TestCase {
-
private static final File basedir = new
File(System.getProperty("basedir", System.getProperty("user.dir")));
-
-
-
private static final String j2eeDomainName = "openejb.server";
-
private static final String j2eeServerName = "TestOpenEJBServer";
-
private static final J2eeContext j2eeContext = new
J2eeContextImpl(j2eeDomainName, j2eeServerName, NameFactory.NULL, "MockModule",
"testapp", NameFactory.J2EE_MODULE);
-
protected static final ObjectName CI_NAME =
JMXUtil.getObjectName("openejb.server:role=ContainerIndex");
-
protected static final ObjectName C_NAME_A;
-
protected static final ObjectName C_NAME_B;
static {
-
-
-
try {
-
- C_NAME_A = NameFactory.getEjbComponentName(null, null,
null,null, "A", NameFactory.ENTITY_BEAN, j2eeContext);
-
- C_NAME_B = NameFactory.getEjbComponentName(null, null,
null,null, "B", NameFactory.ENTITY_BEAN, j2eeContext);
-
+ C_NAME_A = NameFactory.getEjbComponentName(null, null, null,
null, "A", NameFactory.ENTITY_BEAN, j2eeContext);
+ C_NAME_B = NameFactory.getEjbComponentName(null, null, null,
null, "B", NameFactory.ENTITY_BEAN, j2eeContext);
} catch (MalformedObjectNameException e) {
-
throw new AssertionError(e);
-
}
-
}
protected Kernel kernel;
-
protected DataSource ds;
-
protected EJBSchema ejbSchema;
-
protected SQL92Schema sqlSchema;
-
protected GlobalSchema cacheSchema;
-
protected Object ahome;
-
protected Object bhome;
-
-
+ private TransactionManager tm;
protected ContainerTransactionContext newTransactionContext() throws
Exception {
-
return (ContainerTransactionContext)
kernel.invoke(DeploymentHelper.TRANSACTIONCONTEXTMANAGER_NAME,
"newContainerTransactionContext", null, null);
-
}
-
protected abstract void buildDBSchema(Connection c) throws Exception;
@@ -274,275 +187,138 @@
protected abstract EJBClass getB();
-
-
protected void setUp() throws Exception {
-
// MysqlDataSource mysqlDataSource = new MysqlDataSource();
-
// mysqlDataSource.setUser("geronimo");
-
// mysqlDataSource.setPassword("geronimo");
-
// mysqlDataSource.setURL("jdbc:mysql://localhost/geronimo");
-
-//
-
+//
// ds = mysqlDataSource;
-
ds = new AxionDataSource("jdbc:axiondb:testdb");
Connection c = ds.getConnection("root", null);
-
buildDBSchema(c);
-
-
kernel =
DeploymentHelper.setUpKernelWithTransactionManager("ContainerManagedPersistenceTest");
-
DeploymentHelper.setUpTimer(kernel);
-
-
- TransactionManager tm = (TransactionManager)
MBeanProxyFactory.getProxy(
-
- TransactionManager.class, kernel.getMBeanServer(),
-
- DeploymentHelper.TRANSACTIONMANAGER_NAME );
-
- TransactionManagerDelegate tmDelegate = new
TransactionManagerDelegate();
+ tm = (TransactionManager)
kernel.getProxyManager().createProxy(DeploymentHelper.TRANSACTIONMANAGER_NAME,
TransactionManager.class);
+ TransactionManagerDelegate tmDelegate = new
TransactionManagerDelegate();
tmDelegate.setTransactionManager(tm);
-
-
ejbSchema = new EJBSchema("Mock");
-
sqlSchema = new SQL92Schema("Mock", ds);
-
cacheSchema = new GlobalSchema("Mock");
-
-
File ejbJarFile = new File(basedir, getEjbJarDD());
-
File openejbJarFile = new File(basedir, getOpenEjbJarDD());
-
EjbJarType ejbJarType = ((EjbJarDocument)
XmlObject.Factory.parse(ejbJarFile)).getEjbJar();
-
OpenejbOpenejbJarType openejbJarType = ((OpenejbOpenejbJarDocument)
XmlObject.Factory.parse(openejbJarFile)).getOpenejbJar();
-
-
OpenEJBModuleBuilder moduleBuilder = new OpenEJBModuleBuilder(null,
null, null);
-
CMPEntityBuilderTestUtil builder = new
CMPEntityBuilderTestUtil(moduleBuilder);
-
File tempDir = DeploymentUtil.createTempDir();
try {
-
EARContext earContext = new EARContext(tempDir,
-
new URI("test"),
-
ConfigurationModuleType.EJB,
-
null,
-
null,
-
j2eeDomainName,
-
j2eeServerName,
-
NameFactory.NULL,
-
null,
-
null,
-
null,
-
null,
-
null);
-
-
ClassLoader cl = Thread.currentThread().getContextClassLoader();
-
builder.buildCMPSchema(earContext, j2eeContext, ejbJarType,
openejbJarType, cl, ejbSchema, sqlSchema, cacheSchema);
-
-
-
GBeanMBean containerIndex = new
GBeanMBean(ContainerIndex.GBEAN_INFO);
-
Set patterns = new HashSet();
-
patterns.add(C_NAME_A);
-
patterns.add(C_NAME_B);
-
containerIndex.setReferencePatterns("EJBContainers", patterns);
-
start(CI_NAME, containerIndex);
-
-
GBeanMBean connectionProxyFactoryGBean = new
GBeanMBean(MockConnectionProxyFactory.GBEAN_INFO);
-
ObjectName connectionProxyFactoryObjectName =
NameFactory.getResourceComponentName(null, null, null, "jcamodule", "testcf",
NameFactory.JCA_CONNECTION_FACTORY, j2eeContext);
-
kernel.loadGBean(connectionProxyFactoryObjectName,
connectionProxyFactoryGBean);
-
kernel.startGBean(connectionProxyFactoryObjectName);
-
-
setUpContainer(ejbSchema.getEJB("A"), getA().bean, getA().home,
getA().local, C_NAME_A, tmDelegate);
-
setUpContainer(ejbSchema.getEJB("B"), getB().bean, getB().home,
getB().local, C_NAME_B, tmDelegate);
-
-
ahome = kernel.getAttribute(C_NAME_A, "ejbLocalHome");
-
bhome = kernel.getAttribute(C_NAME_B, "ejbLocalHome");
-
} finally {
-
DeploymentUtil.recursiveDelete(tempDir);
-
}
-
}
-
private void setUpContainer(EJB ejb, Class beanClass, Class homeClass,
Class localClass, ObjectName containerName, TransactionManagerDelegate
tmDelegate) throws Exception {
-
CMPContainerBuilder builder = new CMPContainerBuilder();
-
builder.setClassLoader(this.getClass().getClassLoader());
-
builder.setContainerId(containerName.getCanonicalName());
-
builder.setEJBName(ejb.getName());
-
builder.setBeanClassName(beanClass.getName());
-
builder.setHomeInterfaceName(null);
-
builder.setLocalHomeInterfaceName(homeClass.getName());
-
builder.setRemoteInterfaceName(null);
-
builder.setLocalInterfaceName(localClass.getName());
-
builder.setPrimaryKeyClassName(ejb.getPrimaryKeyClass().getName());
builder.setJndiNames(new String[0]);
-
builder.setLocalJndiNames(new String[0]);
-
builder.setUnshareableResources(new HashSet());
-
builder.setTransactionPolicySource(new TransactionPolicySource() {
-
public TransactionPolicy getTransactionPolicy(String methodIntf,
InterfaceMethodSignature signature) {
-
return ContainerPolicy.Required;
-
}
-
});
builder.setSecurityConfiguration(new SecurityConfiguration());
-
builder.setEJBSchema(ejbSchema);
-
builder.setSQLSchema(sqlSchema);
-
builder.setGlobalSchema(cacheSchema);
-
builder.setComponentContext(new ReadOnlyContext());
-
// builder.setConnectionFactoryName("defaultDatasource");
-
builder.setTransactionManagerDelegate(tmDelegate);
-
builder.setQueries(new HashMap());
-
-
GBeanMBean container = builder.createConfiguration();
-
-
container.setReferencePatterns("TransactionContextManager",
Collections.singleton(DeploymentHelper.TRANSACTIONCONTEXTMANAGER_NAME));
-
container.setReferencePatterns("TrackedConnectionAssociator",
Collections.singleton(DeploymentHelper.TRACKEDCONNECTIONASSOCIATOR_NAME));
-
container.setReferencePattern("Timer",
DeploymentHelper.TRANSACTIONALTIMER_NAME);
-
start(containerName, container);
-
}
-
-
protected void tearDown() throws Exception {
-
+ kernel.getProxyManager().destroyProxy(tm);
kernel.shutdown();
-
java.sql.Connection c = ds.getConnection();
-
c.createStatement().execute("SHUTDOWN");
-
}
-
-
private void start(ObjectName name, GBeanMBean instance) throws
Exception {
-
kernel.loadGBean(name, instance);
-
kernel.startGBean(name);
-
- }
-
-
-
- private void stop(ObjectName name) throws Exception {
-
- kernel.stopGBean(name);
-
- kernel.unloadGBean(name);
-
}
-
-
protected class EJBClass {
-
public EJBClass(Class bean, Class home, Class local) {
-
this.bean = bean;
-
this.home = home;
-
this.local = local;
-
};
-
public Class bean;
-
public Class home;
-
public Class local;
-
}
-
}