use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class JTAPuAndBmtTest method app.
@Module
public StatelessBean app() throws Exception {
final StatelessBean bean = new StatelessBean(BmtManager.class);
bean.setLocalBean(new Empty());
return bean;
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class SecondStatelessInterceptedTest method module.
@Module
public EjbJar module() {
final EjbJar ejbJar = new EjbJar();
final StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(SecondStatelessInterceptedBean.class));
final AssemblyDescriptor assembly = ejbJar.getAssemblyDescriptor();
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorOne.class)));
assembly.addInterceptorBinding(new InterceptorBinding("*", new Interceptor(DefaultInterceptorTwo.class)));
assembly.addInterceptorBinding(new InterceptorBinding(bean)).setExcludeDefaultInterceptors(true);
return ejbJar;
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class OpenejbLookupTest method testLocalInitialContext.
public void testLocalInitialContext() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
Context context = new InitialContext(properties);
// This is still the jvm InitialContext delegating to the openejbURLContextFactory
assertTrue(context instanceof InitialContext);
assertOpenejbUrlLookups(context);
// Now we have effectively unwrapped the InitalContext, openejb: lookups should still work.
context = (Context) context.lookup("");
assertTrue(context instanceof IvmContext);
assertOpenejbUrlLookups(context);
// Test that an EJB can lookup items from openejb:
final FooLocal fooLocal = (FooLocal) context.lookup("FooBeanLocal");
fooLocal.test();
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class EjbContextTest method test.
public void test() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatefulBean("Stateful", MySessionBean.class));
ejbJar.addEnterpriseBean(new StatelessBean("Stateless", MySessionBean.class));
ejbJar.addEnterpriseBean(new SingletonBean("Singleton", MySessionBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
final Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final InitialContext context = new InitialContext(properties);
{
final MySessionBean bean = (MySessionBean) context.lookup("StatefulLocalBean");
bean.test();
}
{
final MySessionBean bean = (MySessionBean) context.lookup("StatelessLocalBean");
bean.test();
}
{
final MySessionBean bean = (MySessionBean) context.lookup("SingletonLocalBean");
bean.test();
}
}
use of org.apache.openejb.jee.StatelessBean 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());
}
}
Aggregations