mirror of https://github.com/apache/openjpa.git
Improve product derivation debugging; add test case.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@636052 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ba5d11b43b
commit
282c8e0c5b
|
@ -268,9 +268,10 @@ public class ProductDerivations {
|
|||
}
|
||||
}
|
||||
reportErrors(errs, resource, err);
|
||||
String rsrc = resource + "#" + anchor;
|
||||
throw (MissingResourceException) JavaVersions.initCause
|
||||
(new MissingResourceException(resource,
|
||||
ProductDerivations.class.getName(), resource), err);
|
||||
(new MissingResourceException(rsrc,
|
||||
ProductDerivations.class.getName(), rsrc), err);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -304,9 +305,10 @@ public class ProductDerivations {
|
|||
String aPath = (String) AccessController.doPrivileged(
|
||||
J2DoPrivHelper.getAbsolutePathAction(file));
|
||||
reportErrors(errs, aPath, err);
|
||||
String rsrc = aPath + "#" + anchor;
|
||||
throw (MissingResourceException) JavaVersions.initCause
|
||||
(new MissingResourceException(aPath,
|
||||
ProductDerivations.class.getName(), aPath), err);
|
||||
(new MissingResourceException(rsrc,
|
||||
ProductDerivations.class.getName(), rsrc), err);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
package org.apache.openjpa.lib.conf;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.MissingResourceException;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.openjpa.lib.util.Options;
|
||||
|
@ -60,4 +66,90 @@ public class TestAnchorParsing extends TestCase {
|
|||
"META-INF/persistence.xml#third-persistence-unit"));
|
||||
assertTrue(locs.contains("META-INF/persistence.xml#invalid"));
|
||||
}
|
||||
|
||||
public void testProductDerivationsLoadResource() {
|
||||
ProductDerivations.load(
|
||||
"org/apache/openjpa/lib/conf/product-derivations-load.xml",
|
||||
"foo", null);
|
||||
|
||||
ProductDerivations.load(
|
||||
"org/apache/openjpa/lib/conf/product-derivations-load.xml",
|
||||
null, null);
|
||||
|
||||
try {
|
||||
ProductDerivations.load(
|
||||
"org/apache/openjpa/lib/conf/product-derivations-load.xml",
|
||||
"nonexistant", null);
|
||||
fail("pu 'nonexistant' does not exist");
|
||||
} catch (MissingResourceException mre) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
ProductDerivations.load(
|
||||
"org/apache/openjpa/lib/conf/product-derivations-load.xml",
|
||||
"", null);
|
||||
fail("pu '' does not exist");
|
||||
} catch (MissingResourceException mre) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testNonexistantResourceLoad() {
|
||||
try {
|
||||
ProductDerivations.load("nonexistant-resource", null, null);
|
||||
fail("resource 'nonexistant-resource' should not exist");
|
||||
} catch (MissingResourceException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testProductDerivationsLoadFile() throws IOException {
|
||||
File validFile = resourceToTemporaryFile(
|
||||
"org/apache/openjpa/lib/conf/product-derivations-load.xml");
|
||||
|
||||
ProductDerivations.load(validFile, "foo", null);
|
||||
|
||||
ProductDerivations.load(validFile, null, null);
|
||||
|
||||
try {
|
||||
ProductDerivations.load(validFile, "nonexistant", null);
|
||||
fail("pu 'nonexistant' does not exist");
|
||||
} catch (MissingResourceException mre) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
ProductDerivations.load(validFile, "", null);
|
||||
fail("pu '' does not exist");
|
||||
} catch (MissingResourceException mre) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testNonexistantFileLoad() {
|
||||
File f = new File("this-should-not-exist");
|
||||
assertFalse(f.exists());
|
||||
try {
|
||||
ProductDerivations.load(f, null, null);
|
||||
fail(f.getName() + " does not exist");
|
||||
} catch (MissingResourceException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private File resourceToTemporaryFile(String s) throws IOException {
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream(s);
|
||||
File f = File.createTempFile("TestAnchorParsing", ".xml");
|
||||
OutputStream out = new FileOutputStream(f);
|
||||
byte[] bytes = new byte[1024];
|
||||
while (true) {
|
||||
int count = in.read(bytes);
|
||||
if (count < 0)
|
||||
break;
|
||||
out.write(bytes, 0, count);
|
||||
}
|
||||
f.deleteOnExit();
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0">
|
||||
|
||||
<persistence-unit name="foo"/>
|
||||
</persistence>
|
Loading…
Reference in New Issue