Search in sources :

Example 26 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class EarModuleNamesTest method testDefaultIdWebapp.

@Test
public void testDefaultIdWebapp() throws Exception {
    final File appsDir = Files.tmpdir();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final File ear = new File(appsDir, "testDefaultIdWebapp.ear");
    final Map<String, Object> contents = new HashMap<String, Object>();
    contents.put("testDefaultIdWebapp.war", Archives.jarArchive(Orange.class));
    Archives.jarArchive(ear, contents);
    final AppInfo appInfo = factory.configureApplication(ear);
    assertEquals(appInfo.ejbJars.size(), 1);
    assertEquals("testDefaultIdWebapp", appInfo.webApps.get(0).moduleId);
}
Also used : HashMap(java.util.HashMap) Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 27 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class OpenEjbContainer method doClose.

private synchronized void doClose() {
    if (instance == null) {
        return;
    }
    if (serviceManager != null) {
        serviceManager.stop();
    }
    try {
        globalJndiContext.close();
    } catch (final NamingException e) {
        throw new IllegalStateException(e);
    }
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    if (assembler != null) {
        for (final AppInfo info : assembler.getDeployedApplications()) {
            try {
                assembler.destroyApplication(info);
            } catch (final UndeployException e) {
                logger().error(e.getMessage(), e);
            }
        }
    }
    if (webBeanContext != null) {
        try {
            stopContexts(webBeanContext.getContextsService(), servletContext, session);
        } catch (final Exception e) {
            logger().warning("can't stop all CDI contexts", e);
        }
    }
    logger().info("Destroying OpenEJB container");
    OpenEJB.destroy();
    instance = null;
}
Also used : NamingException(javax.naming.NamingException) Assembler(org.apache.openejb.assembler.classic.Assembler) NamingException(javax.naming.NamingException) EJBException(javax.ejb.EJBException) ValidationFailedException(org.apache.openejb.config.ValidationFailedException) NameNotFoundException(javax.naming.NameNotFoundException) MalformedURLException(java.net.MalformedURLException) ValidationException(javax.validation.ValidationException) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 28 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class QuartzMdbContainerTest 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
    CronBean.lifecycle.clear();
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
    final Connector connector = new Connector("email-ra");
    final ResourceAdapter adapter = new ResourceAdapter(QuartzResourceAdapter.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(Job.class, JobSpec.class));
    listener.getActivationSpec().addRequiredConfigProperty("cronExpression");
    app.getConnectorModules().add(new ConnectorModule(connector));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new MessageDrivenBean(CronBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    assertTrue(CronBean.latch.await(5, TimeUnit.SECONDS));
    final Stack<Lifecycle> lifecycle = CronBean.lifecycle;
    final List expected = Arrays.asList(Lifecycle.values());
    Assert.assertEquals(expected.get(0), lifecycle.get(0));
    Assert.assertEquals(expected.get(1), lifecycle.get(1));
}
Also used : Connector(org.apache.openejb.jee.Connector) MessageAdapter(org.apache.openejb.jee.MessageAdapter) 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) ConnectorModule(org.apache.openejb.config.ConnectorModule) AppInfo(org.apache.openejb.assembler.classic.AppInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) QuartzResourceAdapter(org.apache.openejb.resource.quartz.QuartzResourceAdapter) ResourceAdapter(org.apache.openejb.jee.ResourceAdapter) List(java.util.List) Assembler(org.apache.openejb.assembler.classic.Assembler) JobSpec(org.apache.openejb.resource.quartz.JobSpec) InboundResourceadapter(org.apache.openejb.jee.InboundResourceadapter) Job(org.apache.openejb.quartz.Job) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 29 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo in project tomee by apache.

the class DependsOnTest method testNoStartUp.

public void testNoStartUp() 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));
    actualConstruct.clear();
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Two.class)).setInitOnStartup(false);
    ejbJar.addEnterpriseBean(new SingletonBean(One.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Four.class)).setInitOnStartup(false);
    ejbJar.addEnterpriseBean(new SingletonBean(Three.class)).setInitOnStartup(false);
    // 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);
}
Also used : ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 30 with AppInfo

use of org.apache.openejb.assembler.classic.AppInfo 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);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) AppInfo(org.apache.openejb.assembler.classic.AppInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) SingletonBean(org.apache.openejb.jee.SingletonBean) 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) SingletonSessionContainerInfo(org.apache.openejb.assembler.classic.SingletonSessionContainerInfo) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)106 File (java.io.File)50 Assembler (org.apache.openejb.assembler.classic.Assembler)46 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 OpenEJBException (org.apache.openejb.OpenEJBException)15 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)13 EjbJar (org.apache.openejb.jee.EjbJar)13 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13 Properties (java.util.Properties)10 EjbModule (org.apache.openejb.config.EjbModule)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8 URL (java.net.URL)8 InitialContext (javax.naming.InitialContext)8