Search in sources :

Example 11 with EjbJar

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);
    }
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) Properties(java.util.Properties) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ManagedBean(org.apache.openejb.jee.ManagedBean) File(java.io.File) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 12 with EjbJar

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")));
}
Also used : EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 13 with EjbJar

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;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) DataSource(javax.sql.DataSource) Module(org.apache.openejb.testing.Module)

Example 14 with 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");
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) EjbModule(org.apache.openejb.config.EjbModule) Logger(org.apache.openejb.util.Logger) Properties(java.util.Properties) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) ResourceException(javax.resource.ResourceException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) SecurityException(java.lang.SecurityException) NotSupportedException(javax.resource.NotSupportedException) InvalidPropertyException(javax.resource.spi.InvalidPropertyException) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ContainerInfo(org.apache.openejb.assembler.classic.ContainerInfo) MdbContainerInfo(org.apache.openejb.assembler.classic.MdbContainerInfo) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) Ignore(org.junit.Ignore)

Example 15 with EjbJar

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;
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Aggregations

EjbJar (org.apache.openejb.jee.EjbJar)253 StatelessBean (org.apache.openejb.jee.StatelessBean)120 Assembler (org.apache.openejb.assembler.classic.Assembler)93 EjbModule (org.apache.openejb.config.EjbModule)87 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)81 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)65 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)65 Properties (java.util.Properties)52 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)52 SingletonBean (org.apache.openejb.jee.SingletonBean)49 InitialContext (javax.naming.InitialContext)44 AppModule (org.apache.openejb.config.AppModule)43 Module (org.apache.openejb.testing.Module)35 StatefulBean (org.apache.openejb.jee.StatefulBean)33 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)32 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)27 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)26 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)26 Test (org.junit.Test)26 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)22