Search in sources :

Example 6 with SingletonBean

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

the class AsyncPostContructTest method asyncConstructBean.

@Module
public EnterpriseBean asyncConstructBean() {
    final SingletonBean singletonBean = new SingletonBean(BuildMeAsync.class);
    singletonBean.setInitOnStartup(true);
    return singletonBean.localBean();
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) Module(org.apache.openejb.testing.Module)

Example 7 with SingletonBean

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

the class DependsOnTest method testCircuit.

public void testCircuit() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Two.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Three.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class)).setDependsOn("One");
    try {
        config.configureApplication(ejbJar);
        fail("Validation should have found a circular reference");
    } catch (final ValidationFailedException e) {
        final ValidationFailure[] failures = e.getFailures();
        assertEquals(1, failures.length);
        assertEquals("dependsOn.circuit", failures[0].getMessageKey());
    }
}
Also used : InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ValidationFailedException(org.apache.openejb.config.ValidationFailedException) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 8 with SingletonBean

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

the class DependsOnTest method testNoStartUp.

public void testNoStartUp() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
    actualConstruct.clear();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Two.class)).setInitOnStartup(false);
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class)).setInitOnStartup(false);
    ejbJar.addEnterpriseBean(new SingletonBean(Three.class)).setInitOnStartup(false);
    // startup and trigger @PostConstruct
    assembler.createApplication(config.configureApplication(ejbJar));
    assertEquals(expected(four, three, two, one), actualConstruct);
    actualDestroy.clear();
    // startup and trigger @PreDestroy
    for (final AppInfo appInfo : assembler.getDeployedApplications()) {
        assembler.destroyApplication(appInfo.path);
    }
    assertEquals(expected(one, two, three, four), actualDestroy);
}
Also used : ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 9 with SingletonBean

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

the class DependsOnTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
    final StatelessSessionContainerInfo statelessContainer = config.configureService(StatelessSessionContainerInfo.class);
    statelessContainer.properties.setProperty("MinSize", "1");
    statelessContainer.properties.setProperty("MaxSize", "1");
    assembler.createContainer(statelessContainer);
    actualConstruct.clear();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Two.class));
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Three.class));
    // startup and trigger @PostConstruct
    assembler.createApplication(config.configureApplication(ejbJar));
    assertEquals(expected(four, three, two, one), actualConstruct);
    actualDestroy.clear();
    // startup and trigger @PreDestroy
    for (final AppInfo appInfo : assembler.getDeployedApplications()) {
        assembler.destroyApplication(appInfo.path);
    }
    assertEquals(expected(one, two, three, four), actualDestroy);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) AppInfo(org.apache.openejb.assembler.classic.AppInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 10 with SingletonBean

use of org.apache.openejb.jee.SingletonBean 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)

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