use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testEmptyUnitOneAvailableNonJtaDataSource.
// ---
/**
* Existing data source "Orange", not jta managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit">
* </persistence-unit>
* <p/>
* The <non-jta-data-source> should be auto linked
* to the Orange data source
* <p/>
* We should generate a <jta-data-source> based on
* the <non-jta-data-source>
*
* @throws Exception
*/
public void testEmptyUnitOneAvailableNonJtaDataSource() 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", null, null);
assertNotNull(unitInfo);
final ResourceInfo generated = resources.get(1);
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"));
}
use of org.apache.openejb.assembler.classic.ResourceInfo in project tomee by apache.
the class AutoConfigPersistenceUnitsTest method testJtaRefToContrarilyConfiguredDataSource2.
/**
* Existing data source "OrangeOne", not jta managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit">
* <jta-data-source>OrangeOne</jta-data-source>
* </persistence-unit>
* <p/>
* This configuration should be rejected
*
* @throws Exception
*/
public void testJtaRefToContrarilyConfiguredDataSource2() throws Exception {
final ResourceInfo jta = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", false);
assertSame(jta, resources.get(0));
try {
addPersistenceUnit("orange-unit", "orangeOne", null);
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 testNonJtaRefToContrarilyConfiguredDataSource2.
/**
* Existing data source "OrangeOne", jta managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit">
* <non-jta-data-source>OrangeOne</non-jta-data-source>
* </persistence-unit>
* <p/>
* This configuration should be rejected
*
* @throws Exception
*/
public void testNonJtaRefToContrarilyConfiguredDataSource2() throws Exception {
final ResourceInfo jta = addDataSource("OrangeOne", OrangeDriver.class, "jdbc:orange:some:stuff", true);
assertSame(jta, resources.get(0));
try {
addPersistenceUnit("orange-unit", null, "orangeOne");
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 testFromAppIdNonJta.
/**
* Existing data source "orange-unit-app", non-jta-managed
* <p/>
* Persistence xml like so:
* <p/>
* <persistence-unit name="orange-unit" />
* <p/>
* The app module id is orange-unit-app. Use orange-unit-app data source and create a new JtaManaged datasource
*
* @throws Exception
*/
public void testFromAppIdNonJta() throws Exception {
final ResourceInfo supplied = addDataSource("orange-unit-app", OrangeDriver.class, "jdbc:orange:some:stuff", false);
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 + "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 testFromWebAppIdJta.
/**
* Existing data source "orange-web", 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 testFromWebAppIdJta() throws Exception {
final ResourceInfo supplied = addDataSource("orange-id", OrangeDriver.class, "jdbc:orange-web:some:stuff", true);
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 + "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