Search in sources :

Example 46 with SingletonBean

use of org.apache.openejb.jee.SingletonBean 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());
    }
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) 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 47 with SingletonBean

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

Example 48 with SingletonBean

use of org.apache.openejb.jee.SingletonBean in project tomee by apache.

the class CustomEndpointConfiguratorTest method module.

@Module
public EjbModule module() {
    final EjbModule module = new EjbModule(new EjbJar());
    module.setOpenejbJar(new OpenejbJar());
    final SingletonBean bean = new SingletonBean(MyWebservice.class);
    bean.setLocalBean(new Empty());
    final EjbDeployment deployment = new EjbDeployment(bean);
    deployment.getProperties().setProperty("openejb.endpoint.configurator", CustomConfigurator.class.getName());
    module.getOpenejbJar().addEjbDeployment(deployment);
    module.getEjbJar().addEnterpriseBean(bean);
    return module;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) Empty(org.apache.openejb.jee.Empty) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module)

Example 49 with SingletonBean

use of org.apache.openejb.jee.SingletonBean in project tomee by apache.

the class FeatureTest method app.

@Module
public EjbModule app() {
    final EjbJar jar = new EjbJar();
    jar.addEnterpriseBean(new SingletonBean(AuthenticatorServiceBean.class).localBean());
    final OpenejbJar openejbJar = new OpenejbJar();
    openejbJar.addEjbDeployment(new EjbDeployment(jar.getEnterpriseBeans()[0]));
    final Properties properties = openejbJar.getEjbDeployment().iterator().next().getProperties();
    properties.setProperty(CxfService.OPENEJB_JAXWS_CXF_FEATURES, MyFeature.class.getName());
    properties.setProperty("cxf.jaxws.features", "my-feature");
    properties.setProperty("cxf.jaxws.properties", "my-props");
    final EjbModule module = new EjbModule(jar);
    module.setOpenejbJar(openejbJar);
    final Resources resources = new Resources();
    final Service service = new Service("my-feature", null, null, null);
    service.setClassName(MyFeature.class.getName());
    resources.add(service);
    final Service myProps = new Service("my-props", null, null, null);
    myProps.setClassName(Properties.class.getName());
    myProps.getProperties().setProperty("faultStackTraceEnabled", "true");
    resources.add(myProps);
    module.initResources(resources);
    return module;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbModule(org.apache.openejb.config.EjbModule) Service(org.apache.openejb.config.sys.Service) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Resources(org.apache.openejb.config.sys.Resources) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.junit.Module)

Aggregations

SingletonBean (org.apache.openejb.jee.SingletonBean)49 EjbJar (org.apache.openejb.jee.EjbJar)42 EjbModule (org.apache.openejb.config.EjbModule)21 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)17 Module (org.apache.openejb.testing.Module)16 Assembler (org.apache.openejb.assembler.classic.Assembler)14 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)12 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)12 AppModule (org.apache.openejb.config.AppModule)11 Properties (java.util.Properties)10 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)10 InitialContext (javax.naming.InitialContext)8 StatelessBean (org.apache.openejb.jee.StatelessBean)8 SingletonSessionContainerInfo (org.apache.openejb.assembler.classic.SingletonSessionContainerInfo)7 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)7 AppInfo (org.apache.openejb.assembler.classic.AppInfo)6 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)6 Empty (org.apache.openejb.jee.Empty)6 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)5 Test (org.junit.Test)5