Search in sources :

Example 21 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class SimplePojoTest method war.

@Module
@Classes(cdi = true, value = { MyFirstRestClass.class })
public WebModule war() {
    final WebModule webModule = new WebModule(new WebApp(), "/foo", Thread.currentThread().getContextClassLoader(), "", "foo");
    webModule.getRestClasses().add(MyFirstRestClass.class.getName());
    return webModule;
}
Also used : MyFirstRestClass(org.apache.openejb.server.cxf.rs.beans.MyFirstRestClass) WebModule(org.apache.openejb.config.WebModule) WebApp(org.apache.openejb.jee.WebApp) WebModule(org.apache.openejb.config.WebModule) Module(org.apache.openejb.testing.Module) Classes(org.apache.openejb.testing.Classes)

Example 22 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testFromWebAppIdThirdParty.

/**
 * Existing data source "orange-id", not controlled by us
 * <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 the non-jta-datasource should be null
 *
 * @throws Exception
 */
public void testFromWebAppIdThirdParty() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-id", 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, null, "orange-id"));
    // 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)

Example 23 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testFromWebAppContextJta.

/**
 * Existing data source "orange-web", 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 testFromWebAppContextJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-web", 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-web"));
    // 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 24 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class AutoConfigPersistenceUnitsTest method testFromWebAppIdNonJta.

/**
 * Existing data source "orange-id", non-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 testFromWebAppIdNonJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-id", 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-id"));
    // 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 25 with WebApp$JAXB

use of org.apache.openejb.jee.WebApp$JAXB in project tomee by apache.

the class ConfigurationFactoryTest method testConfigureApplicationWebModule.

@Test
public void testConfigureApplicationWebModule() throws OpenEJBException {
    SystemInstance.get().setProperty("openejb.environment.default", "false");
    final String moduleId = "testConfigureApplicationWebModule";
    final String fileSeparator = System.getProperty("file.separator");
    SystemInstance.get().setProperty(ConfigurationFactory.VALIDATION_SKIP_PROPERTY, "false");
    SystemInstance.get().setProperty(DeploymentsResolver.SEARCH_CLASSPATH_FOR_DEPLOYMENTS_PROPERTY, "false");
    final ConfigurationFactory factory = new ConfigurationFactory();
    final WebApp webApp = new WebApp();
    // no real classes engaged so disable metadata (annotation) processing
    webApp.setMetadataComplete(true);
    final WebModule webModule = new WebModule(webApp, null, null, fileSeparator + "some" + fileSeparator + "where.war", moduleId);
    final WebAppInfo info = factory.configureApplication(webModule);
    assertEquals(moduleId, info.moduleId);
    SystemInstance.get().getProperties().remove("openejb.environment.default");
}
Also used : WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) WebApp(org.apache.openejb.jee.WebApp) Test(org.junit.Test)

Aggregations

WebApp (org.apache.openejb.jee.WebApp)24 AppInfo (org.apache.openejb.assembler.classic.AppInfo)7 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)7 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)7 File (java.io.File)6 IOException (java.io.IOException)6 URL (java.net.URL)6 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)6 WebModule (org.apache.openejb.config.WebModule)5 MalformedURLException (java.net.MalformedURLException)4 LinkedHashSet (java.util.LinkedHashSet)4 JarFile (java.util.jar.JarFile)4 HashSet (java.util.HashSet)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)3 EjbJar (org.apache.openejb.jee.EjbJar)3 InputStream (java.io.InputStream)2 URLClassLoader (java.net.URLClassLoader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2