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