Search in sources :

Example 6 with ModuleContext

use of org.apache.openejb.ModuleContext in project tomee by apache.

the class ModulePropertiesTest method assertContexts.

private void assertContexts(final ContainerSystem containerSystem) {
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final ModuleContext moduleContext = beanContext.getModuleContext();
    final AppContext appContext = moduleContext.getAppContext();
    {
        // Assert as Properties
        // ModuleContext should have color property
        assertProperty(moduleContext.getProperties(), "color", "orange");
        // BeanContext and AppContext should not
        assertNoProperty(beanContext.getProperties(), "color");
        assertNoProperty(appContext.getProperties(), "color");
        // Try all the above again with mixed case
        assertProperty(moduleContext.getProperties(), "coLOr", "orange");
        assertNoProperty(beanContext.getProperties(), "coLOr");
        assertNoProperty(appContext.getProperties(), "coLOr");
    }
    {
        // Assert as Options
        // ModuleContext should have color option
        assertOption(moduleContext.getOptions(), "color", "orange");
        // BeanContext should inherit ModuleContext color
        assertOption(beanContext.getOptions(), "color", "orange");
        // AppContext should remain unpolluted
        assertNoOption(appContext.getOptions(), "color");
        // Try all the above again using mixed case
        assertOption(moduleContext.getOptions(), "coLoR", "orange");
        assertOption(beanContext.getOptions(), "coLoR", "orange");
        assertNoOption(appContext.getOptions(), "coLoR");
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Example 7 with ModuleContext

use of org.apache.openejb.ModuleContext in project tomee by apache.

the class BeanPropertiesTest method assertContexts.

private void assertContexts(final ContainerSystem containerSystem) {
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final ModuleContext moduleContext = beanContext.getModuleContext();
    final AppContext appContext = moduleContext.getAppContext();
    {
        // Assert as Properties
        // BeanContext should have color property
        assertProperty(beanContext.getProperties(), "color", "orange");
        // ModuleContext and AppContext should not
        assertNoProperty(moduleContext.getProperties(), "color");
        assertNoProperty(appContext.getProperties(), "color");
        // Try all the above again with mixed case
        assertProperty(beanContext.getProperties(), "coLOr", "orange");
        assertNoProperty(moduleContext.getProperties(), "coLOr");
        assertNoProperty(appContext.getProperties(), "coLOr");
    }
    {
        // Assert as Options
        // ModuleContext should have color option
        assertOption(beanContext.getOptions(), "color", "orange");
        // AppContext and ModuleContext should remain unpolluted
        assertNoOption(moduleContext.getOptions(), "color");
        assertNoOption(appContext.getOptions(), "color");
        // Try all the above again using mixed case
        assertOption(beanContext.getOptions(), "coLoR", "orange");
        assertNoOption(moduleContext.getOptions(), "coLoR");
        assertNoOption(appContext.getOptions(), "coLoR");
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Example 8 with ModuleContext

use of org.apache.openejb.ModuleContext in project tomee by apache.

the class InheritedAppExceptionTest method testRollback.

@Test
public void testRollback() throws Exception {
    SystemInstance.init(new Properties());
    final BeanContext cdi = new BeanContext("foo", null, new ModuleContext("foo", null, "bar", new AppContext("foo", SystemInstance.get(), null, null, null, false), null, null), Object.class, null, new HashMap<String, String>());
    cdi.addApplicationException(AE1.class, true, true);
    cdi.addApplicationException(AE3.class, true, false);
    cdi.addApplicationException(AE6.class, false, true);
    assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE1()));
    assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE2()));
    assertEquals(ExceptionType.APPLICATION_ROLLBACK, cdi.getExceptionType(new AE3()));
    assertEquals(ExceptionType.SYSTEM, cdi.getExceptionType(new AE4()));
    assertEquals(ExceptionType.SYSTEM, cdi.getExceptionType(new AE5()));
    assertEquals(ExceptionType.APPLICATION, cdi.getExceptionType(new AE6()));
    assertEquals(ExceptionType.APPLICATION, cdi.getExceptionType(new AE7()));
}
Also used : AppContext(org.apache.openejb.AppContext) Properties(java.util.Properties) BeanContext(org.apache.openejb.BeanContext) ModuleContext(org.apache.openejb.ModuleContext) Test(org.junit.Test)

Example 9 with ModuleContext

use of org.apache.openejb.ModuleContext 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 10 with ModuleContext

use of org.apache.openejb.ModuleContext in project tomee by apache.

the class OWBContextThreadListener method contextEntered.

@Override
public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) {
    final BeanContext beanContext = newContext.getBeanContext();
    if (beanContext == null) {
        // OWBContextHolder will be null so calling contextExited will throw a NPE
        return;
    }
    final ModuleContext moduleContext = beanContext.getModuleContext();
    // TODO its not clear what the scope for one of these context should be: ejb, module, or app
    // For now, go with the attachment of the BeanManager to AppContext
    final AppContext appContext = moduleContext.getAppContext();
    final WebBeansContext owbContext = appContext.getWebBeansContext();
    final Object oldOWBContext;
    if (owbContext != null) {
        oldOWBContext = singletonService.contextEntered(owbContext);
    } else {
        oldOWBContext = null;
    }
    final OWBContextHolder holder = new OWBContextHolder(oldOWBContext);
    newContext.set(OWBContextHolder.class, holder);
}
Also used : BeanContext(org.apache.openejb.BeanContext) WebBeansContext(org.apache.webbeans.config.WebBeansContext) AppContext(org.apache.openejb.AppContext) ModuleContext(org.apache.openejb.ModuleContext)

Aggregations

ModuleContext (org.apache.openejb.ModuleContext)15 BeanContext (org.apache.openejb.BeanContext)14 AppContext (org.apache.openejb.AppContext)13 Context (javax.naming.Context)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TimerService (javax.ejb.TimerService)2 Injection (org.apache.openejb.Injection)2 OpenEJBException (org.apache.openejb.OpenEJBException)2 IvmContext (org.apache.openejb.core.ivm.naming.IvmContext)2 Method (java.lang.reflect.Method)1 URI (java.net.URI)1 Properties (java.util.Properties)1 EJBContext (javax.ejb.EJBContext)1 TimedObject (javax.ejb.TimedObject)1 Timer (javax.ejb.Timer)1 InitialContext (javax.naming.InitialContext)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NamingException (javax.naming.NamingException)1