Search in sources :

Example 46 with AppModule

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

the class ResourcesEarTest method checkAppModuleGetResources.

@Test
public void checkAppModuleGetResources() throws IOException, OpenEJBException {
    final File root = new File("target/ResourcesEarTest/myear/");
    final File temp = Files.mkdirs(new File(root, "META-INF/"));
    IO.copy(URLs.toFile(Thread.currentThread().getContextClassLoader().getResource("descriptor-resources.xml")), new File(temp, "resources.xml"));
    Files.deleteOnExit(root);
    final AtomicReference<AppModule> moduleAtomicReference = new AtomicReference<>();
    new DeploymentLoader() {

        {
            moduleAtomicReference.set(createAppModule(root.getAbsoluteFile(), root.getPath()));
        }
    };
    final AppModule object = moduleAtomicReference.get();
    assertNotNull(object);
    assertEquals(1, object.getResources().size());
    assertEquals("jdbc/descriptors", object.getResources().iterator().next().getId());
}
Also used : AppModule(org.apache.openejb.config.AppModule) DeploymentLoader(org.apache.openejb.config.DeploymentLoader) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) Test(org.junit.Test)

Example 47 with AppModule

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

the class DeploymentContextOptionsTest method testAllLevels.

public void testAllLevels() throws Exception {
    SystemInstance.get().setProperty("color", "orangeSystem");
    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 EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        {
            // Set at BeanContext level
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
            deployment.getProperties().put("color", "orangeBean");
        }
        {
            // Set at ModuleContext level
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            openejbJar.getProperties().put("color", "orangeModule");
        }
        final AppModule appModule = new AppModule(ejbModule);
        {
            // Set at AppContext level
            appModule.getProperties().put("color", "orangeApp");
        }
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orangeBean");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orangeModule");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orangeApp");
    assertOption(SystemInstance.get().getOptions(), "color", "orangeSystem");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 48 with AppModule

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

the class DeploymentContextOptionsTest method testSystemInstanceOptions.

public void testSystemInstanceOptions() throws Exception {
    SystemInstance.get().setProperty("color", "orange");
    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 EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final AppModule appModule = new AppModule(ejbModule);
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orange");
    assertOption(SystemInstance.get().getOptions(), "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 49 with AppModule

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

the class DeploymentContextPropertiesTest method testAppContextProperties.

public void testAppContextProperties() throws Exception {
    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 EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final AppModule appModule = new AppModule(ejbModule);
        appModule.getProperties().setProperty("color", "orange");
        final AppInfo appInfo = config.configureApplication(appModule);
        assertProperty(appInfo.properties, "color", "orange");
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getModuleContext().getAppContext().getProperties();
    assertProperty(properties, "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 50 with AppModule

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

the class PersistenceUnitLinkResolverTest method resolve.

@Test
public void resolve() {
    final AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "target/classes/foo", new Application(), false);
    Files.mkdir(new File("target/classes/foo/bar"));
    final PersistenceUnitLinkResolver resolver = new PersistenceUnitLinkResolver(appModule);
    resolver.add(URI.create("file:/fake/1"), "foo", new PersistenceUnit());
    resolver.add(URI.create("file:/fake/2"), "foo", new PersistenceUnit());
    // can't resolve but doesn't fail
    assertNull(resolver.resolveLink("foo", URI.create("bar")));
}
Also used : PersistenceUnitLinkResolver(org.apache.openejb.config.PersistenceUnitLinkResolver) AppModule(org.apache.openejb.config.AppModule) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) Application(org.apache.openejb.jee.Application) File(java.io.File) Test(org.junit.Test)

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