Search in sources :

Example 56 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class AsynchTest method testMethodScopeAsynch.

@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Test
public void testMethodScopeAsynch() throws Exception {
    System.out.println(long.class.getName());
    System.out.println(String[].class.getCanonicalName());
    // Build the application
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testasynch");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(TestBeanC.class));
    ejbJar.addEnterpriseBean(new SingletonBean(TestBeanD.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext context = new InitialContext();
    final String[] beans = new String[] { "TestBeanCLocal", "TestBeanDLocal" };
    for (final String beanName : beans) {
        final TestBean testBean = (TestBean) context.lookup(beanName);
        testBean.testA(Thread.currentThread().getId());
        Thread.sleep(1000L);
        Assert.assertEquals("testA was never executed", "testA", testBean.getLastInvokeMethod());
        final Future<String> future = testBean.testB(Thread.currentThread().getId());
        Thread.sleep(1000L);
        Assert.assertTrue("The task should be done", future.isDone());
        Assert.assertEquals("testB was never executed", "testB", testBean.getLastInvokeMethod());
        testBean.testC(Thread.currentThread().getId());
        Assert.assertEquals("testC was never executed", "testC", testBean.getLastInvokeMethod());
        testBean.testD(Thread.currentThread().getId());
        Assert.assertEquals("testD was never executed", "testD", testBean.getLastInvokeMethod());
    }
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 57 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class AsynchTest method testClassScopeAsynch.

@Test
public void testClassScopeAsynch() throws Exception {
    // Build the application
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testclassasynch");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(TestBeanA.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext context = new InitialContext();
    final TestBean test = (TestBean) context.lookup("TestBeanALocal");
    test.testA(Thread.currentThread().getId());
    Thread.sleep(1000L);
    Assert.assertEquals("testA was never executed", "testA", test.getLastInvokeMethod());
    final Future<String> future = test.testB(Thread.currentThread().getId());
    Thread.sleep(1000L);
    Assert.assertTrue("The task should be done", future.isDone());
    Assert.assertEquals("testB was never executed", "testB", test.getLastInvokeMethod());
    test.testC(Thread.currentThread().getId());
    Assert.assertEquals("testC was never executed", "testC", test.getLastInvokeMethod());
    test.testD(Thread.currentThread().getId());
    Assert.assertEquals("testD was never executed", "testD", test.getLastInvokeMethod());
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 58 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class GlobalLookupScopesTest method createApp.

private AppContext createApp(final String name, final ConfigurationFactory config, final Assembler assembler) throws OpenEJBException, IOException, javax.naming.NamingException {
    // Setup the descriptor information
    final EjbJar ejbJar = new EjbJar(name);
    ejbJar.addEnterpriseBean(new SingletonBean(Bean.class));
    // Deploy the bean a second time to simulate situations
    // where the same java:module java:app java:global names
    // are re-declared in a compatible way
    ejbJar.addEnterpriseBean(new SingletonBean("Other", Bean.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    final AppModule module = new AppModule(ejbModule);
    return assembler.createApplication(config.configureApplication(module));
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar) SingletonBean(org.apache.openejb.jee.SingletonBean)

Example 59 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class JavaLookupScopesTest method test.

public void test() throws Exception {
    final AppContext app;
    {
        final ConfigurationFactory config = new ConfigurationFactory();
        final Assembler assembler = new Assembler();
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
        // Setup the descriptor information
        final EjbJar ejbJar = new EjbJar("testmodule");
        ejbJar.addEnterpriseBean(new SingletonBean(Bean.class));
        // Deploy the bean a second time to simulate situations
        // where the same java:module java:app java:global names
        // are re-declared in a compatible way
        ejbJar.addEnterpriseBean(new SingletonBean("Other", Bean.class));
        final EjbModule ejbModule = new EjbModule(ejbJar);
        final AppModule module = new AppModule(ejbModule);
        app = assembler.createApplication(config.configureApplication(module));
    }
    final BeanContext bean = app.getBeanContexts().get(0);
    final ModuleContext module = bean.getModuleContext();
    {
        // app context lookups
        final Context context = app.getAppJndiContext();
        assertTrue(context.lookup("app") instanceof Context);
        assertTrue(context.lookup("app/AppName") instanceof String);
        assertTrue(context.lookup("app/green") instanceof DataSource);
        assertTrue(context.lookup("app/testmodule") instanceof Context);
        assertTrue(context.lookup("app/testmodule/Bean") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other!" + Bean.class.getName()) instanceof Bean);
        assertEquals("testmodule", context.lookup("app/AppName"));
    }
    {
        // module context lookups
        final Context context = module.getModuleJndiContext();
        assertTrue(context.lookup("module") instanceof Context);
        assertTrue(context.lookup("module/ModuleName") instanceof String);
        assertTrue(context.lookup("module/blue") instanceof DataSource);
        assertTrue(context.lookup("module/Bean") instanceof Bean);
        assertTrue(context.lookup("module/Bean!" + Bean.class.getName()) instanceof Bean);
        assertEquals("testmodule", context.lookup("module/ModuleName"));
    // TODO the Module JNDI context *should* be able to see the App context
    }
    {
        final Context context = bean.getJndiContext();
        assertTrue(context.lookup("comp") instanceof Context);
        assertTrue(context.lookup("comp/EJBContext") instanceof EJBContext);
        assertTrue(context.lookup("comp/TimerService") instanceof TimerService);
        assertTrue(context.lookup("comp/TransactionManager") instanceof TransactionManager);
        assertTrue(context.lookup("comp/TransactionSynchronizationRegistry") instanceof TransactionSynchronizationRegistry);
        assertTrue(context.lookup("comp/WebServiceContext") instanceof WebServiceContext);
        assertTrue(context.lookup("comp/env") instanceof Context);
        assertTrue(context.lookup("comp/env") instanceof Context);
        assertTrue(context.lookup("comp/env/orange") instanceof DataSource);
        assertTrue(context.lookup("comp/env/" + Bean.class.getName()) instanceof Context);
        assertTrue(context.lookup("comp/env/" + Bean.class.getName() + "/red") instanceof DataSource);
        assertTrue(context.lookup("module") instanceof Context);
        assertTrue(context.lookup("module/ModuleName") instanceof String);
        assertTrue(context.lookup("module/blue") instanceof DataSource);
        assertTrue(context.lookup("module/Bean") instanceof Bean);
        assertTrue(context.lookup("module/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("module/Other") instanceof Bean);
        assertTrue(context.lookup("module/Other!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("app") instanceof Context);
        assertTrue(context.lookup("app/AppName") instanceof String);
        assertTrue(context.lookup("app/green") instanceof DataSource);
        assertTrue(context.lookup("app/testmodule") instanceof Context);
        assertTrue(context.lookup("app/testmodule/Bean") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other") instanceof Bean);
        assertTrue(context.lookup("app/testmodule/Other!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("global") instanceof Context);
        assertTrue(context.lookup("global/yellow") instanceof DataSource);
        assertTrue(context.lookup("global/testmodule") instanceof Context);
        assertTrue(context.lookup("global/testmodule/Bean") instanceof Bean);
        assertTrue(context.lookup("global/testmodule/Bean!" + Bean.class.getName()) instanceof Bean);
        assertTrue(context.lookup("global/testmodule/Other") instanceof Bean);
        assertTrue(context.lookup("global/testmodule/Other!" + Bean.class.getName()) instanceof Bean);
        assertEquals("testmodule", context.lookup("app/AppName"));
        assertEquals("testmodule", context.lookup("module/ModuleName"));
    }
}
Also used : InitialContext(javax.naming.InitialContext) BeanContext(org.apache.openejb.BeanContext) ModuleContext(org.apache.openejb.ModuleContext) WebServiceContext(javax.xml.ws.WebServiceContext) AppContext(org.apache.openejb.AppContext) Context(javax.naming.Context) EJBContext(javax.ejb.EJBContext) EJBContext(javax.ejb.EJBContext) AppModule(org.apache.openejb.config.AppModule) AppContext(org.apache.openejb.AppContext) EjbModule(org.apache.openejb.config.EjbModule) WebServiceContext(javax.xml.ws.WebServiceContext) TimerService(javax.ejb.TimerService) DataSource(javax.sql.DataSource) SingletonBean(org.apache.openejb.jee.SingletonBean) BeanContext(org.apache.openejb.BeanContext) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ModuleContext(org.apache.openejb.ModuleContext) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 60 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CustomMdbContainerTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Setup the descriptor information
    EmailBean.lifecycle.clear();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
    final Connector connector = new Connector("email-ra");
    final ResourceAdapter adapter = new ResourceAdapter(EmailResourceAdapter.class);
    connector.setResourceAdapter(adapter);
    final InboundResourceadapter inbound = adapter.setInboundResourceAdapter(new InboundResourceadapter());
    final MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
    final MessageListener listener = messageAdapter.addMessageListener(new MessageListener(EmailConsumer.class, EmailAccountInfo.class));
    listener.getActivationSpec().addRequiredConfigProperty("address");
    app.getConnectorModules().add(new ConnectorModule(connector));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext initialContext = new InitialContext();
    final EmailResourceAdapter ra = (EmailResourceAdapter) initialContext.lookup("java:openejb/Resource/email-raRA");
    final Properties headers = new Properties();
    headers.put("To", "dblevins@apache.org");
    headers.put("From", "dblevins@visi.com");
    headers.put("Subject", "Hello");
    ra.deliverEmail(headers, "How's it going?");
    final Stack<Lifecycle> lifecycle = EmailBean.lifecycle;
    final List expected = Arrays.asList(Lifecycle.values());
    Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
}
Also used : Connector(org.apache.openejb.jee.Connector) AppModule(org.apache.openejb.config.AppModule) MessageListener(org.apache.openejb.jee.MessageListener) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Properties(java.util.Properties) ConnectorModule(org.apache.openejb.config.ConnectorModule) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MessageAdapter(org.apache.openejb.jee.MessageAdapter) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) Assembler(org.apache.openejb.assembler.classic.Assembler)

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)91 EjbJar (org.apache.openejb.jee.EjbJar)81 AppModule (org.apache.openejb.config.AppModule)41 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)30 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)27 Properties (java.util.Properties)24 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)20 Module (org.apache.openejb.testing.Module)18 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)13 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)13 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)11 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9