openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r426658 - in /incubator/openjpa/trunk/openjpa-lib/src/test: java/org/apache/openjpa/lib/conf/test/ java/org/apache/openjpa/lib/xml/ resources/ resources/META-INF/ resources/META-INF/services/ resources/org/apache/openjpa/lib/xml/
Date Fri, 28 Jul 2006 19:58:45 GMT
Author: awhite
Date: Fri Jul 28 12:58:44 2006
New Revision: 426658

URL: http://svn.apache.org/viewvc?rev=426658&view=rev
Log:
Got all tests passing.


Added:
    incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestConfigurationProvider.java
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/test.properties   (with props)
Modified:
    incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java
    incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/xml/TestDocTypeReader.java
    incubator/openjpa/trunk/openjpa-lib/src/test/resources/org/apache/openjpa/lib/xml/formatted-result.xml

Added: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestConfigurationProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestConfigurationProvider.java?rev=426658&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestConfigurationProvider.java
(added)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/ConfigurationTestConfigurationProvider.java
Fri Jul 28 12:58:44 2006
@@ -0,0 +1,88 @@
+package org.apache.openjpa.lib.conf.test;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.MissingResourceException;
+import java.util.Properties;
+
+import org.apache.openjpa.lib.conf.MapConfigurationProvider;
+
+/**
+ * Configuration provider used in testing.
+ *
+ * @author Abe White
+ */
+public class ConfigurationTestConfigurationProvider
+    extends MapConfigurationProvider {
+
+    public ConfigurationTestConfigurationProvider() {
+        super(null);
+    }
+
+    public boolean loadDefaults(ClassLoader loader)
+        throws IOException {
+        return load(null, loader);
+    }
+
+    public boolean load(String rsrc, ClassLoader loader)
+        throws IOException {
+        if (rsrc == null)
+            rsrc = System.getProperty("openjpatest.properties");
+        if (rsrc == null || !rsrc.endsWith(".properties"))
+            return false;
+
+        URL url = findResource(rsrc, loader);
+        if (url == null)
+            throw new MissingResourceException(rsrc, getClass().getName(), 
+                rsrc);
+
+        InputStream in = url.openStream();
+        Properties props = new Properties();
+        if (in != null) {
+            try {
+                props.load(in);
+                addProperties(props);
+                return true;
+            } finally {
+                try {
+                    in.close();
+                } catch (Exception e) {
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Locate the given resource.
+     */
+    private URL findResource(String rsrc, ClassLoader loader)
+        throws IOException {
+        if (loader != null)
+            return loader.getResource(rsrc);
+
+        // in jbuilder the classloader can be null
+        URL url = null;
+        loader = getClass().getClassLoader();
+        if (loader != null)
+            url = loader.getResource(rsrc);
+        if (url == null) {
+            loader = Thread.currentThread().getContextClassLoader();
+            if (loader != null)
+                url = loader.getResource(rsrc);
+        }
+        if (url == null) {
+            loader = ClassLoader.getSystemClassLoader();
+            if (loader != null)
+                url = loader.getResource(rsrc);
+        }
+        return url;
+    }
+
+    public boolean load(File file)
+        throws IOException {
+        return false;
+    }
+}

Modified: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java?rev=426658&r1=426657&r2=426658&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/test/TestConfigurationImpl.java
Fri Jul 28 12:58:44 2006
@@ -43,24 +43,19 @@
     }
 
     public void setUp() {
-        _def = System.getProperty("openjpa.properties");
-        System.setProperty("openjpa.properties", "test.properties");
+        System.setProperty("openjpatest.properties", "test.properties");
     }
 
     public void tearDown() throws Exception {
-    	if (_def != null)
-    		System.setProperty("openjpa.properties", _def);
-
+        System.setProperty("openjpatest.properties", "");
     	super.tearDown();
     }
 
     /**
      * Test that default properties are found and loaded.
-     * ### This test method requires some sort of ConfigurationProvider
-     * ### to be available in the openjpa-lib module, which is not the case.
      */
     public void testDefaults() {
-        System.setProperty("sysKey", "sysvalue");
+        System.setProperty("openjpa.sysKey", "sysvalue");
         assertNull(_conf.getTestKey());
         assertNull(_conf.getSysKey());
         assertNull(_conf.getPluginKey());
@@ -74,7 +69,7 @@
         // override the properties location to a non-existant value
         _conf.setTestKey(null);
         _conf.setSysKey(null);
-        System.setProperty("openjpa.properties", "foo.properties");
+        System.setProperty("openjpatest.properties", "foo.properties");
         try {
             assertTrue(!_conf.loadDefaults());
             fail("Should have thrown exception for missing resource.");
@@ -82,8 +77,8 @@
         }
 
         // set back for remainder of tests
-        System.setProperty("openjpa.properties", "test.properties");
-        System.setProperty("pluginKey", "java.lang.Object");
+        System.setProperty("openjpatest.properties", "test.properties");
+        System.setProperty("openjpa.pluginKey", "java.lang.Object");
         assertTrue(_conf.loadDefaults());
         assertEquals("testvalue", _conf.getTestKey());
         assertEquals("sysvalue", _conf.getSysKey());
@@ -99,15 +94,15 @@
         assertTrue(_conf.loadDefaults());
         assertEquals("testvalue", _conf.getTestKey());
         Map props = _conf.toProperties(false);
-        assertEquals("testvalue", props.get("testKey"));
-        assertFalse(props.containsKey("objectKey"));
+        assertEquals("testvalue", props.get("openjpa.testKey"));
+        assertFalse(props.containsKey("openjpa.objectKey"));
         _conf.setTestKey("foo");
         _conf.setPluginKey(new Object());
         _conf.setObjectKey(new Object());
         props = _conf.toProperties(false);
-        assertEquals("foo", props.get("testKey"));
-        assertEquals("java.lang.Object", props.get("pluginKey"));
-        assertFalse(props.containsKey("objectKey"));
+        assertEquals("foo", props.get("openjpa.testKey"));
+        assertEquals("java.lang.Object", props.get("openjpa.pluginKey"));
+        assertFalse(props.containsKey("openjpa.objectKey"));
     }
 
     /**
@@ -261,10 +256,6 @@
             _sysKey = addString("sysKey");
             _pluginKey = addPlugin("pluginKey", canSetPlugin);
             _objectKey = addObject("objectKey");
-        }
-
-        public String getProductName() {
-            return "test";
         }
 
         public String getTestKey() {

Modified: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/xml/TestDocTypeReader.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/xml/TestDocTypeReader.java?rev=426658&r1=426657&r2=426658&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/xml/TestDocTypeReader.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/xml/TestDocTypeReader.java
Fri Jul 28 12:58:44 2006
@@ -51,7 +51,7 @@
     public void setUp() {
         StringBuffer docType = new StringBuffer();
         docType.append("<!DOCTYPE foo [\n");
-        docType.append("\t<!ELEMENT foo(bar)>\n");
+        docType.append("\t<!ELEMENT foo (bar)>\n");
         docType.append("\t<!ELEMENT bar EMPTY>\n");
         docType.append("\t<!ATTLIST bar attr CDATA \"value\">\n");
         docType.append("\t<!ATTLIST bar attr2 CDATA \"value2\">\n");

Added: incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider?rev=426658&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider
(added)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/resources/META-INF/services/org.apache.openjpa.lib.conf.ConfigurationProvider
Fri Jul 28 12:58:44 2006
@@ -0,0 +1 @@
+org.apache.openjpa.lib.conf.test.ConfigurationTestConfigurationProvider

Modified: incubator/openjpa/trunk/openjpa-lib/src/test/resources/org/apache/openjpa/lib/xml/formatted-result.xml
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/resources/org/apache/openjpa/lib/xml/formatted-result.xml?rev=426658&r1=426657&r2=426658&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/resources/org/apache/openjpa/lib/xml/formatted-result.xml
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/resources/org/apache/openjpa/lib/xml/formatted-result.xml
Fri Jul 28 12:58:44 2006
@@ -1,5 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
 <root attr1="1" attr2="2">
     <list/>
     <list>

Added: incubator/openjpa/trunk/openjpa-lib/src/test/resources/test.properties
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/resources/test.properties?rev=426658&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/resources/test.properties (added)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/resources/test.properties Fri Jul 28 12:58:44
2006
@@ -0,0 +1 @@
+openjpa.testKey=testvalue

Propchange: incubator/openjpa/trunk/openjpa-lib/src/test/resources/test.properties
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message