use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testNonJtaRefToContrarilyConfiguredDataSource.
/**
* Existing data source "OrangeOne", jta managed
* Existing data source "OrangeTwo", jta managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit">
* <jta-data-source>OrangeOne</jta-data-source>
* <non-jta-data-source>OrangeTwo</non-jta-data-source>
* </persistence-unit>
* <p/>
* This configuration should be rejected
*
* @throws Exception
*/
public void testNonJtaRefToContrarilyConfiguredDataSource() throws Exception {
final ResourceInfo jta1 = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", true);
final ResourceInfo jta2 = addDataSource("OrangeTwo", OrangeDriver.class, "jdbc:orange:some:stuff", true);
assertSame(jta1, resources.get(0));
assertSame(jta2, resources.get(1));
try {
addPersistenceUnit("orange-unit", "orangeOne", "orangeTwo");
fail("Configuration should be rejected");
} catch (final OpenEJBException e) {
// pass
}
}
use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testMultiple.
/**
* Existing data source "Orange", jta managed
* Existing data source "OrangeUnmanaged", not jta managed
* Existing data source "Lime", jta managed
* Existing data source "LimeUnmanaged", 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>OrangeUnmanaged</non-jta-data-source>
* </persistence-unit>
* <persistence-unit name="lime-unit">
* <jta-data-source>Lime</jta-data-source>
* <non-jta-data-source>LimeUnmanaged</non-jta-data-source>
* </persistence-unit>
* <p/>
* This is the happy path.
*
* @throws Exception
*/
public void testMultiple() throws Exception {
final ResourceInfo orangeJta = addDataSource("Orange", OrangeDriver.class, "jdbc:orange:some:stuff", true);
final ResourceInfo orangeNonJta = addDataSource("OrangeUnmanaged", OrangeDriver.class, "jdbc:orange:some:stuff", false);
final ResourceInfo limeJta = addDataSource("Lime", LimeDriver.class, "jdbc:lime:some:stuff", true);
final ResourceInfo limeNonJta = addDataSource("LimeUnmanaged", LimeDriver.class, "jdbc:lime:some:stuff", false);
assertSame(orangeJta, resources.get(0));
assertSame(orangeNonJta, resources.get(1));
assertSame(limeJta, resources.get(2));
assertSame(limeNonJta, resources.get(3));
final PersistenceUnit unit1 = new PersistenceUnit("orange-unit");
unit1.setJtaDataSource("Orange");
unit1.setNonJtaDataSource("OrangeUnmanaged");
final PersistenceUnit unit2 = new PersistenceUnit("lime-unit");
unit2.setJtaDataSource("Lime");
unit2.setNonJtaDataSource("LimeUnmanaged");
final AppModule app = new AppModule(this.getClass().getClassLoader(), "test-app");
app.addPersistenceModule(new PersistenceModule("root", new Persistence(unit1, unit2)));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
// Check results
final PersistenceUnitInfo orangeUnit = appInfo.persistenceUnits.get(0);
final PersistenceUnitInfo limeUnit = appInfo.persistenceUnits.get(1);
assertNotNull(orangeUnit);
assertEquals(orangeJta.id, orangeUnit.jtaDataSource);
assertEquals(orangeNonJta.id, orangeUnit.nonJtaDataSource);
assertNotNull(limeUnit);
assertEquals(limeJta.id, limeUnit.jtaDataSource);
assertEquals(limeNonJta.id, limeUnit.nonJtaDataSource);
}
use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testInvalidOptionsNonJta.
/**
* Existing data source "Orange", jta managed
* Existing data source "Lime", non 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>. We should not select the
* Lime datasource which is for a different database.
*
* @throws Exception
*/
public void testInvalidOptionsNonJta() 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);
assertSame(supplied, resources.get(0));
assertSame(badMatch, resources.get(1));
final PersistenceUnitInfo unitInfo = addPersistenceUnit("orange-unit", "orange", null);
assertNotNull(unitInfo);
final ResourceInfo generated = resources.get(2);
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.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromWebAppIdNonJta.
/**
* Existing data source "orange-id", non-jta managed
* <p/>
* Application contains a web module with id "orange-id"
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit" />
* <p/>
* The orange-unit app should automatically use orange-id data source and create a new non-JtaManaged datasource
*
* @throws Exception
*/
public void testFromWebAppIdNonJta() throws Exception {
final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", false);
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-id"));
// Create app
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
// 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"));
}
use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testFromUnitNameJta.
/**
* 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 testFromUnitNameJta() throws Exception {
final ResourceInfo supplied = addDataSource("orange-unit", 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"));
}
Aggregations