use of org.apache.openejb.OpenEJBException 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.OpenEJBException 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.OpenEJBException in project tomee by apache.
the class NoServiceJarTest method testInvalid.
public void testInvalid() throws Exception {
final ConfigurationFactory factory = new ConfigurationFactory();
final Resource orange = new Resource("Orange");
orange.getProperties().setProperty("red", "255");
orange.getProperties().setProperty("green", "200");
orange.getProperties().setProperty("blue", "0");
try {
factory.configureService(orange, ResourceInfo.class);
fail("OpenEJBException should have been thrown");
} catch (final OpenEJBException e) {
// pass
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class NoServiceJarTest method testInvalidJustType.
public void testInvalidJustType() throws Exception {
final ConfigurationFactory factory = new ConfigurationFactory();
final Resource orange = new Resource("Orange");
orange.setType(Color.class.getName());
orange.getProperties().setProperty("red", "255");
orange.getProperties().setProperty("green", "200");
orange.getProperties().setProperty("blue", "0");
try {
factory.configureService(orange, ResourceInfo.class);
fail("OpenEJBException should have been thrown");
} catch (final OpenEJBException e) {
// pass
}
}
use of org.apache.openejb.OpenEJBException in project tomee by apache.
the class AbstractTomEEMojo method ensureAppsFolderExistAndIsConfiguredByDefault.
private void ensureAppsFolderExistAndIsConfiguredByDefault(final File file) throws IOException {
if ("openejb".equals(container.toLowerCase(Locale.ENGLISH)) || (file.exists() && ((apps != null && !apps.isEmpty()) || (!"pom".equals(packaging) && !"war".equals(packaging))))) {
// webapps doesn't need apps folder in tomee
final String rootTag = container.toLowerCase(Locale.ENGLISH);
if (file.isFile()) {
// can be not existing since we dont always deploy tomee but shouldn't since then apps/ is not guaranteed to work
try {
final Openejb jaxb = JaxbOpenejb.readConfig(file.getAbsolutePath());
boolean needAdd = true;
for (final Deployments d : jaxb.getDeployments()) {
if ("apps".equals(d.getDir())) {
needAdd = false;
break;
}
}
if (needAdd) {
final String content = IO.slurp(file);
final FileWriter writer = new FileWriter(file);
final String end = "</" + rootTag + ">";
writer.write(content.replace(end, " <Deployments dir=\"apps\" />\n" + end));
writer.close();
}
} catch (final OpenEJBException e) {
throw new IllegalStateException("illegal tomee.xml:\n" + IO.slurp(file), e);
}
} else {
final FileWriter writer = new FileWriter(file);
writer.write("<?xml version=\"1.0\"?>\n" + "<" + rootTag + ">\n" + " <Deployments dir=\"apps\" />\n" + "</" + rootTag + ">\n");
writer.close();
}
final File appsFolder = new File(catalinaBase, "apps");
if (!appsFolder.exists() && !appsFolder.mkdirs()) {
throw new RuntimeException("Failed to create: " + appsFolder);
}
}
}
Aggregations