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