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");
}
}
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");
}
}
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()));
}
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"));
}
}
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);
}
Aggregations