use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo 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.assembler.classic.StatelessSessionContainerInfo 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.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.
the class DependsOnTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.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));
// containers
assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
final StatelessSessionContainerInfo statelessContainer = config.configureService(StatelessSessionContainerInfo.class);
statelessContainer.properties.setProperty("MinSize", "1");
statelessContainer.properties.setProperty("MaxSize", "1");
assembler.createContainer(statelessContainer);
actualConstruct.clear();
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(Two.class));
ejbJar.addEnterpriseBean(new SingletonBean(One.class));
ejbJar.addEnterpriseBean(new SingletonBean(Four.class));
ejbJar.addEnterpriseBean(new StatelessBean(Three.class));
// startup and trigger @PostConstruct
assembler.createApplication(config.configureApplication(ejbJar));
assertEquals(expected(four, three, two, one), actualConstruct);
actualDestroy.clear();
// startup and trigger @PreDestroy
for (final AppInfo appInfo : assembler.getDeployedApplications()) {
assembler.destroyApplication(appInfo.path);
}
assertEquals(expected(one, two, three, four), actualDestroy);
}
use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.
the class ConfigureServiceTest method testConfigureService2.
public void testConfigureService2() throws Exception {
final ConfigurationFactory factory = new ConfigurationFactory();
// We should be able to create one of these with a different name
final Container container = new Container("MyContainer", "STATELESS", "org.acme#CheddarContainer");
final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
assertNotNull(myStatelessContainer);
assertEquals("MyContainer", myStatelessContainer.id);
assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
assertNotNull(myStatelessContainer.constructorArgs);
assertNotNull(myStatelessContainer.properties);
assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
assertEquals("Yummy Cheese", myStatelessContainer.properties.getProperty("myProperty"));
}
use of org.apache.openejb.assembler.classic.StatelessSessionContainerInfo in project tomee by apache.
the class ConfigureServiceTest method testConfigureServiceAddedPropertyViaURI2.
public void testConfigureServiceAddedPropertyViaURI2() throws Exception {
final ConfigurationFactory factory = new ConfigurationFactory();
final URI uri = new URI("new://Container?type=STATELESS&provider=org.acme%23CheddarContainer&myProperty=Queso");
final Container container = (Container) factory.toConfigDeclaration("MyContainer", uri);
container.getProperties().setProperty("anotherProperty", "Cheese is good");
final StatelessSessionContainerInfo myStatelessContainer = factory.configureService(container, StatelessSessionContainerInfo.class);
assertNotNull(myStatelessContainer);
assertEquals("MyContainer", myStatelessContainer.id);
assertEquals("org.acme.SuperContainer", myStatelessContainer.className);
assertNotNull(myStatelessContainer.constructorArgs);
assertNotNull(myStatelessContainer.properties);
assertNotNull(myStatelessContainer.properties.getProperty("myProperty"));
assertEquals("Queso", myStatelessContainer.properties.getProperty("myProperty"));
assertNotNull(myStatelessContainer.properties.getProperty("anotherProperty"));
assertEquals("Cheese is good", myStatelessContainer.properties.getProperty("anotherProperty"));
}
Aggregations