Search in sources :

Example 6 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testEmptyUnitOneAvailableNonJtaDataSource.

// ---
/**
     * Existing data source "Orange", not jta managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit">
     * </persistence-unit>
     * <p/>
     * The <non-jta-data-source> should be auto linked
     * to the Orange data source
     * <p/>
     * We should generate a <jta-data-source> based on
     * the <non-jta-data-source>
     *
     * @throws Exception
     */
public void testEmptyUnitOneAvailableNonJtaDataSource() 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, null);
    assertNotNull(unitInfo);
    final ResourceInfo generated = resources.get(1);
    assertEquals(generated.id, unitInfo.jtaDataSource);
    assertEquals(supplied.id, unitInfo.nonJtaDataSource);
    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 7 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testFromAppIdNonJta.

/**
     * Existing data source "orange-unit-app", non-jta-managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit" />
     * <p/>
     * The app module id is orange-unit-app. Use orange-unit-app data source and create a new JtaManaged datasource
     *
     * @throws Exception
     */
public void testFromAppIdNonJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-unit-app", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
    assertNotNull(unitInfo);
    // 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 : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 8 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testFromUnitNameNonJta.

/**
     * Existing data source "orange-unit", non-jta-managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit" />
     * <p/>
     * The orange-unit app should automatically use orange-unit data source and create a new JtaManaged datasource
     *
     * @throws Exception
     */
public void testFromUnitNameNonJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-unit", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
    assertNotNull(unitInfo);
    // 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 : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 9 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testFromAppIdJta.

/**
     * Existing data source "orange-unit-app", jta-managed
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit" />
     * <p/>
     * The app module id is orange-unit-app. Use orange-unit-app data source and create a new non-JtaManaged datasource
     *
     * @throws Exception
     */
public void testFromAppIdJta() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-unit-app", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
    assertNotNull(unitInfo);
    // 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 : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 10 with PersistenceUnitInfo

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

the class AutoConfigPersistenceUnitsTest method testFromAppIdThirdParty.

/**
     * Existing data source "orange-unit-app", not controlled by us
     * <p/>
     * Persistence xml like so:
     * <p/>
     * <persistence-unit name="orange-unit" />
     * <p/>
     * The app module id is orange-unit-app. The jta data source should be orange-unit-app and the non-jta-data-source should be null
     *
     * @throws Exception
     */
public void testFromAppIdThirdParty() throws Exception {
    final ResourceInfo supplied = addDataSource("orange-unit-app", OrangeDriver.class, "jdbc:orange:some:stuff", null);
    assertSame(supplied, resources.get(0));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, null);
    assertNotNull(unitInfo);
    //Check results
    assertEquals(supplied.id, unitInfo.jtaDataSource);
    assertNull(unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

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