Search in sources :

Example 41 with AppModule

use of org.apache.openejb.config.AppModule in project tomee by apache.

the class QuartzPersistenceForEJBTimersTest method application.

@Module
public AppModule application() {
    final EjbModule ejbModule = new EjbModule(new EjbJar());
    ejbModule.getEjbJar().addEnterpriseBean(new SingletonBean(MyTimedEjb.class).localBean());
    final Properties quartzConfig = new PropertiesBuilder().p("org.apache.openejb.quartz.scheduler.instanceName", "TestScheduler").p("org.apache.openejb.quartz.scheduler.instanceId", "AUTO").p("org.apache.openejb.quartz.threadPool.class", SimpleThreadPool.class.getName()).p("org.apache.openejb.quartz.threadPool.threadCount", "4").p("org.apache.openejb.quartz.threadPool.threadPriority", "5").p("org.apache.openejb.quartz.jobStore.class", JobStoreCMT.class.getName()).p("org.apache.openejb.quartz.jobStore.driverDelegateClass", HSQLDBDelegate.class.getName()).p("org.apache.openejb.quartz.jobStore.dataSource", "QUARTZ").p("org.apache.openejb.quartz.jobStore.nonManagedTXDataSource", "QUARTZ_NOTX").p("org.apache.openejb.quartz.jobStore.tablePrefix", "qrtz_").p("org.apache.openejb.quartz.jobStore.isClustered", "true").p("org.apache.openejb.quartz.jobStore.clusterCheckinInterval", "60000").p("org.apache.openejb.quartz.jobStore.txIsolationLevelSerializable", "true").p("org.apache.openejb.quartz.jobStore.maxMisfiresToHandleAtATime", "100").p("org.apache.openejb.quartz.dataSource.QUARTZ.jndiURL", "openejb:Resource/QuartzPersistenceForEJBTimersDB").p("org.apache.openejb.quartz.dataSource.QUARTZ_NOTX.jndiURL", "openejb:Resource/QuartzPersistenceForEJBTimersDBNoTx").build();
    final AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), null);
    appModule.getEjbModules().add(ejbModule);
    appModule.getProperties().putAll(quartzConfig);
    return appModule;
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) AppModule(org.apache.openejb.config.AppModule) HSQLDBDelegate(org.apache.openejb.quartz.impl.jdbcjobstore.HSQLDBDelegate) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) PropertiesBuilder(org.apache.openejb.testng.PropertiesBuilder) SimpleThreadPool(org.apache.openejb.quartz.simpl.SimpleThreadPool) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) AppModule(org.apache.openejb.config.AppModule) Module(org.apache.openejb.testing.Module)

Example 42 with AppModule

use of org.apache.openejb.config.AppModule in project tomee by apache.

the class CheckAnnotationTest method testWebServiceWithStateful.

@Keys({ @Key(value = "annotation.invalid.stateful.webservice", type = KeyType.WARNING) })
public AppModule testWebServiceWithStateful() {
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean(Green.class));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(Green.class)).link());
    final AppModule appModule = new AppModule(ejbModule);
    return appModule;
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) Green(org.apache.openejb.test.annotated.Green) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 43 with AppModule

use of org.apache.openejb.config.AppModule in project tomee by apache.

the class AppClientTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(ejbServer, 10);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbModule ejbModule = new EjbModule(new EjbJar("testejbmodule"), new OpenejbJar());
    final EjbJar ejbJar = ejbModule.getEjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Orange.class));
    final ClassLoader loader = this.getClass().getClassLoader();
    final ClientModule clientModule = new ClientModule(new ApplicationClient(), loader, "orange-client", OrangeAppClient.class.getName(), "orange-client");
    final AppModule appModule = new AppModule(loader, "testapp");
    appModule.getClientModules().add(clientModule);
    appModule.getEjbModules().add(ejbModule);
    assembler.createApplication(config.configureApplication(appModule));
    final Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    props.put("openejb.client.moduleId", "orange-client");
    Context context = new InitialContext(props);
    final Object home = context.lookup("comp/env/home");
    assertTrue(home instanceof OrangeHome);
    OrangeHome orangeHome = (OrangeHome) home;
    final OrangeRemote orangeRemote = orangeHome.create();
    assertEquals("bat", orangeRemote.echo("tab"));
    final Object business = context.lookup("comp/env/business");
    assertTrue(business instanceof OrangeBusinessRemote);
    OrangeBusinessRemote orangeBusinessRemote = (OrangeBusinessRemote) business;
    assertEquals("nap", orangeBusinessRemote.echo("pan"));
    final Object dataSourceObject = context.lookup("comp/env/datasource");
    assertTrue(dataSourceObject instanceof DataSource);
    // DataSource dataSource = (DataSource) dataSourceObject;
    // assertEquals("nap", orangeBusinessRemote.echo("pan"));
    props.put("openejb.client.moduleId", "openejb/global");
    context = new InitialContext(props);
    final Object global = context.lookup("global/testapp/testejbmodule/Orange!" + OrangeBusinessRemote.class.getName());
    assertTrue(global instanceof OrangeBusinessRemote);
    OrangeBusinessRemote globalOrangeBusinessRemote = (OrangeBusinessRemote) global;
    assertEquals("nap", globalOrangeBusinessRemote.echo("pan"));
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ApplicationClient(org.apache.openejb.jee.ApplicationClient) ServicePool(org.apache.openejb.server.ServicePool) ClientModule(org.apache.openejb.config.ClientModule) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EJBObject(javax.ejb.EJBObject) Assembler(org.apache.openejb.assembler.classic.Assembler)

Example 44 with AppModule

use of org.apache.openejb.config.AppModule in project tomee by apache.

the class EjbSecurityRoleRefTest method testShouldCheckUserRole.

public void testShouldCheckUserRole() throws Exception {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean statelessBean = new StatelessBean(UserBean.class);
    final SecurityRoleRef securityRoleRef = new SecurityRoleRef();
    securityRoleRef.setRoleName("TEST");
    securityRoleRef.setRoleLink("committer");
    statelessBean.getSecurityRoleRef().add(securityRoleRef);
    ejbJar.addEnterpriseBean(statelessBean);
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "classpath-" + ejbJar.hashCode());
    app.getEjbModules().add(new EjbModule(ejbJar));
    assembler.createApplication(config.configureApplication(app));
    final User user = (User) context.lookup("UserBeanLocal");
    assertTrue(user.isUserInRole());
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) SecurityRoleRef(org.apache.openejb.jee.SecurityRoleRef) EjbJar(org.apache.openejb.jee.EjbJar)

Example 45 with AppModule

use of org.apache.openejb.config.AppModule in project tomee by apache.

the class OpenEJBXmlByModuleTest 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(OpenEJBXmlByModuleTest.class.getClassLoader(), OpenEJBXmlByModuleTest.class.getSimpleName());
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(UselessBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("META-INF/resource/appresource.openejb.xml"));
    assembler.createApplication(config.configureApplication(app));
    final Properties properties = new Properties();
    properties.setProperty(javax.naming.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 = (UselessBean) context.lookup("UselessBeanLocalBean");
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Aggregations

AppModule (org.apache.openejb.config.AppModule)51 EjbModule (org.apache.openejb.config.EjbModule)41 EjbJar (org.apache.openejb.jee.EjbJar)40 StatelessBean (org.apache.openejb.jee.StatelessBean)18 InitialContext (javax.naming.InitialContext)15 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)15 Properties (java.util.Properties)14 AppInfo (org.apache.openejb.assembler.classic.AppInfo)14 Assembler (org.apache.openejb.assembler.classic.Assembler)14 SingletonBean (org.apache.openejb.jee.SingletonBean)11 Test (org.junit.Test)10 WebModule (org.apache.openejb.config.WebModule)9 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)8 File (java.io.File)7 IOException (java.io.IOException)6 List (java.util.List)6 OpenEJBException (org.apache.openejb.OpenEJBException)6 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)6 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)6 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)6