use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class OutputGeneratedDescriptorsTest method testOutputDescriptor.
@Test
public void testOutputDescriptor() throws Exception {
final OutputGeneratedDescriptors dynamicDeployer = new OutputGeneratedDescriptors();
final EjbJar ejbJar = new EjbJar();
final StatelessBean redBean = new StatelessBean();
redBean.setEjbClass("com.foo.Red");
redBean.setEjbName("Red");
redBean.setRemote("com.foo.Color");
final ManagedBean orangeBean = new ManagedBean("Orange", "com.foo.Orange");
final StatefulBean yellowBean = new StatefulBean();
yellowBean.setEjbClass("com.foo.Yellow");
yellowBean.setEjbName("Yellow");
yellowBean.setRemote("com.foo.Color");
final SingletonBean greenBean = new SingletonBean();
greenBean.setEjbClass("com.foo.Green");
greenBean.setEjbName("Green");
greenBean.setRemote("com.foo.Color");
ejbJar.addEnterpriseBean(redBean);
ejbJar.addEnterpriseBean(orangeBean);
ejbJar.addEnterpriseBean(yellowBean);
ejbJar.addEnterpriseBean(greenBean);
final OpenejbJar openejbJar = new OpenejbJar();
final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
final AppModule appModule = new AppModule(ejbModule);
File tempFolder = File.createTempFile("tmp", "ogd");
tempFolder.delete();
Assert.assertTrue("unable to create temp folder", tempFolder.mkdirs());
try {
Properties properties = ejbModule.getOpenejbJar().getProperties();
properties.setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "true");
properties.setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS_FOLDER, tempFolder.getAbsolutePath());
SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS_FOLDER, tempFolder.getAbsolutePath());
dynamicDeployer.deploy(appModule);
boolean seenEjbJarXml = false;
boolean seenOpenejbJarXml = false;
File[] listFiles = tempFolder.listFiles();
for (File file : listFiles) {
if (file.getName().startsWith("ejb-jar-")) {
seenEjbJarXml = true;
assertEjbFileCorrect(file);
}
if (file.getName().startsWith("openejb-jar-")) {
seenOpenejbJarXml = true;
}
}
Assert.assertTrue("No ejb-jar.xml file produced", seenEjbJarXml);
Assert.assertTrue("No openejb-jar.xml file produced", seenOpenejbJarXml);
} finally {
// clean up temporary folder
Files.delete(tempFolder);
}
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class ReadDescriptorsTest method testReadCmpOrmDescriptor.
@Test
public void testReadCmpOrmDescriptor() throws Exception {
final EjbModule ejbModule = new EjbModule(new EjbJar());
ejbModule.getAltDDs().put("openejb-cmp-orm.xml", getClass().getResource("test-openejb-cmp-orm.xml"));
new ReadDescriptors().readCmpOrm(ejbModule);
Assert.assertNotNull(ejbModule.getAltDDs().get("openejb-cmp-orm.xml"));
Assert.assertTrue(EntityMappings.class.isInstance(ejbModule.getAltDDs().get("openejb-cmp-orm.xml")));
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class XmlDataSourceTest method app.
@Module
public EjbJar app() {
final EjbJar ejbJar = new EjbJar();
final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(Bean.class));
final org.apache.openejb.jee.DataSource ds = new org.apache.openejb.jee.DataSource();
ds.setName("java:comp/env/foo");
ds.setUrl("jdbc:hsqldb:mem:override");
ds.setClassName("org.hsqldb.jdbcDriver");
statelessBean.getDataSourceMap().put("foo", ds);
return ejbJar;
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class AutoConnectionTrackerTest method test.
@Ignore
public void test() throws Exception {
System.setProperty("openejb.log.async", "false");
final Logger logger = Logger.getInstance(LogCategory.OPENEJB_CONNECTOR, AutoConnectionTrackerTest.class);
logger.info("Starting test");
final java.util.logging.Logger julLogger = LogManager.getLogManager().getLogger(LogCategory.OPENEJB_CONNECTOR.getName());
final LogCaptureHandler logCapture = new LogCaptureHandler();
julLogger.addHandler(logCapture);
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
// System services
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// JMS persistence datasource
final ResourceInfo dataSourceInfo = config.configureService("Default Unmanaged JDBC Database", ResourceInfo.class);
dataSourceInfo.properties.setProperty("JdbcUrl", "jdbc:hsqldb:mem:MdbConfigTest");
assembler.createResource(dataSourceInfo);
// FakeRA
final ResourceInfo resourceInfo = new ResourceInfo();
resourceInfo.service = "Resource";
resourceInfo.className = FakeRA.class.getName();
resourceInfo.id = "FakeRA";
resourceInfo.properties = new Properties();
assembler.createResource(resourceInfo);
// FakeRA container
final ContainerInfo containerInfo = config.configureService(MdbContainerInfo.class);
containerInfo.id = "FakeContainer";
containerInfo.displayName = "Fake Container";
containerInfo.properties.setProperty("ResourceAdapter", "FakeRA");
containerInfo.properties.setProperty("MessageListenerInterface", FakeMessageListener.class.getName());
containerInfo.properties.setProperty("ActivationSpecClass", FakeActivationSpec.class.getName());
assembler.createContainer(containerInfo);
// Fake connection factory
final ResourceInfo mcfResourceInfo = new ResourceInfo();
mcfResourceInfo.className = FakeManagedConnectionFactory.class.getName();
mcfResourceInfo.id = "FakeConnectionFactory";
mcfResourceInfo.types = Collections.singletonList(FakeConnectionFactory.class.getName());
mcfResourceInfo.properties = new Properties();
mcfResourceInfo.properties.setProperty("ResourceAdapter", "FakeRA");
mcfResourceInfo.properties.setProperty("TransactionSupport", "None");
mcfResourceInfo.properties.setProperty("allConnectionsEqual", "false");
assembler.createResource(mcfResourceInfo);
// generate ejb jar application
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean("TestBean", FakeStatelessBean.class));
final EjbModule ejbModule = new EjbModule(getClass().getClassLoader(), "FakeEjbJar", "fake.jar", ejbJar, null);
// configure and deploy it
final EjbJarInfo info = config.configureApplication(ejbModule);
assembler.createEjbJar(info);
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final FakeConnectionFactory cf = (FakeConnectionFactory) containerSystem.getJNDIContext().lookup("openejb:Resource/FakeConnectionFactory");
final FakeRemote bean = (FakeRemote) containerSystem.getJNDIContext().lookup("java:global/FakeEjbJar/FakeEjbJar/TestBean!org.apache.openejb.resource.AutoConnectionTrackerTest$FakeRemote");
{
logCapture.clear();
runTest(new Runnable() {
@Override
public void run() {
try {
bean.nonLeakyTxMethod();
System.gc();
} catch (Exception e) {
e.printStackTrace();
}
}
});
System.gc();
cf.getConnection().close();
assertLogs(logCapture, 0, "Transaction complete, but connection still has handles associated");
assertLogs(logCapture, 0, "Detected abandoned connection");
assertTrue(getConnectionCount((FakeConnectionFactoryImpl) cf) > 0);
}
{
logCapture.clear();
runTest(new Runnable() {
@Override
public void run() {
try {
bean.nonleakyNonTxMethod();
} catch (Exception e) {
e.printStackTrace();
}
}
});
System.gc();
cf.getConnection().close();
assertLogs(logCapture, 0, "Transaction complete, but connection still has handles associated");
assertLogs(logCapture, 0, "Detected abandoned connection");
assertTrue(getConnectionCount((FakeConnectionFactoryImpl) cf) > 0);
}
{
logCapture.clear();
bean.leakyTxMethod();
System.gc();
final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl) cf);
tracker.setEnvironment(null, null);
assertLogs(logCapture, 1, "Transaction complete, but connection still has handles associated");
assertLogs(logCapture, 1, "Detected abandoned connection");
}
{
logCapture.clear();
bean.leakyNonTxMethod();
System.gc();
final AutoConnectionTracker tracker = getAutoConnectionTracker((FakeConnectionFactoryImpl) cf);
tracker.setEnvironment(null, null);
assertLogs(logCapture, 1, "Detected abandoned connection");
}
}
use of org.apache.openejb.jee.EjbJar in project tomee by apache.
the class ThirdSLSBeanTest method module.
@Module
public EjbJar module() {
final EjbJar ejbJar = new EjbJar();
final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(ThirdSLSBean.class));
final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
return ejbJar;
}
Aggregations