use of org.apache.openejb.jee.StatelessBean 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.jee.StatelessBean in project tomee by apache.
the class MessageDestinationTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final ClassLoader cl = this.getClass().getClassLoader();
final AppModule app = new AppModule(cl, "app");
final MessageDestinationRef webMessageDestRef = new MessageDestinationRef();
webMessageDestRef.setMessageDestinationRefName("jms/myqueue");
webMessageDestRef.setMessageDestinationType("javax.jms.Queue");
webMessageDestRef.setMessageDestinationUsage(MessageDestinationUsage.PRODUCES);
webMessageDestRef.setMessageDestinationLink("ejb.jar#myqueue");
final WebApp webApp = new WebApp();
webApp.setMetadataComplete(true);
webApp.getMessageDestinationRef().add(webMessageDestRef);
final WebModule webModule = new WebModule(webApp, "web", cl, "war", "web");
app.getWebModules().add(webModule);
final EjbJar ejbJar = new EjbJar();
final StatelessBean statelessBean = new StatelessBean(GreenBean.class);
final MessageDestinationRef ejbMessageDestRef = new MessageDestinationRef();
ejbMessageDestRef.setMessageDestinationRefName("jms/myqueue");
ejbMessageDestRef.setMessageDestinationType("javax.jms.Queue");
ejbMessageDestRef.setMessageDestinationUsage(MessageDestinationUsage.PRODUCES);
ejbMessageDestRef.setMessageDestinationLink("myqueue");
statelessBean.getMessageDestinationRef().add(ejbMessageDestRef);
ejbJar.addEnterpriseBean(statelessBean);
final MessageDestination queue = new MessageDestination();
queue.setMessageDestinationName("myqueue");
ejbJar.getAssemblyDescriptor().getMessageDestination().add(queue);
final EjbModule ejbModule = new EjbModule(cl, "ejb.jar", ejbJar, new OpenejbJar());
app.getEjbModules().add(ejbModule);
final AppInfo info = config.configureApplication(app);
assembler.createApplication(info);
final Object beanQueue = assembler.getContainerSystem().getBeanContext("GreenBean").getJndiContext().lookup("comp/env/jms/myqueue");
Assert.assertTrue(beanQueue instanceof Queue);
Assert.assertEquals(1, info.webApps.size());
final List<ResourceEnvReferenceInfo> resourceEnvRefs = info.webApps.get(0).jndiEnc.resourceEnvRefs;
boolean found = false;
for (final ResourceEnvReferenceInfo resourceEnvRef : resourceEnvRefs) {
if (!"comp/env/jms/myqueue".equals(resourceEnvRef.referenceName))
continue;
found = true;
Assert.assertEquals("jms/myqueue", resourceEnvRef.resourceID);
Assert.assertEquals("javax.jms.Queue", resourceEnvRef.resourceEnvRefType);
}
Assert.assertTrue(found);
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class CheckNoCreateMethodsTest method noCreateMethod.
@Keys({ @Key(value = "no.home.create", count = 4), @Key(value = "unused.ejb.create", count = 2, type = KeyType.WARNING), @Key(value = "unused.ejbPostCreate", type = KeyType.WARNING), @Key("entity.no.ejb.create"), @Key(value = "session.no.ejb.create", count = 2) })
public EjbJar noCreateMethod() throws OpenEJBException {
System.setProperty("openejb.validation.output.level", "VERBOSE");
final EjbJar ejbJar = new EjbJar();
final StatelessBean stateless = new StatelessBean(FooStateless.class);
stateless.setHomeAndRemote(FooStatelessHome.class, FooStatelessRemote.class);
stateless.setHomeAndLocal(FooStatelessLocalHome.class, FooStatelessLocal.class);
ejbJar.addEnterpriseBean(stateless);
final StatefulBean stateful = new StatefulBean(FooStateful.class);
stateful.setHomeAndRemote(FooStatefulHome.class, FooStatefulRemote.class);
stateful.setHomeAndLocal(FooStatefulLocalHome.class, FooStatefulLocal.class);
ejbJar.addEnterpriseBean(stateful);
final org.apache.openejb.jee.EntityBean bean = new org.apache.openejb.jee.EntityBean(MyEntity.class, PersistenceType.BEAN);
bean.setLocalHome(MyLocalHome.class.getName());
bean.setLocal(MyLocal.class.getName());
ejbJar.addEnterpriseBean(bean);
final org.apache.openejb.jee.EntityBean bean1 = new org.apache.openejb.jee.EntityBean(YourEntity.class, PersistenceType.BEAN);
bean1.setLocalHome(MyLocalHome.class.getName());
bean1.setLocal(MyLocal.class.getName());
ejbJar.addEnterpriseBean(bean1);
final StatelessBean bar = new StatelessBean(BarStateless.class);
bar.setHomeAndRemote(BarStatelessHome.class, BarStatelessRemote.class);
ejbJar.addEnterpriseBean(bar);
final StatefulBean bazStateful = new StatefulBean(BazStateful.class);
ejbJar.addEnterpriseBean(bazStateful);
return ejbJar;
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class CheckPersistenceUnitUsageTest method vagueMatches.
@Keys({ @Key(value = "persistenceUnitRef.vagueMatches") })
public AppModule vagueMatches() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessTwo.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
final AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
appModule.getEjbModules().add(ejbModule);
final PersistenceUnit pu = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu);
final PersistenceModule pm = new PersistenceModule("foo", p);
appModule.getPersistenceModules().add(pm);
final PersistenceUnit pu1 = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p1 = new org.apache.openejb.jee.jpa.unit.Persistence(pu1);
final PersistenceModule pm1 = new PersistenceModule("foo1", p1);
appModule.addPersistenceModule(pm1);
return appModule;
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class InvalidEjbRefTest method test1.
@Keys({ @Key("ejbAnnotation.onClassWithNoBeanInterface"), @Key("ejbAnnotation.onClassWithNoName") })
public EjbJar test1() throws Exception {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(MyBean.class));
return ejbJar;
}
Aggregations