Search in sources :

Example 31 with AppModule

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

Example 32 with AppModule

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();
}
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 33 with AppModule

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());
    }
}
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 34 with AppModule

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());
}
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 35 with AppModule

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

Aggregations

AppModule (org.apache.openejb.config.AppModule)51 EjbModule (org.apache.openejb.config.EjbModule)41 EjbJar (org.apache.openejb.jee.EjbJar)40 StatelessBean (org.apache.openejb.jee.StatelessBean)18 InitialContext (javax.naming.InitialContext)15 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)15 Properties (java.util.Properties)14 AppInfo (org.apache.openejb.assembler.classic.AppInfo)14 Assembler (org.apache.openejb.assembler.classic.Assembler)14 SingletonBean (org.apache.openejb.jee.SingletonBean)11 Test (org.junit.Test)10 WebModule (org.apache.openejb.config.WebModule)9 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)8 File (java.io.File)7 IOException (java.io.IOException)6 List (java.util.List)6 OpenEJBException (org.apache.openejb.OpenEJBException)6 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)6 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)6 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)6