Return-Path: Delivered-To: apmail-incubator-open-jpa-commits-archive@locus.apache.org Received: (qmail 26843 invoked from network); 1 Aug 2006 01:59:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Aug 2006 01:59:44 -0000 Received: (qmail 83236 invoked by uid 500); 1 Aug 2006 01:59:44 -0000 Delivered-To: apmail-incubator-open-jpa-commits-archive@incubator.apache.org Received: (qmail 83150 invoked by uid 500); 1 Aug 2006 01:59:43 -0000 Mailing-List: contact open-jpa-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: open-jpa-dev@incubator.apache.org Delivered-To: mailing list open-jpa-commits@incubator.apache.org Delivered-To: moderator for open-jpa-commits@incubator.apache.org Received: (qmail 72392 invoked by uid 99); 28 Jul 2006 19:59:07 -0000 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: open-jpa-commits@incubator.apache.org From: awhite@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060728195846.442061A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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("\n"); + docType.append("\t\n"); docType.append("\t\n"); docType.append("\t\n"); docType.append("\t\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 @@ - 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 = *