openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r636052 - in /openjpa/trunk: openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/lib/conf/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/ openjpa-persistence-...
Date Tue, 11 Mar 2008 18:29:32 GMT
Author: pcl
Date: Tue Mar 11 11:29:19 2008
New Revision: 636052

URL: http://svn.apache.org/viewvc?rev=636052&view=rev
Log:
Improve product derivation debugging; add test case.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/conf/
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/conf/product-derivations-load.xml
Modified:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/lib/conf/TestAnchorParsing.java

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java?rev=636052&r1=636051&r2=636052&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/ProductDerivations.java
Tue Mar 11 11:29:19 2008
@@ -268,9 +268,10 @@
             }
         }
         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 @@
         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);
     }
    
     /**

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/lib/conf/TestAnchorParsing.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/lib/conf/TestAnchorParsing.java?rev=636052&r1=636051&r2=636052&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/lib/conf/TestAnchorParsing.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/lib/conf/TestAnchorParsing.java
Tue Mar 11 11:29:19 2008
@@ -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;
@@ -59,5 +65,91 @@
         assertTrue(locs.contains(
             "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;
     }
 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/conf/product-derivations-load.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/conf/product-derivations-load.xml?rev=636052&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/conf/product-derivations-load.xml
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/lib/conf/product-derivations-load.xml
Tue Mar 11 11:29:19 2008
@@ -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>
\ No newline at end of file



Mime
View raw message