Search in sources :

Example 51 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testInvalidOptionsJta.

// ---
/**
 * Existing data source "Orange", not jta managed
 * Existing data source "Lime", 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>.  We should not select
 * the Lime datasource which is for a different database.
 *
 * @throws Exception
 */
public void testInvalidOptionsJta() throws Exception {
    final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    final ResourceInfo badMatch = addDataSource("Lime", LimeDriver.class, "jdbc:lime:some:stuff", true);
    assertSame(supplied, resources.get(0));
    assertSame(badMatch, resources.get(1));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", null, "orange");
    assertNotNull(unitInfo);
    final ResourceInfo generated = resources.get(2);
    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 52 with ResourceInfo

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

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

the class AutoConfigPersistenceUnitsTest method testPossiblyAmbiguousNonJtaOptions.

/**
 * Existing data source "Orange", jta managed
 * Existing data source "Lime", not jta managed
 * Existing data source "OrangeUnamanged", not jta managed
 * <p/>
 * Persistence xml like so:
 * <p/>
 * <persistence-unit name="orange-unit">
 * <jta-data-source>Orange</jta-data-source>
 * </persistence-unit>
 * <p/>
 * We should select the <non-jta-data-source> based on
 * the closest match to the <jta-data-source>
 *
 * @throws Exception
 */
public void testPossiblyAmbiguousNonJtaOptions() throws Exception {
    final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
    final ResourceInfo badMatch = addDataSource("Lime", LimeDriver.class, "jdbc:lime:some:stuff", false);
    final ResourceInfo goodMatch = addDataSource("OrangeUnmanaged", OrangeDriver.class, "jdbc:orange:some:stuff", false);
    assertSame(supplied, resources.get(0));
    assertSame(badMatch, resources.get(1));
    assertSame(goodMatch, resources.get(2));
    final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", null);
    assertNotNull(unitInfo);
    assertEquals(supplied.id, unitInfo.jtaDataSource);
    assertEquals(goodMatch.id, unitInfo.nonJtaDataSource);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 54 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testFromUnitNameJtaWithClasspath.

/**
 * Existing data source "orange-unit", 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 non-JtaManaged datasource
 *
 * @throws Exception
 */
public void testFromUnitNameJtaWithClasspath() throws Exception {
    final Resource resource = new Resource("orange-unit", "DataSource");
    final File file = new File("target/" + getClass().getName());
    file.mkdirs();
    resource.setClasspath(file.getPath());
    final ResourceInfo supplied = addDataSource(OrangeDriver.class, "jdbc:orange:some:stuff", true, resource);
    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"));
    final String expected = Join.join("\n", supplied.classpath);
    final String actual = Join.join("\n", generated.classpath);
    assertEquals(expected, actual);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) Resource(org.apache.openejb.config.sys.Resource) File(java.io.File) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo)

Example 55 with ResourceInfo

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

the class AutoConfigPersistenceUnitsTest method testShortName.

/**
 * 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>java:foo/bar/baz/Orange</jta-data-source>
 * <non-jta-data-source>java:foo/bar/baz/OrangeUnamanged</non-jta-data-source>
 * </persistence-unit>
 * <p/>
 * The datasources should be mapped correctly despite the
 * vendor specific prefix.
 *
 * @throws Exception
 */
public void testShortName() 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", "java:foo/bar/baz/orange", "java:foo/bar/baz/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)

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