use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testInvalidRefs.
/**
* 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>DoesNotExist</jta-data-source>
* <non-jta-data-source>AlsoDoesNotExist</non-jta-data-source>
* </persistence-unit>
* <p/>
* We should automatically hook them up to the configured
* datasources that do match
*
* @throws Exception
*/
public void testInvalidRefs() 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", "DoesNotExist", "AlsoDoesNotExist");
assertNotNull(unitInfo);
assertEquals(jta.id, unitInfo.jtaDataSource);
assertEquals(nonJta.id, unitInfo.nonJtaDataSource);
}
use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testMissingNonJtaDataSource.
/**
* Existing data source "Orange" 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 generate a <non-jta-data-source> based on
* the <jta-data-source>
*
* @throws Exception
*/
public void testMissingNonJtaDataSource() throws Exception {
final ResourceInfo supplied = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
assertSame(supplied, resources.get(0));
final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", null);
assertNotNull(unitInfo);
final ResourceInfo generated = resources.get(1);
assertEquals(supplied.id, unitInfo.jtaDataSource);
assertEquals(generated.id, unitInfo.nonJtaDataSource);
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"));
}
use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testSameDataSourceForBoth4.
/**
* Existing data source "OrangeOne", jta managed
* Existing data source "OrangeTwo", not jta managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit">
* <jta-data-source>OrangeTwo</jta-data-source>
* <non-jta-data-source>OrangeTwo</non-jta-data-source>
* </persistence-unit>
* <p/>
* They used the same data source for both the
* jta-data-source and non-jta-data-source and we
* can determine the data source will not work as
* a jta-data-source
* BUT
* they have explicitly configured a data source
* that nearly matches the named datasource and
* would be identical to what we would auto-create
*
* @throws Exception
*/
public void testSameDataSourceForBoth4() throws Exception {
final ResourceInfo jta = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", true);
final ResourceInfo nonJta = addDataSource("OrangeTwo", OrangeDriver.class, "jdbc:orange:some:stuff", false);
assertSame(jta, resources.get(0));
assertSame(nonJta, resources.get(1));
final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orangeTwo", "orangeTwo");
assertNotNull(unitInfo);
assertEquals(jta.id, unitInfo.jtaDataSource);
assertEquals(nonJta.id, unitInfo.nonJtaDataSource);
}
use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testSameDataSourceForBoth2.
/**
* Existing data source "Orange", 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>Orange</non-jta-data-source>
* </persistence-unit>
* <p/>
* They used the same data source for both the
* jta-data-source and non-jta-data-source and we
* can determine the data source will not work as
* a jta-data-source
* <p/>
* We should generate the missing data source for them
* based on the one they supplied.
*
* @throws Exception
*/
public void testSameDataSourceForBoth2() 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", "orange", "orange");
assertNotNull(unitInfo);
final ResourceInfo generated = resources.get(1);
assertEquals(generated.id, unitInfo.jtaDataSource);
assertEquals(supplied.id, unitInfo.nonJtaDataSource);
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"));
}
use of org.apache.openejb.assembler.classic.PersistenceUnitInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppContextThirdParty.
/**
* Existing data source "orange-web", not controlled by us
* <p/>
* Application contains a web module with root context path as "orange-web"
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit" />
* <p/>
* The orange-unit app should automatically use orange-web data source and the non-jta-datasource should be null
*
* @throws Exception
*/
public void testFromWebAppContextThirdParty() throws Exception {
final ResourceInfo supplied = addDataSource("orange-web", OrangeDriver.class, "jdbc:orange-web:some:stuff", null);
assertSame(supplied, resources.get(0));
final PersistenceUnit persistenceUnit = new PersistenceUnit("orange-unit");
final ClassLoader cl = this.getClass().getClassLoader();
final AppModule app = new AppModule(cl, "orange-app");
app.addPersistenceModule(new PersistenceModule("root", new Persistence(persistenceUnit)));
final WebApp webApp = new WebApp();
webApp.setMetadataComplete(true);
app.getWebModules().add(new WebModule(webApp, "orange-web", cl, "war", "orange-web"));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
final PersistenceUnitInfo unitInfo = appInfo.persistenceUnits.get(0);
//Check results
assertEquals(supplied.id, unitInfo.jtaDataSource);
assertNull(unitInfo.nonJtaDataSource);
}
Aggregations