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);
}
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);
}
}
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));
}
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;
}
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;
}
Aggregations