use of org.apache.openejb.config.AppModule in project tomee by apache.
the class AsynchInRoleTest 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 Properties env = new Properties();
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "jonathan");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "secret");
final InitialContext context = new InitialContext(env);
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());
context.close();
}
use of org.apache.openejb.config.AppModule in project tomee by apache.
the class AsynchInRoleTest method testMethodScopeAsynch.
@Test
public void testMethodScopeAsynch() throws Exception {
// 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 Properties env = new Properties();
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "jonathan");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "secret");
final InitialContext context = new InitialContext(env);
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());
}
context.close();
}
use of org.apache.openejb.config.AppModule 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.AppModule 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.AppModule 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));
}
Aggregations