Search in sources :

Example 11 with StatefulBean

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

the class ScheduleTest method testSchedule.

public void testSchedule() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.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));
    final EjbJar ejbJar = new EjbJar();
    // Configure schedule by deployment plan
    final StatelessBean subBeanA = new StatelessBean(SubBeanA.class);
    final Timer subBeanATimer = new Timer();
    subBeanATimer.setTimeoutMethod(new NamedMethod("subBeanA", "javax.ejb.Timer"));
    final TimerSchedule timerScheduleA = new TimerSchedule();
    timerScheduleA.setSecond("2");
    timerScheduleA.setMinute("*");
    timerScheduleA.setHour("*");
    subBeanATimer.setSchedule(timerScheduleA);
    subBeanATimer.setInfo("SubBeanAInfo");
    subBeanA.getTimer().add(subBeanATimer);
    ejbJar.addEnterpriseBean(subBeanA);
    // Configure schedule by annotation
    final StatelessBean subBeanB = new StatelessBean(SubBeanB.class);
    ejbJar.addEnterpriseBean(subBeanB);
    // Override aroundTimeout annotation by deployment plan
    final StatelessBean subBeanC = new StatelessBean(SubBeanC.class);
    final Timer subBeanCTimer = new Timer();
    subBeanCTimer.setTimeoutMethod(new NamedMethod("subBeanC", "javax.ejb.Timer"));
    final TimerSchedule timerScheduleC = new TimerSchedule();
    timerScheduleC.setSecond("2");
    timerScheduleC.setMinute("*");
    timerScheduleC.setHour("*");
    subBeanCTimer.setSchedule(timerScheduleC);
    subBeanCTimer.setInfo("SubBeanCInfo");
    subBeanC.getTimer().add(subBeanCTimer);
    ejbJar.addEnterpriseBean(subBeanC);
    final StatefulBean subBeanM = new StatefulBean(SubBeanM.class);
    ejbJar.addEnterpriseBean(subBeanM);
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    countDownLatch.await(1L, TimeUnit.MINUTES);
    // A better way for validation ?
    int beforeAroundInvocationCount = 0;
    int afterAroundInvocationCount = 0;
    int timeoutInvocationCount = 0;
    final int size;
    synchronized (result) {
        size = result.size();
        for (final Call call : result) {
            switch(call) {
                case BEAN_BEFORE_AROUNDTIMEOUT:
                    beforeAroundInvocationCount++;
                    break;
                case BEAN_AFTER_AROUNDTIMEOUT:
                    afterAroundInvocationCount++;
                    break;
                case TIMEOUT:
                    timeoutInvocationCount++;
                    break;
            }
        }
    }
    assertEquals(3, beforeAroundInvocationCount);
    assertEquals(3, afterAroundInvocationCount);
    assertEquals(3, timeoutInvocationCount);
    assertEquals(9, size);
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) NamedMethod(org.apache.openejb.jee.NamedMethod) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TimerSchedule(org.apache.openejb.jee.TimerSchedule) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Timer(org.apache.openejb.jee.Timer) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 12 with StatefulBean

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

Example 13 with StatefulBean

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

the class Green method testSystemPropertyNames.

@Keys({ @Key(value = "incorrect.property.name", type = KeyType.WARNING) })
public AppModule testSystemPropertyNames() {
    // SystemInstance.get().setProperty("java.persistence.provider", "test");
    SystemInstance.get().setProperty("javax.naming.referral", "test");
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
    return new AppModule(new EjbModule(ejbJar));
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar)

Example 14 with StatefulBean

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

the class CheckInvalidAroundTimeoutTest method testIgnoredAroundTimeout.

@Keys(@Key(value = "ignoredMethodAnnotation", type = KeyType.WARNING))
public EjbJar testIgnoredAroundTimeout() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean("TestAroundTimeout", TestAroundTimeout.class));
    return ejbJar;
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 15 with StatefulBean

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

the class CheckInvalidCallbacksTest method test2.

@Keys(@Key(value = "callback.sessionbean.invalidusage", count = 6))
public EjbJar test2() {
    System.setProperty("openejb.validation.output.level", "VERBOSE");
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean sun = ejbJar.addEnterpriseBean(new StatelessBean("SunStateless", Sun.class));
    sun.setLocalHome(SunLocalHome.class.getName());
    sun.setLocal(SunLocal.class.getName());
    final StatefulBean meteor = ejbJar.addEnterpriseBean(new StatefulBean("MeteorStateful", Meteor.class));
    meteor.setLocal(SunLocal.class.getName());
    meteor.setLocalHome(SunLocalHome.class.getName());
    return ejbJar;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

StatefulBean (org.apache.openejb.jee.StatefulBean)36 EjbJar (org.apache.openejb.jee.EjbJar)33 Assembler (org.apache.openejb.assembler.classic.Assembler)18 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)18 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)18 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)16 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)12 StatelessBean (org.apache.openejb.jee.StatelessBean)12 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)10 StatefulSessionContainerInfo (org.apache.openejb.assembler.classic.StatefulSessionContainerInfo)7 EjbModule (org.apache.openejb.config.EjbModule)7 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)6 NamedMethod (org.apache.openejb.jee.NamedMethod)6 InitialContext (javax.naming.InitialContext)5 AppModule (org.apache.openejb.config.AppModule)3 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)3 AssemblyDescriptor (org.apache.openejb.jee.AssemblyDescriptor)3 SingletonBean (org.apache.openejb.jee.SingletonBean)3 Timeout (org.apache.openejb.jee.Timeout)3 Properties (java.util.Properties)2