Search in sources :

Example 36 with AppInfo

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

the class AutoConfigPersistenceUnitsTest method testFromWebAppIdJta.

/**
 * Existing data source "orange-web", jta managed
 * <p/>
 * Application contains a web module with id "orange-id"
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit" />
 * <p/>
 * The orange-unit app should automatically use orange-id data source and create a new non-JtaManaged datasource
 *
 * @throws Exception
 */
public void testFromWebAppIdJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", true);
    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-id"));
    // Create app
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    // Check results
    final ResourceInfo generated = resources.get(1);
    assertEquals(supplied.id + "NonJta", 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("false", 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 37 with AppInfo

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

the class DeploymentsElementTest method deploymentsFile_and_Dir_Jars_Order.

/**
 * <Deployments dir="myapps/2000.jar"/>
 * <Deployments dir="myapps"/>
 * <p/>
 * Order should be guaranteed to be the same as
 * they are declared in the openejb.xml
 * <p/>
 * To test, the jars are named intentionally in an order
 * that would naturally sort to be the reverse.
 *
 * @throws Exception
 */
@Test
public void deploymentsFile_and_Dir_Jars_Order() throws Exception {
    final Server server = new Server();
    final File apps = Files.mkdir(server.getBase(), "myapps");
    {
        // Jar one
        final File jar = server.deploymentsFile("myapps/2000.jar");
        Archives.jarArchive(jar, null, Yellow.class);
    }
    {
        // Jar two
        server.deploymentsDir("myapps");
        final File jar = Files.path(apps, "1000.jar");
        Archives.jarArchive(jar, null, Orange.class);
    }
    final OpenEjbConfiguration configuration = server.init();
    assertEquals(2, configuration.containerSystem.applications.size());
    assertEquals("2000", configuration.containerSystem.applications.get(0).appId);
    assertEquals("1000", configuration.containerSystem.applications.get(1).appId);
    final AppInfo yellow = configuration.containerSystem.applications.get(0);
    assertEquals(1, yellow.ejbJars.size());
    assertEquals(1, yellow.ejbJars.get(0).enterpriseBeans.size());
    assertEquals("Yellow", yellow.ejbJars.get(0).enterpriseBeans.get(0).ejbName);
    final AppInfo orange = configuration.containerSystem.applications.get(1);
    assertEquals(1, orange.ejbJars.size());
    assertEquals(1, orange.ejbJars.get(0).enterpriseBeans.size());
    assertEquals("Orange", orange.ejbJars.get(0).enterpriseBeans.get(0).ejbName);
}
Also used : File(java.io.File) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 38 with AppInfo

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

the class DeploymentsElementTest method deployments_Duplicates.

/**
 * <Deployments dir="myapps/2000.jar"/>
 * <Deployments dir="myapps/2000.jar"/>
 * <Deployments dir="myapps"/>
 * <Deployments dir="myapps"/>
 * <p/>
 * Order should be guaranteed to be the same as
 * they are declared in the openejb.xml
 * <p/>
 * To test, the jars are named intentionally in an order
 * that would naturally sort to be the reverse.
 *
 * @throws Exception
 */
@Test
public void deployments_Duplicates() throws Exception {
    final Server server = new Server();
    final File apps = Files.mkdir(server.getBase(), "myapps");
    {
        // Jar one
        final File jar = server.deploymentsFile("myapps/2000.jar");
        server.deploymentsFile("myapps/2000.jar");
        Archives.jarArchive(jar, null, Yellow.class);
    }
    {
        // Jar two
        server.deploymentsDir("myapps");
        server.deploymentsDir("myapps");
        final File jar = Files.path(apps, "1000.jar");
        Archives.jarArchive(jar, null, Orange.class);
    }
    final OpenEjbConfiguration configuration = server.init();
    assertEquals(2, configuration.containerSystem.applications.size());
    assertEquals("2000", configuration.containerSystem.applications.get(0).appId);
    assertEquals("1000", configuration.containerSystem.applications.get(1).appId);
    final AppInfo yellow = configuration.containerSystem.applications.get(0);
    assertEquals(1, yellow.ejbJars.size());
    assertEquals(1, yellow.ejbJars.get(0).enterpriseBeans.size());
    assertEquals("Yellow", yellow.ejbJars.get(0).enterpriseBeans.get(0).ejbName);
    final AppInfo orange = configuration.containerSystem.applications.get(1);
    assertEquals(1, orange.ejbJars.size());
    assertEquals(1, orange.ejbJars.get(0).enterpriseBeans.size());
    assertEquals("Orange", orange.ejbJars.get(0).enterpriseBeans.get(0).ejbName);
}
Also used : File(java.io.File) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 39 with AppInfo

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

the class DeploymentsElementTest method deploymentsDir_Jars_Packed.

/**
 * <Deployments dir="myapps"/>
 * <p/>
 * Two ejb jars
 *
 * @throws Exception
 */
@Test
public void deploymentsDir_Jars_Packed() throws Exception {
    final Server server = new Server();
    final File apps = server.deploymentsDir("myapps");
    {
        // Jar one
        final File ear = new File(apps, "yellow.jar");
        Archives.jarArchive(ear, null, Yellow.class);
    }
    {
        // Jar two
        final File ear = new File(apps, "orange.jar");
        Archives.jarArchive(ear, null, Orange.class);
    }
    final OpenEjbConfiguration configuration = server.init();
    assertEquals(2, configuration.containerSystem.applications.size());
    final AppInfo yellow = select(configuration.containerSystem.applications, "yellow");
    assertEquals(1, yellow.ejbJars.size());
    assertEquals(1, yellow.ejbJars.get(0).enterpriseBeans.size());
    assertEquals("Yellow", yellow.ejbJars.get(0).enterpriseBeans.get(0).ejbName);
    final AppInfo orange = select(configuration.containerSystem.applications, "orange");
    assertEquals(1, orange.ejbJars.size());
    assertEquals(1, orange.ejbJars.get(0).enterpriseBeans.size());
    assertEquals("Orange", orange.ejbJars.get(0).enterpriseBeans.get(0).ejbName);
}
Also used : File(java.io.File) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) AppInfo(org.apache.openejb.assembler.classic.AppInfo) Test(org.junit.Test)

Example 40 with AppInfo

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

the class EarModuleNamesTest method testIdEjbJar.

@Test
public void testIdEjbJar() throws Exception {
    final File appsDir = Files.tmpdir();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final File ear = new File(appsDir, "testIdEjbJar.ear");
    final Map<String, Object> metaInf = new HashMap<String, Object>();
    metaInf.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"testIdEjbJar\" />");
    final File ejbJar = Archives.jarArchive(metaInf, "testIdEjbJar", Orange.class);
    final Map<String, Object> contents = new HashMap<String, Object>();
    contents.put("green.jar", ejbJar);
    Archives.jarArchive(ear, contents);
    final AppInfo appInfo = factory.configureApplication(ear);
    assertEquals(appInfo.ejbJars.size(), 1);
    assertEquals("testIdEjbJar", appInfo.ejbJars.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)

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