use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class CheckPersistenceUnitUsageTest method noUnitName.
@Keys({ @Key(value = "persistenceUnitRef.noMatches"), @Key(value = "persistenceUnitRef.noUnitName") })
public AppModule noUnitName() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessOne.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
final AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
appModule.getEjbModules().add(ejbModule);
final PersistenceUnit pu = new PersistenceUnit("fooUnit");
final PersistenceUnit pu1 = new PersistenceUnit("fooUnit1");
final PersistenceUnit pu2 = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu, pu1, pu2);
final PersistenceModule pm = new PersistenceModule("foo", p);
appModule.addPersistenceModule(pm);
return appModule;
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class NoServiceJarTest method test.
public void test() throws Exception {
final ConfigurationFactory factory = new ConfigurationFactory();
final Assembler assembler = new Assembler();
final Resource orange = new Resource("Orange");
orange.setClassName(Color.class.getName());
orange.getProperties().setProperty("red", "255");
orange.getProperties().setProperty("green", "200");
orange.getProperties().setProperty("blue", "0");
final ResourceInfo resourceInfo = factory.configureService(orange, ResourceInfo.class);
assembler.createResource(resourceInfo);
assembler.createSecurityService(factory.configureService(SecurityServiceInfo.class));
assembler.createTransactionManager(factory.configureService(TransactionServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MyBean.class));
final AppContext application = assembler.createApplication(factory.configureApplication(new EjbModule(ejbJar)));
final MyBean myBean = (MyBean) application.getBeanContexts().get(0).getBusinessLocalBeanHome().create();
final Color color = myBean.getColor();
assertNotNull(color);
assertEquals(255, color.getRed());
assertEquals(200, color.getGreen());
assertEquals(0, color.getBlue());
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class ParseAppCtxXmlTest method module.
@Module
public AppModule module() {
final AppModule app = new AppModule(ParseAppCtxXmlTest.class.getClassLoader(), "");
app.getAltDDs().put("app-ctx.xml", ParseAppCtxXmlTest.class.getClassLoader().getResource("complete-app-ctx.xml"));
app.getEjbModules().add(ejbModule("1"));
app.getEjbModules().iterator().next().getEjbJar().addEnterpriseBean(new SingletonBean("CalculatorBean", CalculatorConfigured.class.getName()));
app.getEjbModules().add(ejbModule("2"));
app.getEjbModules().get(1).getEjbJar().addEnterpriseBean(new SingletonBean("BeanInAModule", CalculatorConfigured2.class.getName()));
return app;
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class LegacyInterfaceTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.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 EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
// <entity>
// <ejb-name>License</ejb-name>
// <local-home>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome</local-home>
// <local>org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal</local>
// <ejb-class>org.apache.openejb.test.entity.cmr.onetoone.LicenseBean</ejb-class>
// <persistence-type>Container</persistence-type>
// <prim-key-class>java.lang.Integer</prim-key-class>
// <reentrant>false</reentrant>
// <cmp-version>2.x</cmp-version>
// <abstract-schema-name>License</abstract-schema-name>
// <cmp-field>
// <field-name>id</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>number</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>points</field-name>
// </cmp-field>
// <cmp-field>
// <field-name>notes</field-name>
// </cmp-field>
// <primkey-field>id</primkey-field>
// <query>
// <!-- CompondPK one-to-one shares the local home interface so we need to declare this useless finder -->
// <query-method>
// <method-name>findByPrimaryKey</method-name>
// <method-params>
// <method-param>org.apache.openejb.test.entity.cmr.onetoone.LicensePk</method-param>
// </method-params>
// </query-method>
// <ejb-ql>SELECT OBJECT(DL) FROM License DL</ejb-ql>
// </query>
// </entity>
final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
cmp.setPrimKeyClass(Integer.class.getName());
cmp.setPrimkeyField("id");
cmp.getCmpField().add(new CmpField("id"));
cmp.getCmpField().add(new CmpField("name"));
final Query query = new Query();
query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
cmp.getQuery().add(query);
final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
// <container-transaction>
// <method>
// <ejb-name>MyBean</ejb-name>
// <method-name>*</method-name>
// </method>
// <trans-attribute>Supports</trans-attribute>
// </container-transaction>
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
final File f = new File("test").getAbsoluteFile();
if (!f.exists() && !f.mkdirs()) {
throw new Exception("Failed to create test directory: " + f);
}
final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
module.getEjbModules().add(new EjbModule(ejbJar));
assembler.createApplication(config.configureApplication(module));
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class AsynchInRoleTest method testSessionContext.
@Test
public void testSessionContext() throws Exception {
// Build the application
final AppModule app = new AppModule(this.getClass().getClassLoader(), "testcanceltask");
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(TestBeanB.class));
app.getEjbModules().add(new EjbModule(ejbJar));
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
final Properties env = new Properties();
env.put(javax.naming.Context.SECURITY_PRINCIPAL, "jonathan");
env.put(javax.naming.Context.SECURITY_CREDENTIALS, "secret");
final InitialContext context = new InitialContext(env);
final TestBean test = (TestBean) context.lookup("TestBeanBLocal");
test.testA(Thread.currentThread().getId());
Assert.assertEquals("testA was never executed", "testA", test.getLastInvokeMethod());
final Future<String> future = test.testB(Thread.currentThread().getId());
Thread.sleep(1000L);
Assert.assertFalse(future.cancel(true));
Assert.assertFalse(future.isCancelled());
Assert.assertFalse(future.isDone());
Thread.sleep(3000L);
Assert.assertTrue(future.isDone());
Assert.assertEquals("testB was never executed", "testB", test.getLastInvokeMethod());
test.testC(Thread.currentThread().getId());
Assert.assertEquals("testC was never executed", "testC", test.getLastInvokeMethod());
test.testD(Thread.currentThread().getId());
Thread.sleep(3000L);
Assert.assertEquals("testD was never executed", "testD", test.getLastInvokeMethod());
context.close();
}
Aggregations