Search in sources :

Example 61 with EjbModule

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

the class NoMessageDeliveryTest 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));
    // Setup the descriptor information
    EmailBean.lifecycle.clear();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
    final Connector connector = new Connector("email-ra");
    final ResourceAdapter adapter = new ResourceAdapter(EmailResourceAdapter.class);
    connector.setResourceAdapter(adapter);
    final InboundResourceadapter inbound = adapter.setInboundResourceAdapter(new InboundResourceadapter());
    final MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
    final MessageListener listener = messageAdapter.addMessageListener(new MessageListener(EmailConsumer.class, EmailAccountInfo.class));
    listener.getActivationSpec().addRequiredConfigProperty("address");
    app.getConnectorModules().add(new ConnectorModule(connector));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final InitialContext initialContext = new InitialContext();
    final EmailResourceAdapter ra = (EmailResourceAdapter) initialContext.lookup("java:openejb/Resource/email-raRA");
    final Properties headers = new Properties();
    headers.put("To", "dblevins@apache.org");
    headers.put("From", "dblevins@visi.com");
    headers.put("Subject", "Hello");
    ra.deliverEmail(headers, "How's it going?");
    final Stack<Lifecycle> lifecycle = EmailBean.lifecycle;
    final List expected = Arrays.asList(Lifecycle.CONSTRUCTOR, Lifecycle.INJECTION, Lifecycle.POST_CONSTRUCT);
    Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
}
Also used : Connector(org.apache.openejb.jee.Connector) AppModule(org.apache.openejb.config.AppModule) MessageListener(org.apache.openejb.jee.MessageListener) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Properties(java.util.Properties) ConnectorModule(org.apache.openejb.config.ConnectorModule) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) MessageAdapter(org.apache.openejb.jee.MessageAdapter) InitialContext(javax.naming.InitialContext) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) Assembler(org.apache.openejb.assembler.classic.Assembler)

Example 62 with EjbModule

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

the class Compat3to2Test 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.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // containers
    final StatefulSessionContainerInfo statefulContainerInfo = config.configureService(StatefulSessionContainerInfo.class);
    statefulContainerInfo.properties.setProperty("PoolSize", "0");
    statefulContainerInfo.properties.setProperty("BulkPassivate", "1");
    statefulContainerInfo.properties.setProperty("Frequency", "0");
    assembler.createContainer(statefulContainerInfo);
    final EjbJar ejbJar = new EjbJar();
    final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(TargetBean.class));
    bean.setHomeAndRemote(TargetHome.class, Target.class);
    assembler.createApplication(config.configureApplication(new EjbModule(getClass().getClassLoader(), getClass().getSimpleName(), "test", ejbJar, null)));
    calls.clear();
    final InitialContext ctx = new InitialContext();
    final TargetHome home = (TargetHome) ctx.lookup("TargetBeanRemoteHome");
    assertNotNull(home);
    final Target target = home.create("Fuzz");
    assertNotNull(target);
    final String name = target.getName();
    assertEquals("Fuzz", name);
    target.remove();
    assertCalls(Call.values());
}
Also used : StatefulSessionContainerInfo(org.apache.openejb.assembler.classic.StatefulSessionContainerInfo) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 63 with EjbModule

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

the class EntityManagerPropogationTest method setUp.

public void setUp() throws OpenEJBException, IOException, NamingException {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    System.setProperty("openejb.embedded", "true");
    // Boot up the minimum required OpenEJB components
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Start creating the test application
    // Create an ejb-jar.xml for this app
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean("PleaseCloseMyExtendedEm", PleaseCloseMyExtendedEmBean.class));
    ejbJar.addEnterpriseBean(new StatefulBean("PleaseCloseMyEm", PleaseCloseMyEmBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("PleaseCloseMyLessEm", PleaseCloseMyEmBean.class));
    // Add six beans and link them all in a chain
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extended", "Extendedx2");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx2", "Extendedx3");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx3", "Extendedx4");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx4", "Extendedx5");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "ExtendedToTransaction", "StatelessTransactionToExtended");
    addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx5", "Extendedx6");
    ejbJar.addEnterpriseBean(new StatefulBean("Extendedx6", EndNodeBean.class));
    // Add six beans and link them all in a chain
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transaction", "Transactionx2");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx2", "Transactionx3");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx3", "Transactionx4");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx4", "Transactionx5");
    addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx5", "Transactionx6");
    addStatefulBean(ejbJar, TransactionContextBean.class, "TransactionToExtended", "Extendedx5");
    addStatelessBean(ejbJar, TransactionContextBean.class, "StatelessTransactionToExtended", "Extendedx5");
    ejbJar.addEnterpriseBean(new StatefulBean("Transactionx6", EndNodeBean.class));
    ejbJar.setAssemblyDescriptor(new AssemblyDescriptor());
    ejbJar.getAssemblyDescriptor().addApplicationException(IllegalArgumentException.class, false, true);
    ejbJar.getAssemblyDescriptor().addApplicationException(ArgumentException.class, false, true);
    // List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    // declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(), "Extendedx5", "*"));
    // declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(), "TransactionToExtended", "*"));
    final EjbModule ejbModule = new EjbModule(ejbJar);
    // Create an "ear"
    final AppModule appModule = new AppModule(ejbModule.getClassLoader(), "test-app");
    // Add the ejb-jar.xml to the ear
    appModule.getEjbModules().add(ejbModule);
    // Create a persistence-unit for this app
    final PersistenceUnit unit = new PersistenceUnit("testUnit");
    unit.addClass(Color.class);
    unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
    unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported");
    // Add the persistence.xml to the "ear"
    appModule.addPersistenceModule(new PersistenceModule("root", new Persistence(unit)));
    // Configure and assemble the ear -- aka. deploy it
    final AppInfo info = config.configureApplication(appModule);
    assembler.createApplication(info);
}
Also used : AppModule(org.apache.openejb.config.AppModule) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) PersistenceModule(org.apache.openejb.config.PersistenceModule) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Persistence(org.apache.openejb.jee.jpa.unit.Persistence) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 64 with EjbModule

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

the class StatefulConstructorInjectionTest 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.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // Setup the descriptor information
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
    final StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(WidgetBean.class));
    bean.getEnvEntry().add(new EnvEntry("count", Integer.class.getName(), "10"));
    final EjbModule module = new EjbModule(ejbJar);
    module.setBeans(new Beans());
    assembler.createApplication(config.configureApplication(module));
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) Beans(org.apache.openejb.jee.Beans) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) EnvEntry(org.apache.openejb.jee.EnvEntry)

Example 65 with EjbModule

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

the class StatefulInterceptorTest method buildTestApp.

public EjbModule buildTestApp() {
    final EjbJar ejbJar = new EjbJar();
    final AssemblyDescriptor ad = ejbJar.getAssemblyDescriptor();
    final EnterpriseBean bean = ejbJar.addEnterpriseBean(new StatefulBean(TargetBean.class));
    Interceptor interceptor;
    interceptor = ejbJar.addInterceptor(new Interceptor(ClassInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
    interceptor = ejbJar.addInterceptor(new Interceptor(DefaultInterceptor.class));
    ad.addInterceptorBinding(new InterceptorBinding("*", interceptor));
    interceptor = ejbJar.addInterceptor(new Interceptor(EchoMethodInterceptor.class));
    final InterceptorBinding binding = ad.addInterceptorBinding(new InterceptorBinding(bean, interceptor));
    binding.setMethod(new NamedMethod("echo"));
    return new EjbModule(this.getClass().getClassLoader(), this.getClass().getSimpleName(), "test", ejbJar, null);
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) StatefulBean(org.apache.openejb.jee.StatefulBean) EjbModule(org.apache.openejb.config.EjbModule) AssemblyDescriptor(org.apache.openejb.jee.AssemblyDescriptor) NamedMethod(org.apache.openejb.jee.NamedMethod) Interceptor(org.apache.openejb.jee.Interceptor) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)91 EjbJar (org.apache.openejb.jee.EjbJar)81 AppModule (org.apache.openejb.config.AppModule)41 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)30 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)27 Properties (java.util.Properties)24 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)20 Module (org.apache.openejb.testing.Module)18 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)13 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)13 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)11 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9