Search in sources :

Example 31 with AppInfo

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

the class ApplicationPropertiesTest method testOverrideAdd.

public void testOverrideAdd() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("fooApp.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 32 with AppInfo

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

the class ApplicationPropertiesTest method testOverrideUnprefixedVsPrefixedOpenEJB.

public void testOverrideUnprefixedVsPrefixedOpenEJB() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("openejb.fooApp.color", "orange");
        SystemInstance.get().getProperties().put("fooApp.color", "green");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 33 with AppInfo

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

the class ApplicationWideTest method testShouldCreateAResourceAndNotRemoveOnUndeploy.

public void testShouldCreateAResourceAndNotRemoveOnUndeploy() throws Exception {
    final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
    final EjbJar ejbJar = ejbModule.getEjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(EchoBean.class));
    final AppModule appModule = new AppModule(ejbModule);
    final Container container = new Container();
    container.setId("My Container");
    container.setCtype("STATELESS");
    container.getProperties().setProperty("ApplicationWide", "true");
    appModule.getContainers().add(container);
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    final AppInfo appInfo = config.configureApplication(appModule);
    assembler.createApplication(appInfo);
    {
        final ContainerSystem containerSystem = assembler.getContainerSystem();
        final org.apache.openejb.Container appContainer = containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
        assertNotNull(appContainer);
    }
    assembler.destroyApplication(appInfo);
    {
        final ContainerSystem containerSystem = assembler.getContainerSystem();
        final org.apache.openejb.Container appContainer = containerSystem.getContainer(ejbModule.getModuleId() + "/My Container");
        assertNotNull(appContainer);
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Container(org.apache.openejb.config.sys.Container) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 34 with AppInfo

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

the class AutoConfigPersistenceUnitsTest method testFromWebAppContextNonJta.

/**
 * Existing data source "orange-web", non-jta managed
 * <p/>
 * Application contains a web module with root context path as "orange-web"
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit" />
 * <p/>
 * The orange-unit app should automatically use orange-web data source and create a new non-JtaManaged datasource
 *
 * @throws Exception
 */
public void testFromWebAppContextNonJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", false);
    assertSame(supplied, resources.get(0));
    final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");
    final ClassLoader cl = this.getClass().getClassLoader();
    final AppModule app = new AppModule(cl, "orange-app");
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
    final WebApp webApp = new WebApp();
    webApp.setMetadataComplete(true);
    app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
    // Create app
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    // Check results
    final ResourceInfo generated = resources.get(1);
    assertEquals(supplied.id + "Jta", generated.id);
    assertEquals(supplied.service, generated.service);
    assertEquals(supplied.className, generated.className);
    assertEquals(supplied.properties.get("JdbcDriver"), generated.properties.get("JdbcDriver"));
    assertEquals(supplied.properties.get("JdbcUrl"), generated.properties.get("JdbcUrl"));
    assertEquals("true", generated.properties.get("JtaManaged"));
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) WebApp(org.apache.openejb.jee.WebApp) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 35 with AppInfo

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

the class AutoConfigPersistenceUnitsTest method testFromWebAppContextThirdParty.

/**
 * Existing data source "orange-web", not controlled by us
 * <p/>
 * Application contains a web module with root context path as "orange-web"
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit" />
 * <p/>
 * The orange-unit app should automatically use orange-web data source and the non-jta-datasource should be null
 *
 * @throws Exception
 */
public void testFromWebAppContextThirdParty() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
    assertSame(supplied, resources.get(0));
    final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");
    final ClassLoader cl = this.getClass().getClassLoader();
    final AppModule app = new AppModule(cl, "orange-app");
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
    final WebApp webApp = new WebApp();
    webApp.setMetadataComplete(true);
    app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
    // Create app
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    final PersistenceUnitInfo unitInfo = appInfo.persistenceUnits.get(0);
    // Check results
    assertEquals(supplied.id, unitInfo.jtaDataSource);
    assertNull(unitInfo.nonJtaDataSource);
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo) WebApp(org.apache.openejb.jee.WebApp) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

AppInfo (org.apache.openejb.assembler.classic.AppInfo)109 File (java.io.File)49 Assembler (org.apache.openejb.assembler.classic.Assembler)49 Test (org.junit.Test)31 HashMap (java.util.HashMap)29 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)25 EjbJar (org.apache.openejb.jee.EjbJar)17 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)16 ContainerSystem (org.apache.openejb.spi.ContainerSystem)15 OpenEJBException (org.apache.openejb.OpenEJBException)14 AppModule (org.apache.openejb.config.AppModule)14 Map (java.util.Map)12 EjbModule (org.apache.openejb.config.EjbModule)11 Properties (java.util.Properties)10 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)10 ArrayList (java.util.ArrayList)9 InitialContext (javax.naming.InitialContext)9 StatelessBean (org.apache.openejb.jee.StatelessBean)9 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)9 IOException (java.io.IOException)8