Search in sources :

Example 46 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testSameDataSourceForBoth1.

/**
 * Existing data source "Orange", jta managed
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <jta-data-source>Orange</jta-data-source>
 * <non-jta-data-source>Orange</non-jta-data-source>
 * </persistence-unit>
 * <p/>
 * They used the same data source for both the
 * jta-data-source and non-jta-data-source and we
 * can determine the data source will not work as
 * a non-jta-data-source
 * <p/>
 * We should generate the missing data source for them
 * based on the one they supplied.
 *
 * @throws Exception
 */
public void testSameDataSourceForBoth1() throws Exception {
    final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", "orange");
    assertNotNull(unitInfo);
    final ResourceInfo generated = resources.get(1);
    assertEquals(supplied.id, unitInfo.jtaDataSource);
    assertEquals(generated.id, unitInfo.nonJtaDataSource);
    assertNotNull(generated);
    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 : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 47 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testJtaRefToContrarilyConfiguredDataSource.

// ---
/**
 * Existing data source "OrangeOne", not jta managed
 * Existing data source "OrangeTwo", not jta managed
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <jta-data-source>OrangeOne</jta-data-source>
 * <non-jta-data-source>OrangeTwo</non-jta-data-source>
 * </persistence-unit>
 * <p/>
 * This configuration should be rejected
 *
 * @throws Exception
 */
public void testJtaRefToContrarilyConfiguredDataSource() throws Exception {
    final ResourceInfo nonJta1 = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    final ResourceInfo nonJta2 = addDataSource("OrangeTwo", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(nonJta1, resources.get(0));
    assertSame(nonJta2, resources.get(1));
    try {
        addPersistenceUnit("orange-unit", "orangeOne", "orangeTwo");
        fail("Configuration should be rejected");
    } catch (final OpenEJBException e) {
    // pass
    }
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) OpenEJBException(org.apache.openejb.OpenEJBException)

Example 48 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testMissingJtaDataSource.

// ---
/**
 * Existing data source "Orange" not jta managed
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <non-jta-data-source>Orange</non-jta-data-source>
 * </persistence-unit>
 * <p/>
 * We should generate a <jta-data-source> based on
 * the <non-jta-data-source>
 *
 * @throws Exception
 */
public void testMissingJtaDataSource() throws Exception {
    final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, "orange");
    assertNotNull(unitInfo);
    final ResourceInfo generated = resources.get(1);
    assertEquals(supplied.id, unitInfo.nonJtaDataSource);
    assertEquals(generated.id, unitInfo.jtaDataSource);
    assertNotNull(generated);
    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 : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 49 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testThirdPartyDataSources2.

/**
 * Existing data source "Orange", not controlled by us
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <jta-data-source>Orange</jta-data-source>
 * </persistence-unit>
 * <p/>
 * Here we should just let them try and get by with
 * just the one data source.
 *
 * @throws Exception
 */
public void testThirdPartyDataSources2() throws Exception {
    final ResourceInfo dataSource = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", null);
    assertSame(dataSource, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", null);
    assertNotNull(unitInfo);
    assertEquals(dataSource.id, unitInfo.jtaDataSource);
    assertNull(unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 50 with ResourceInfo

use of org.apache.openejb.assembler.classic.ResourceInfo 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)

Aggregations

ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)66 PersistenceUnitInfo (org.apache.openejb.assembler.classic.PersistenceUnitInfo)31 Resource (org.apache.openejb.config.sys.Resource)14 OpenEJBException (org.apache.openejb.OpenEJBException)12 Properties (java.util.Properties)8 AppInfo (org.apache.openejb.assembler.classic.AppInfo)8 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)8 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)8 ArrayList (java.util.ArrayList)6 Assembler (org.apache.openejb.assembler.classic.Assembler)6 WebApp (org.apache.openejb.jee.WebApp)6 SuperProperties (org.apache.openejb.util.SuperProperties)6 Test (org.junit.Test)6 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)5 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)5 File (java.io.File)4 DataSource (javax.sql.DataSource)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 AppContext (org.apache.openejb.AppContext)3