Search in sources :

Example 1 with SingletonBean

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

the class ResourcesJsonTest method setUp.

@Before
public void setUp() throws OpenEJBException, NamingException, IOException {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final AppModule app = new AppModule(ResourcesJsonTest.class.getClassLoader(), ResourcesJsonTest.class.getSimpleName());
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(ConfiguredThroughJSonBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.getEjbModules().iterator().next().getAltDDs().put("resources.json", getClass().getClassLoader().getResource("appresource.resources.json"));
    assembler.createApplication(config.configureApplication(app));
    final Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
    // some hack to be sure to call destroy()
    context = new InitialContext(properties);
    bean = (ConfiguredThroughJSonBean) context.lookup("ConfiguredThroughJSonBeanLocalBean");
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 2 with SingletonBean

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

the class ConcurrentMethodTest method test.

public void test() throws Exception {
    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));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Color.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    loadAttributes(ejbJarInfo, "Color");
    assertAccessTimeoutAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Object.class));
    assertLockAttribute("Read", Color.class.getMethod("color", Object.class));
    assertAccessTimeoutAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", String.class));
    assertLockAttribute("Write", Color.class.getMethod("color", String.class));
    assertAccessTimeoutAttribute(2, TimeUnit.HOURS, Color.class.getMethod("color", Boolean.class));
    assertLockAttribute("Read", Color.class.getMethod("color", Boolean.class));
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Example 3 with SingletonBean

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

the class DescriptorDataSourceDefinitionTest method application.

@Module
public EjbJar application() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final SingletonBean orange = ejbJar.addEnterpriseBean(new SingletonBean(OrangeBean.class));
    orange.getDataSource().add(new org.apache.openejb.jee.DataSource().name("java:comp/env/superDS").className("org.hsqldb.jdbc.JDBCDataSource").user("sa").password("").url("jdbc:hsqldb:mem:superDS"));
    orange.getResourceRef().add(new ResourceRef().lookup("java:comp/env/superDS").injectionTarget(OrangeBean.class, "ds"));
    final StatelessBean yellow = ejbJar.addEnterpriseBean(new StatelessBean(YellowBean.class));
    yellow.getDataSource().add(new org.apache.openejb.jee.DataSource().name("java:comp/env/superMegaDS").className("org.hsqldb.jdbc.JDBCDataSource").user("sa").password("").url("jdbc:hsqldb:mem:superDS"));
    yellow.getResourceRef().add(new ResourceRef().lookup("java:comp/env/superMegaDS").injectionTarget(YellowBean.class, "mega"));
    yellow.getDataSource().add(new org.apache.openejb.jee.DataSource().name("java:comp/env/superGigaDS").className("org.hsqldb.jdbc.JDBCDataSource").user("sa").password("").url("jdbc:hsqldb:mem:superDS"));
    yellow.getResourceRef().add(new ResourceRef().lookup("java:comp/env/superGigaDS").injectionTarget(YellowBean.class, "giga"));
    return ejbJar;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) ResourceRef(org.apache.openejb.jee.ResourceRef) EjbJar(org.apache.openejb.jee.EjbJar) DataSource(javax.sql.DataSource) Module(org.apache.openejb.testing.Module)

Example 4 with SingletonBean

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

the class DynamicEJBImplTest method app.

@Module
public EjbJar app() throws Exception {
    final EjbJar ejbJar = new EjbJar("dynamic");
    ejbJar.addEnterpriseBean(new SingletonBean(UtilBean.class));
    ejbJar.addEnterpriseBean(new SingletonBean(DynamicCustomProxy.class));
    ejbJar.addEnterpriseBean(new StatelessBean(UserDAO.class));
    ejbJar.addEnterpriseBean(new StatelessBean(UserDAOChild.class));
    return ejbJar;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) Module(org.apache.openejb.testing.Module)

Example 5 with SingletonBean

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

the class OutputGeneratedDescriptorsTest method testOutputDescriptor.

@Test
public void testOutputDescriptor() throws Exception {
    final OutputGeneratedDescriptors dynamicDeployer = new OutputGeneratedDescriptors();
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean redBean = new StatelessBean();
    redBean.setEjbClass("com.foo.Red");
    redBean.setEjbName("Red");
    redBean.setRemote("com.foo.Color");
    final ManagedBean orangeBean = new ManagedBean("Orange", "com.foo.Orange");
    final StatefulBean yellowBean = new StatefulBean();
    yellowBean.setEjbClass("com.foo.Yellow");
    yellowBean.setEjbName("Yellow");
    yellowBean.setRemote("com.foo.Color");
    final SingletonBean greenBean = new SingletonBean();
    greenBean.setEjbClass("com.foo.Green");
    greenBean.setEjbName("Green");
    greenBean.setRemote("com.foo.Color");
    ejbJar.addEnterpriseBean(redBean);
    ejbJar.addEnterpriseBean(orangeBean);
    ejbJar.addEnterpriseBean(yellowBean);
    ejbJar.addEnterpriseBean(greenBean);
    final OpenejbJar openejbJar = new OpenejbJar();
    final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
    final AppModule appModule = new AppModule(ejbModule);
    File tempFolder = File.createTempFile("tmp", "ogd");
    tempFolder.delete();
    Assert.assertTrue("unable to create temp folder", tempFolder.mkdirs());
    try {
        Properties properties = ejbModule.getOpenejbJar().getProperties();
        properties.setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "true");
        properties.setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS_FOLDER, tempFolder.getAbsolutePath());
        SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS_FOLDER, tempFolder.getAbsolutePath());
        dynamicDeployer.deploy(appModule);
        boolean seenEjbJarXml = false;
        boolean seenOpenejbJarXml = false;
        File[] listFiles = tempFolder.listFiles();
        for (File file : listFiles) {
            if (file.getName().startsWith("ejb-jar-")) {
                seenEjbJarXml = true;
                assertEjbFileCorrect(file);
            }
            if (file.getName().startsWith("openejb-jar-")) {
                seenOpenejbJarXml = true;
            }
        }
        Assert.assertTrue("No ejb-jar.xml file produced", seenEjbJarXml);
        Assert.assertTrue("No openejb-jar.xml file produced", seenOpenejbJarXml);
    } finally {
        // clean up temporary folder
        Files.delete(tempFolder);
    }
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) Properties(java.util.Properties) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ManagedBean(org.apache.openejb.jee.ManagedBean) File(java.io.File) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

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