Search in sources :

Example 86 with StatelessBean

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();
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 87 with StatelessBean

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);
}
Also used : MessageDestination(org.apache.openejb.jee.MessageDestination) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) ResourceEnvReferenceInfo(org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) MessageDestinationRef(org.apache.openejb.jee.MessageDestinationRef) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Queue(javax.jms.Queue) WebApp(org.apache.openejb.jee.WebApp) EjbJar(org.apache.openejb.jee.EjbJar)

Example 88 with StatelessBean

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;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EntityBean(javax.ejb.EntityBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 89 with StatelessBean

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;
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) PersistenceModule(org.apache.openejb.config.PersistenceModule) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 90 with StatelessBean

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;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

StatelessBean (org.apache.openejb.jee.StatelessBean)132 EjbJar (org.apache.openejb.jee.EjbJar)120 Assembler (org.apache.openejb.assembler.classic.Assembler)58 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)46 EjbModule (org.apache.openejb.config.EjbModule)39 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)33 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)33 InitialContext (javax.naming.InitialContext)31 Properties (java.util.Properties)30 Module (org.apache.openejb.testing.Module)25 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)19 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)18 AppModule (org.apache.openejb.config.AppModule)18 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)17 ServerFederation (org.apache.openejb.core.ServerFederation)15 Context (javax.naming.Context)14 ContainerSystem (org.apache.openejb.spi.ContainerSystem)14 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)13 Empty (org.apache.openejb.jee.Empty)13 StatefulBean (org.apache.openejb.jee.StatefulBean)12