use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class InjectionTest method setUp.
protected void setUp() throws Exception {
super.setUp();
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
statelessContainerInfo.properties.setProperty("TimeOut", "10");
statelessContainerInfo.properties.setProperty("MaxSize", "0");
statelessContainerInfo.properties.setProperty("StrictPooling", "false");
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
final StatelessBean bean = new StatelessBean(WidgetBean.class);
bean.addBusinessLocal(Widget.class.getName());
bean.addBusinessRemote(RemoteWidget.class.getName());
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(bean);
bean.getEnvEntry().add(new EnvEntry(name("myString"), "java.lang.String", "2"));
bean.getEnvEntry().add(new EnvEntry(name("myDouble"), "java.lang.Double", "3.0"));
bean.getEnvEntry().add(new EnvEntry(name("myLong"), "java.lang.Long", "4"));
bean.getEnvEntry().add(new EnvEntry(name("myFloat"), "java.lang.Float", "5"));
bean.getEnvEntry().add(new EnvEntry(name("myInteger"), "java.lang.Integer", "6"));
bean.getEnvEntry().add(new EnvEntry(name("myShort"), "java.lang.Short", "7"));
bean.getEnvEntry().add(new EnvEntry(name("myBoolean"), "java.lang.Boolean", "false"));
bean.getEnvEntry().add(new EnvEntry(name("myByte"), "java.lang.Byte", "8"));
bean.getEnvEntry().add(new EnvEntry(name("myCharacter"), "java.lang.Character", "9"));
bean.getEnvEntry().add(new EnvEntry(name("myClass"), "java.lang.Class", Widget.class.getName()));
bean.getEnvEntry().add(new EnvEntry(name("myTimeUnit"), TimeUnit.class.getName(), "HOURS"));
final EnvEntry entry = new EnvEntry("injectedBoolean", (String) null, "true");
entry.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "injectedBoolean")));
bean.getEnvEntry().add(entry);
final ResourceEnvRef resourceEnvRef = new ResourceEnvRef("injectedContext", (String) null);
resourceEnvRef.getInjectionTarget().add((new InjectionTarget(WidgetBean.class.getName(), "injectedContext")));
bean.getResourceEnvRef().add(resourceEnvRef);
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class JndiNameTest method testOpenejbJar2.
public void testOpenejbJar2() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
final StatelessSessionContainerInfo statelessContainerInfo = config.configureService(StatelessSessionContainerInfo.class);
assembler.createContainer(statelessContainerInfo);
// Setup the descriptor information
final EjbModule ejbModule = new EjbModule(new EjbJar(), null);
ejbModule.getEjbJar().addEnterpriseBean(new StatelessBean(FooBean.class));
final OpenejbJarType v2 = new OpenejbJarType();
final SessionBeanType ejbDeployment = new SessionBeanType();
ejbDeployment.setEjbName("FooBean");
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("thename", "Local"));
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("anothername", "Remote"));
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("loldstyle", "LocalHome"));
ejbDeployment.getJndi().add(new org.apache.openejb.jee.oejb2.Jndi("roldstyle", "RemoteHome"));
v2.getEnterpriseBeans().add(ejbDeployment);
ejbModule.getAltDDs().put("openejb-jar.xml", v2);
assembler.createApplication(config.configureApplication(ejbModule));
final InitialContext initialContext = new InitialContext();
assertName(initialContext, Orange.class, "thename");
assertName(initialContext, Red.class, "anothername");
assertName(initialContext, LHYellow.class, "loldstyle");
assertName(initialContext, RHGreen.class, "roldstyle");
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class LocalClientNoInjectionTest method setUp.
public void setUp() throws OpenEJBException, NamingException, IOException {
//avoid linkage error on mac, only used for tests so don't need to add it in Core
JULLoggerFactory.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 AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
final Persistence persistence = new Persistence(new org.apache.openejb.jee.jpa.unit.PersistenceUnit("foo-unit"));
app.addPersistenceModule(new PersistenceModule("root", persistence));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
app.getEjbModules().add(new EjbModule(ejbJar));
final ClientModule clientModule = new ClientModule(null, app.getClassLoader(), app.getJarLocation(), null, null);
clientModule.getLocalClients().add(this.getClass().getName());
app.getClientModules().add(clientModule);
assembler.createApplication(config.configureApplication(app));
}
use of org.apache.openejb.jee.StatelessBean in project tomee by apache.
the class JndiNameFormatTest method deploy.
private void deploy(final String format) throws OpenEJBException, IOException, NamingException {
SystemInstance.get().setProperty("openejb.jndiname.format", format);
final ConfigurationFactory config = new ConfigurationFactory();
assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(EchoImpl.class));
app.getEjbModules().add(new EjbModule(ejbJar));
assembler.createApplication(config.configureApplication(app));
}
use of org.apache.openejb.jee.StatelessBean 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