Search in sources :

Example 16 with PersistenceUnitInfo

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

the class AltDDPrefixTest method testPersistenceUnitWithAllDD.

/**
     * OPENEJB-1059: altdd does not work with a persistence.xml when no embedded
     * in EjbModule/Client module.
     *
     * @throws Exception if something wrong happen
     */
public void testPersistenceUnitWithAllDD() throws Exception {
    System.out.println("*** testPersistenceUnitWithAllDD ***");
    final Assembler assmbler = new Assembler();
    // TODO should be better to add a remove property method
    SystemInstance.get().getProperties().remove("openejb.altdd.prefix");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddPU1");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(0, appInfo.ejbJars.size());
    assertEquals(1, appInfo.persistenceUnits.size());
    final PersistenceUnitInfo info = appInfo.persistenceUnits.get(0);
    // a space must be present before hashcode
    assertTrue(info.id.startsWith("unit "));
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 17 with PersistenceUnitInfo

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

the class AltDDPrefixTest method testPersistenceUnit.

/**
     * OPENEJB-1059: altdd does not work with a persistence.xml when no embedded
     * in EjbModule/Client module.
     *
     * @throws Exception if something wrong happen
     */
public void testPersistenceUnit() throws Exception {
    System.out.println("*** testPersistenceUnit ***");
    final Assembler assmbler = new Assembler();
    SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddPU1");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(0, appInfo.ejbJars.size());
    assertEquals(1, appInfo.persistenceUnits.size());
    final PersistenceUnitInfo info = appInfo.persistenceUnits.get(0);
    // a space must be present before hashcode
    assertTrue(info.id.startsWith("footest-unit "));
//        appInfo = factory.configureApplication(file);
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) PersistenceUnitInfo(org.apache.openejb.assembler.classic.PersistenceUnitInfo) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 18 with PersistenceUnitInfo

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

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

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

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