Search in sources :

Example 26 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class AsynchTest method testSessionContext.

@Test
public void testSessionContext() throws Exception {
    //Build the application
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testcanceltask");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(TestBeanB.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("TestBeanBLocal");
    test.testA(Thread.currentThread().getId());
    Assert.assertEquals("testA was never executed", "testA", test.getLastInvokeMethod());
    final Future<String> future = test.testB(Thread.currentThread().getId());
    Thread.sleep(1000L);
    Assert.assertFalse(future.cancel(true));
    Assert.assertFalse(future.isCancelled());
    Assert.assertFalse(future.isDone());
    Thread.sleep(3000L);
    Assert.assertTrue(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());
    Thread.sleep(3000L);
    Assert.assertEquals("testD was never executed", "testD", test.getLastInvokeMethod());
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) 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 27 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class LegacyInterfaceTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.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 EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
    ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
    //<entity>
    //  <ejb-name>License</ejb-name>
    //  <local-home>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome</local-home>
    //  <local>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal</local>
    //  <ejb-class>org.apache.openejb.test.entity.cmr.onetoone.LicenseBean</ejb-class>
    //  <persistence-type>Container</persistence-type>
    //  <prim-key-class>java.lang.Integer</prim-key-class>
    //  <reentrant>false</reentrant>
    //  <cmp-version>2.x</cmp-version>
    //  <abstract-schema-name>License</abstract-schema-name>
    //  <cmp-field>
    //    <field-name>id</field-name>
    //  </cmp-field>
    //  <cmp-field>
    //    <field-name>number</field-name>
    //  </cmp-field>
    //  <cmp-field>
    //    <field-name>points</field-name>
    //  </cmp-field>
    //  <cmp-field>
    //    <field-name>notes</field-name>
    //  </cmp-field>
    //  <primkey-field>id</primkey-field>
    //  <query>
    //    <!-- CompondPK one-to-one shares the local home interface so we need to declare this useless finder -->
    //    <query-method>
    //      <method-name>findByPrimaryKey</method-name>
    //      <method-params>
    //        <method-param>org.apache.openejb.test.entity.cmr.onetoone.LicensePk</method-param>
    //      </method-params>
    //    </query-method>
    //    <ejb-ql>SELECT OBJECT(DL) FROM License DL</ejb-ql>
    //  </query>
    //</entity>
    final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
    cmp.setPrimKeyClass(Integer.class.getName());
    cmp.setPrimkeyField("id");
    cmp.getCmpField().add(new CmpField("id"));
    cmp.getCmpField().add(new CmpField("name"));
    final Query query = new Query();
    query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
    query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
    cmp.getQuery().add(query);
    final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    //<container-transaction>
    //  <method>
    //    <ejb-name>MyBean</ejb-name>
    //    <method-name>*</method-name>
    //  </method>
    //  <trans-attribute>Supports</trans-attribute>
    //</container-transaction>
    transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
    transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
    transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
    final File f = new File("test").getAbsoluteFile();
    if (!f.exists() && !f.mkdirs()) {
        throw new Exception("Failed to create test directory: " + f);
    }
    final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
    module.getEjbModules().add(new EjbModule(ejbJar));
    assembler.createApplication(config.configureApplication(module));
}
Also used : AppModule(org.apache.openejb.config.AppModule) Query(org.apache.openejb.jee.Query) QueryMethod(org.apache.openejb.jee.QueryMethod) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) RemoveException(javax.ejb.RemoveException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) CmpField(org.apache.openejb.jee.CmpField) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) EntityBean(org.apache.openejb.jee.EntityBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) File(java.io.File) EjbJar(org.apache.openejb.jee.EjbJar)

Example 28 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CheckAnnotationTest method testWebServiceWithMessageDriven.

@Keys({ @Key(value = "annotation.invalid.messagedriven.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithMessageDriven() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Yellow.class)).link());
    final AppModule appModule = new AppModule(ejbModule);
    return appModule;
}
Also used : AppModule(org.apache.openejb.config.AppModule) Yellow(org.apache.openejb.test.annotated.Yellow) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 29 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CheckAnnotationTest method testWebServiceWithManagedBean.

@Keys({ @Key(value = "annotation.invalid.managedbean.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithManagedBean() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new ManagedBean(Red.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Red.class)).link());
    final AppModule appModule = new AppModule(ejbModule);
    return appModule;
}
Also used : Red(org.apache.openejb.test.annotated.Red) AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) ManagedBean(org.apache.openejb.jee.ManagedBean) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 30 with EjbModule

use of org.apache.openejb.config.EjbModule in project tomee by apache.

the class CheckAnnotationTest method shouldWarnForLocalAnnotationOnBeanWithNoInterface.

@Keys({ @Key(value = "ann.local.forLocalBean", type = KeyType.WARNING) })
public EjbModule shouldWarnForLocalAnnotationOnBeanWithNoInterface() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(EjbWithoutInterface.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(EjbWithoutInterface.class)).link());
    return ejbModule;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)88 EjbJar (org.apache.openejb.jee.EjbJar)78 AppModule (org.apache.openejb.config.AppModule)40 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)29 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)26 Properties (java.util.Properties)23 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)19 Module (org.apache.openejb.testing.Module)16 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)12 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)12 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9