Search in sources :

Example 26 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testEmptyUnitNoAvailableDataSources.

// ---
/**
     * Existing data source "Orange", not jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * </persistence-unit>
     * <p/>
     * A set of default data sources should be generated
     * <p/>
     * The <non-jta-data-source> should be auto linked
     * to the Default JDBC Database data source
     * <p/>
     * The <jta-data-source> should be auto linked
     * to the Default Unmanaged JDBC Database data source
     *
     * @throws Exception
     */
public void testEmptyUnitNoAvailableDataSources() throws Exception {
    assertEquals(0, resources.size());
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
    assertNotNull(unitInfo);
    final ResourceInfo jta = resources.get(0);
    final ResourceInfo nonJta = resources.get(1);
    assertEquals("Default JDBC Database", jta.id);
    assertEquals("Default Unmanaged JDBC Database", nonJta.id);
    assertEquals(jta.id, unitInfo.jtaDataSource);
    assertEquals(nonJta.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 27 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method test.

/**
     * Existing data source "Orange", jta managed
     * Existing data source "OrangeUnmanaged", not jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * <jta-data-source>Orange</jta-data-source>
     * <non-jta-data-source>OrangeUnamanged</non-jta-data-source>
     * </persistence-unit>
     * <p/>
     * This is the happy path.
     *
     * @throws Exception
     */
public void test() throws Exception {
    final ResourceInfo jta = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    final ResourceInfo nonJta = addDataSource("OrangeUnmanaged", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(jta, resources.get(0));
    assertSame(nonJta, resources.get(1));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", "orangeUnmanaged");
    assertNotNull(unitInfo);
    assertEquals(jta.id, unitInfo.jtaDataSource);
    assertEquals(nonJta.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 28 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo 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 29 with PersistenceUnitInfo

use of org.apache.openejb.assembler.classic.PersistenceUnitInfo 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 30 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testMultiple.

/**
     * Existing data source "Orange", jta managed
     * Existing data source "OrangeUnmanaged", not jta managed
     * Existing data source "Lime", jta managed
     * Existing data source "LimeUnmanaged", not jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * <jta-data-source>Orange</jta-data-source>
     * <non-jta-data-source>OrangeUnmanaged</non-jta-data-source>
     * </persistence-unit>
     * <persistence-unit name="lime-unit">
     * <jta-data-source>Lime</jta-data-source>
     * <non-jta-data-source>LimeUnmanaged</non-jta-data-source>
     * </persistence-unit>
     * <p/>
     * This is the happy path.
     *
     * @throws Exception
     */
public void testMultiple() throws Exception {
    final ResourceInfo orangeJta = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    final ResourceInfo orangeNonJta = addDataSource("OrangeUnmanaged", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    final ResourceInfo limeJta = addDataSource("Lime", LimeDriver.class, "jdbc:lime:some:stuff", true);
    final ResourceInfo limeNonJta = addDataSource("LimeUnmanaged", LimeDriver.class, "jdbc:lime:some:stuff", false);
    assertSame(orangeJta, resources.get(0));
    assertSame(orangeNonJta, resources.get(1));
    assertSame(limeJta, resources.get(2));
    assertSame(limeNonJta, resources.get(3));
    final PersistenceUnit unit1 = new PersistenceUnit("orange-unit");
    unit1.setJtaDataSource("Orange");
    unit1.setNonJtaDataSource("OrangeUnmanaged");
    final PersistenceUnit unit2 = new PersistenceUnit("lime-unit");
    unit2.setJtaDataSource("Lime");
    unit2.setNonJtaDataSource("LimeUnmanaged");
    final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
    app.addPersistenceModule(new PersistenceModule("root", new Persistence(unit1, unit2)));
    // Create app
    final AppInfo appInfo = config.configureApplication(app);
    assembler.createApplication(appInfo);
    // Check results
    final PersistenceUnitInfo orangeUnit = appInfo.persistenceUnits.get(0);
    final PersistenceUnitInfo limeUnit = appInfo.persistenceUnits.get(1);
    assertNotNull(orangeUnit);
    assertEquals(orangeJta.id, orangeUnit.jtaDataSource);
    assertEquals(orangeNonJta.id, orangeUnit.nonJtaDataSource);
    assertNotNull(limeUnit);
    assertEquals(limeJta.id, limeUnit.jtaDataSource);
    assertEquals(limeNonJta.id, limeUnit.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) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Aggregations

PersistenceUnitInfo (org.apache.openejb.assembler.classic.PersistenceUnitInfo)35 ResourceInfo (org.apache.openejb.assembler.classic.ResourceInfo)31 AppInfo (org.apache.openejb.assembler.classic.AppInfo)5 File (java.io.File)3 URL (java.net.URL)3 Assembler (org.apache.openejb.assembler.classic.Assembler)3 Persistence (org.apache.openejb.jee.jpa.unit.Persistence)3 PersistenceUnit (org.apache.openejb.jee.jpa.unit.PersistenceUnit)3 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NameNotFoundException (javax.naming.NameNotFoundException)1