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 "));
}
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);
}
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);
}
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);
}
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"));
}
Aggregations