db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r1823104 - in /db/jdo/trunk/api/test: java/javax/jdo/ schema/jdoconfig/Pmfmapmap01/META-INF/ schema/jdoconfig/Pmfmapmap02/
Date Sun, 04 Feb 2018 19:44:21 GMT
Author: mbo
Date: Sun Feb  4 19:44:20 2018
New Revision: 1823104

URL: http://svn.apache.org/viewvc?rev=1823104&view=rev
Log:
JDO-769: Improving and reformatting three test classes including PMFMapMapTest; using property
ConnectionFactory2Name in PMFMapMapTest

Modified:
    db/jdo/trunk/api/test/java/javax/jdo/AbstractJDOConfigTest.java
    db/jdo/trunk/api/test/java/javax/jdo/JDOHelperConfigTest.java
    db/jdo/trunk/api/test/java/javax/jdo/PMFMapMapTest.java
    db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap01/META-INF/jdoconfig.xml
    db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap02/propsfile.props

Modified: db/jdo/trunk/api/test/java/javax/jdo/AbstractJDOConfigTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/java/javax/jdo/AbstractJDOConfigTest.java?rev=1823104&r1=1823103&r2=1823104&view=diff
==============================================================================
--- db/jdo/trunk/api/test/java/javax/jdo/AbstractJDOConfigTest.java (original)
+++ db/jdo/trunk/api/test/java/javax/jdo/AbstractJDOConfigTest.java Sun Feb  4 19:44:20 2018
@@ -50,8 +50,7 @@ public abstract class AbstractJDOConfigT
      * The class path used to specify the location of test class files.
      * @return the class path where test class files can be found.
      */
-    protected static String TEST_CLASSPATH =
-            initTestClasspath();
+    protected static String TEST_CLASSPATH = initTestClasspath();
 
     /**
      * Returns the default class path for JDO test class files 
@@ -65,8 +64,7 @@ public abstract class AbstractJDOConfigT
     /**
      * The class path used to locate the JDO API class files.
      */
-    protected static String API_CLASSPATH =
-            initAPIClasspath();
+    protected static String API_CLASSPATH = initAPIClasspath();
 
     /**
      * Returns the default class path for JDO API class files
@@ -118,8 +116,7 @@ public abstract class AbstractJDOConfigT
             String expectedValue = (String) entry.getValue();
             String actualValue = (String) actual.get(key);
 
-            assertEquals(
-                    "Actual property at key [" + key + "] with value [" +
+            assertEquals("Actual property at key [" + key + "] with value [" +
                             actualValue + "] not equal to expected value [" +
                             expectedValue + "]",
                     expectedValue,

Modified: db/jdo/trunk/api/test/java/javax/jdo/JDOHelperConfigTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/java/javax/jdo/JDOHelperConfigTest.java?rev=1823104&r1=1823103&r2=1823104&view=diff
==============================================================================
--- db/jdo/trunk/api/test/java/javax/jdo/JDOHelperConfigTest.java (original)
+++ db/jdo/trunk/api/test/java/javax/jdo/JDOHelperConfigTest.java Sun Feb  4 19:44:20 2018
@@ -89,40 +89,40 @@ public class JDOHelperConfigTest extends
                 PMF_ATTRIBUTE_PERSISTENCE_UNIT_NAME + "." + testVariant);
         }
 
-    expected.put(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS,
-        PMF_ATTRIBUTE_CLASS + "." + testVariant);
-    expected.put(PROPERTY_CONNECTION_DRIVER_NAME,
-        PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME + "." + testVariant);
-    expected.put(PROPERTY_CONNECTION_FACTORY_NAME,
-        PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME + "." + testVariant);
-    expected.put(PROPERTY_CONNECTION_FACTORY2_NAME,
-        PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME + "." + testVariant);
-    expected.put(PROPERTY_CONNECTION_PASSWORD,
-        PMF_ATTRIBUTE_CONNECTION_PASSWORD + "." + testVariant);
-    expected.put(PROPERTY_CONNECTION_URL, PMF_ATTRIBUTE_CONNECTION_URL
-        + "." + testVariant);
-    expected.put(PROPERTY_CONNECTION_USER_NAME,
-        PMF_ATTRIBUTE_CONNECTION_USER_NAME + "." + testVariant);
-    expected.put(PROPERTY_IGNORE_CACHE, PMF_ATTRIBUTE_IGNORE_CACHE + "."
-        + testVariant);
-    expected.put(PROPERTY_MAPPING, PMF_ATTRIBUTE_MAPPING + "."
-        + testVariant);
-    expected.put(PROPERTY_MULTITHREADED, PMF_ATTRIBUTE_MULTITHREADED + "."
-        + testVariant);
-    expected.put(PROPERTY_NONTRANSACTIONAL_READ,
-        PMF_ATTRIBUTE_NONTRANSACTIONAL_READ + "." + testVariant);
-    expected.put(PROPERTY_NONTRANSACTIONAL_WRITE,
-        PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE + "." + testVariant);
-    expected.put(PROPERTY_OPTIMISTIC, PMF_ATTRIBUTE_OPTIMISTIC + "."
-        + testVariant);
-    expected.put(PROPERTY_RESTORE_VALUES, PMF_ATTRIBUTE_RESTORE_VALUES
-        + "." + testVariant);
-    expected.put(PROPERTY_RETAIN_VALUES, PMF_ATTRIBUTE_RETAIN_VALUES + "."
-        + testVariant);
-    expected.put(PROPERTY_DETACH_ALL_ON_COMMIT,
-        PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT + "." + testVariant);
-    expected.put(PROPERTY_SERVER_TIME_ZONE_ID,
-        PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID + "." + testVariant);
+        expected.put(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS,
+                PMF_ATTRIBUTE_CLASS + "." + testVariant);
+        expected.put(PROPERTY_CONNECTION_DRIVER_NAME,
+                PMF_ATTRIBUTE_CONNECTION_DRIVER_NAME + "." + testVariant);
+        expected.put(PROPERTY_CONNECTION_FACTORY_NAME,
+                PMF_ATTRIBUTE_CONNECTION_FACTORY_NAME + "." + testVariant);
+        expected.put(PROPERTY_CONNECTION_FACTORY2_NAME,
+                PMF_ATTRIBUTE_CONNECTION_FACTORY2_NAME + "." + testVariant);
+        expected.put(PROPERTY_CONNECTION_PASSWORD,
+                PMF_ATTRIBUTE_CONNECTION_PASSWORD + "." + testVariant);
+        expected.put(PROPERTY_CONNECTION_URL, PMF_ATTRIBUTE_CONNECTION_URL
+                + "." + testVariant);
+        expected.put(PROPERTY_CONNECTION_USER_NAME,
+                PMF_ATTRIBUTE_CONNECTION_USER_NAME + "." + testVariant);
+        expected.put(PROPERTY_IGNORE_CACHE, PMF_ATTRIBUTE_IGNORE_CACHE + "."
+                + testVariant);
+        expected.put(PROPERTY_MAPPING, PMF_ATTRIBUTE_MAPPING + "."
+                + testVariant);
+        expected.put(PROPERTY_MULTITHREADED, PMF_ATTRIBUTE_MULTITHREADED + "."
+                + testVariant);
+        expected.put(PROPERTY_NONTRANSACTIONAL_READ,
+                PMF_ATTRIBUTE_NONTRANSACTIONAL_READ + "." + testVariant);
+        expected.put(PROPERTY_NONTRANSACTIONAL_WRITE,
+                PMF_ATTRIBUTE_NONTRANSACTIONAL_WRITE + "." + testVariant);
+        expected.put(PROPERTY_OPTIMISTIC, PMF_ATTRIBUTE_OPTIMISTIC + "."
+                + testVariant);
+        expected.put(PROPERTY_RESTORE_VALUES, PMF_ATTRIBUTE_RESTORE_VALUES
+                + "." + testVariant);
+        expected.put(PROPERTY_RETAIN_VALUES, PMF_ATTRIBUTE_RETAIN_VALUES + "."
+                + testVariant);
+        expected.put(PROPERTY_DETACH_ALL_ON_COMMIT,
+                PMF_ATTRIBUTE_DETACH_ALL_ON_COMMIT + "." + testVariant);
+        expected.put(PROPERTY_SERVER_TIME_ZONE_ID,
+                PMF_ATTRIBUTE_SERVER_TIME_ZONE_ID + "." + testVariant);
 
         // listeners
         for (int i = 0; i < listenerCount; i++) {
@@ -167,8 +167,8 @@ public class JDOHelperConfigTest extends
         int listenerCount, int vendorSpecificPropertyCount,
         boolean checkEqualProperties) throws IOException {
 
-    doPositiveTest(classpaths, testVariantName, listenerCount,
-        vendorSpecificPropertyCount, checkEqualProperties, false, false);
+        doPositiveTest(classpaths, testVariantName, listenerCount,
+                vendorSpecificPropertyCount, checkEqualProperties, false, false);
     }
 
     /**
@@ -291,8 +291,8 @@ public class JDOHelperConfigTest extends
         String expected = "class.positive04.pmf0";
         String actual = getPMFClassNameViaServiceLookup(loader);
 
-    assertNotNull("No PMF name found via services lookup", actual);
-    assertEquals(expected, actual);
+        assertNotNull("No PMF name found via services lookup", actual);
+        assertEquals(expected, actual);
     }
 
     public void testPositive05_PMF0_PMFClassNameViaServicesLookup()

Modified: db/jdo/trunk/api/test/java/javax/jdo/PMFMapMapTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/java/javax/jdo/PMFMapMapTest.java?rev=1823104&r1=1823103&r2=1823104&view=diff
==============================================================================
--- db/jdo/trunk/api/test/java/javax/jdo/PMFMapMapTest.java (original)
+++ db/jdo/trunk/api/test/java/javax/jdo/PMFMapMapTest.java Sun Feb  4 19:44:20 2018
@@ -22,7 +22,6 @@ import java.io.File;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URLClassLoader;
 import java.util.Properties;
 import junit.framework.TestSuite;
 
@@ -34,19 +33,15 @@ import javax.jdo.util.BatchTestRunner;
  */
 public class PMFMapMapTest extends AbstractJDOConfigTest {
 
-    static String expectedDriverName = "Jane Doe";
-    static String expectedDriverName4NamedPMF = "Larry";
-    static String expectedDriverNameWithOverrides = "Gerard Manley Hopkins";
-    static String PMFName = "BookSearch";
-    static String resourceDir = "/Pmfmapmap01/";
-    static String propsDir = "/Pmfmapmap02/";
-    static String pmfServiceClass = "javax.jdo.stub.StubPMF";
-    static String propertiesFile = "propsfile.props";
-    PersistenceManagerFactory pmf;
-    Properties props;
-    Properties overrides;
-    URLClassLoader resourceClassLoader;
-
+    private static final String EXPECTED_FACTORY2_NAME = "Jane Doe";
+    private static final String EXPECTED_FACTORY2_NAME_4_NAMED_PMF = "Larry";
+    private static final String EXPECTED_FACTORY2_NAME_WITH_OVERRIDE = "Gerard Manley Hopkins";
+    private static final String PMF_NAME = "BookSearch";
+    private static final String RESOURCE_DIR = "/Pmfmapmap01/";
+    private static final String PROPS_DIR = "/Pmfmapmap02/";
+    private static final String PMF_SERVICE_CLASS = "javax.jdo.stub.StubPMF";
+    private static final String PROPERTIES_FILE = "propsfile.props";
+    
     public static void main(String args[]) {
         BatchTestRunner.run(PMFMapMapTest.class);
     }
@@ -60,24 +55,6 @@ public class PMFMapMapTest extends Abstr
         return new TestSuite(PMFMapMapTest.class);
     }
 
-    void setupResourceClassLoader(String dir) throws IOException {
-
-        switch (dir.charAt(dir.length() - 1)) {
-        case '\\':
-            dir = dir.substring(0, dir.length() - 1) + '/';
-            break;
-        case '/':
-            break;
-        default:
-            if (new File(dir).isDirectory()) {
-                dir += '/';
-            }
-        }
-
-        resourceClassLoader = new JDOConfigTestClassLoader(getClass()
-                .getClassLoader(), JDOCONFIG_CLASSPATH_PREFIX + dir);
-    }
-
     /*
      * static PersistenceManagerFactory getPersistenceManagerFactory() Get the
      * anonymous PersistenceManagerFactory configured via the standard
@@ -87,24 +64,18 @@ public class PMFMapMapTest extends Abstr
      */
     public void testJDOConfigXML() throws IOException {
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader saveContextClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(resourceClassLoader);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory();
+            PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory();
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         } finally {
             Thread.currentThread().setContextClassLoader(saveContextClassLoader);
         }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
-        }
     }
 
     /*
@@ -115,19 +86,14 @@ public class PMFMapMapTest extends Abstr
      */
     public void testJDOConfigXMLWithLoader() throws IOException {
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(resourceClassLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(resourceClassLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         }
     }
 
@@ -138,24 +104,19 @@ public class PMFMapMapTest extends Abstr
      */
     public void testPropsFile() throws IOException {
 
-        setupResourceClassLoader(propsDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(PROPS_DIR);
         ClassLoader saveContextClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(resourceClassLoader);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(propertiesFile);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(PROPERTIES_FILE);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         } finally {
             Thread.currentThread().setContextClassLoader(saveContextClassLoader);
         }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
-        }
     }
 
     /*
@@ -166,20 +127,14 @@ public class PMFMapMapTest extends Abstr
      */
     public void testPropsFileAndLoader() throws IOException {
 
-        setupResourceClassLoader(propsDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(PROPS_DIR);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(propertiesFile,
-                    resourceClassLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(PROPERTIES_FILE, resourceClassLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         }
     }
 
@@ -189,10 +144,9 @@ public class PMFMapMapTest extends Abstr
      * configured based on the Properties stored in the input stream at stream.
      */
     public void testInputStream() throws IOException {
-        props = new Properties();
-        props.setProperty(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS,
-                pmfServiceClass);
-        props.setProperty(PROPERTY_CONNECTION_DRIVER_NAME, expectedDriverName);
+        Properties props = new Properties();
+        props.setProperty(Constants.PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, PMF_SERVICE_CLASS);
+        props.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME, EXPECTED_FACTORY2_NAME);
 
         ByteArrayOutputStream outstream = new ByteArrayOutputStream();
         try {
@@ -200,27 +154,21 @@ public class PMFMapMapTest extends Abstr
         } catch (IOException ex) {
             fail(ex.getMessage());
         }
-        InputStream byteArrayInputStream = new ByteArrayInputStream(
-                outstream.toByteArray());
+        InputStream byteArrayInputStream = new ByteArrayInputStream(outstream.toByteArray());
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader saveContextClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(resourceClassLoader);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(byteArrayInputStream);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(byteArrayInputStream);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         } finally {
             Thread.currentThread().setContextClassLoader(saveContextClassLoader);
         }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
-        }
     }
 
     /*
@@ -230,10 +178,9 @@ public class PMFMapMapTest extends Abstr
      * the input stream at stream.
      */
     public void testInputStreamWithLoader() throws IOException {
-        props = new Properties();
-        props.setProperty(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS,
-                pmfServiceClass);
-        props.setProperty(PROPERTY_CONNECTION_DRIVER_NAME, expectedDriverName);
+        Properties props = new Properties();
+        props.setProperty(Constants.PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, PMF_SERVICE_CLASS);
+        props.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME, EXPECTED_FACTORY2_NAME);
 
         ByteArrayOutputStream outstream = new ByteArrayOutputStream();
         try {
@@ -241,23 +188,16 @@ public class PMFMapMapTest extends Abstr
         } catch (IOException ex) {
             fail(ex.getMessage());
         }
-        InputStream byteArrayInputStream = new ByteArrayInputStream(
-                outstream.toByteArray());
+        InputStream byteArrayInputStream = new ByteArrayInputStream(outstream.toByteArray());
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(byteArrayInputStream,
-                    resourceClassLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(byteArrayInputStream, resourceClassLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         }
     }
 
@@ -268,28 +208,21 @@ public class PMFMapMapTest extends Abstr
      * locate the PersistenceManagerFactory class.
      */
     public void testProperties() throws IOException {
-        props = new Properties();
-        props.setProperty(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS,
-                pmfServiceClass);
-        props.setProperty(PROPERTY_CONNECTION_DRIVER_NAME, expectedDriverName);
+        Properties props = new Properties();
+        props.setProperty(Constants.PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, PMF_SERVICE_CLASS);
+        props.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME, EXPECTED_FACTORY2_NAME);
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader saveContextClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(resourceClassLoader);
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(props);
+            PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(props);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         } finally {
             Thread.currentThread().setContextClassLoader(saveContextClassLoader);
         }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
-        }
     }
 
     /*
@@ -298,24 +231,17 @@ public class PMFMapMapTest extends Abstr
      * PersistenceManagerFactory based on a Map and a class loader.
      */
     public void testPropertiesAndLoader() throws IOException {
-        props = new Properties();
-        props.setProperty(PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS,
-                pmfServiceClass);
-        props.setProperty(PROPERTY_CONNECTION_DRIVER_NAME, expectedDriverName);
+        Properties props = new Properties();
+        props.setProperty(Constants.PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS, PMF_SERVICE_CLASS);
+        props.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME, EXPECTED_FACTORY2_NAME);
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(props,
-                    resourceClassLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(props, resourceClassLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         }
     }
 
@@ -325,29 +251,23 @@ public class PMFMapMapTest extends Abstr
      * PersistenceManagerFactory or persistence unit.
      */
     public void testNamedPMFWithOverrides() throws IOException {
-        overrides = new Properties();
-        overrides.setProperty(PROPERTY_CONNECTION_DRIVER_NAME,
-                expectedDriverNameWithOverrides);
+        Properties overrides = new Properties();
+        overrides.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME,
+                              EXPECTED_FACTORY2_NAME_WITH_OVERRIDE);
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader saveContextClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(resourceClassLoader);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(overrides, PMFName);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(overrides, PMF_NAME);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME_WITH_OVERRIDE);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         } finally {
             Thread.currentThread().setContextClassLoader(saveContextClassLoader);
         }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverNameWithOverrides.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverNameWithOverrides
-                    + "\"");
-        }
     }
 
     /*
@@ -357,25 +277,18 @@ public class PMFMapMapTest extends Abstr
      * PersistenceManagerFactory or persistence unit.
      */
     public void testNamedPMFWithOverridesAndLoader() throws IOException {
-        overrides = new Properties();
-        overrides.setProperty(PROPERTY_CONNECTION_DRIVER_NAME,
-                expectedDriverNameWithOverrides);
+        Properties overrides = new Properties();
+        overrides.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME,
+                              EXPECTED_FACTORY2_NAME_WITH_OVERRIDE);
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(overrides, PMFName,
-                    resourceClassLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(overrides, PMF_NAME, resourceClassLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME_WITH_OVERRIDE);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass."
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverNameWithOverrides.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverNameWithOverrides
-                    + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass." + ex.getMessage());
         }
     }
 
@@ -390,26 +303,19 @@ public class PMFMapMapTest extends Abstr
      * PersistenceManagerFactory.
      */
     public void testNamedPMFWithOverridesAndTwoLoaders() throws IOException {
-        overrides = new Properties();
-        overrides.setProperty(PROPERTY_CONNECTION_DRIVER_NAME,
-                expectedDriverNameWithOverrides);
+        Properties overrides = new Properties();
+        overrides.setProperty(Constants.PROPERTY_CONNECTION_FACTORY2_NAME,
+                              EXPECTED_FACTORY2_NAME_WITH_OVERRIDE);
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader pmfLoader = getClass().getClassLoader();
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(overrides, PMFName,
-                    resourceClassLoader, pmfLoader);
+            PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(
+                    overrides, PMF_NAME, resourceClassLoader, pmfLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME_WITH_OVERRIDE);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass. "
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverNameWithOverrides.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverNameWithOverrides
-                    + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass. " + ex.getMessage());
         }
     }
 
@@ -420,24 +326,18 @@ public class PMFMapMapTest extends Abstr
      */
     public void testNamedPMF() throws IOException {
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader saveContextClassLoader = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(resourceClassLoader);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(PMFName);
+            PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(PMF_NAME);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME_4_NAMED_PMF);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass. "
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass. " + ex.getMessage());
         } finally {
             Thread.currentThread().setContextClassLoader(saveContextClassLoader);
         }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName4NamedPMF.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName4NamedPMF + "\"");
-        }
     }
 
     /*
@@ -447,20 +347,14 @@ public class PMFMapMapTest extends Abstr
      */
     public void testNamedPMFWithLoader() throws IOException {
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(PMFName,
-                    resourceClassLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(PMF_NAME, resourceClassLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME_4_NAMED_PMF);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass. "
-                    + ex.getMessage());
-        }
-
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName4NamedPMF.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName4NamedPMF + "\"");
+            fail("Failed to find PersistenceManagerFactoryClass. " + ex.getMessage());
         }
     }
 
@@ -472,21 +366,39 @@ public class PMFMapMapTest extends Abstr
      */
     public void testNamedPMFWithTwoLoaders() throws IOException {
 
-        setupResourceClassLoader(resourceDir);
+        ClassLoader resourceClassLoader = createResourceClassLoader(RESOURCE_DIR);
         ClassLoader pmfLoader = getClass().getClassLoader();
 
         try {
-            pmf = JDOHelper.getPersistenceManagerFactory(PMFName,
-                    resourceClassLoader, pmfLoader);
+            PersistenceManagerFactory pmf =
+                    JDOHelper.getPersistenceManagerFactory(PMF_NAME, resourceClassLoader,
pmfLoader);
+            checkConnectionFactory2Name(pmf, EXPECTED_FACTORY2_NAME_4_NAMED_PMF);
         } catch (JDOFatalUserException ex) {
-            fail("Failed to find PersistenceManagerFactoryClass. "
-                    + ex.getMessage());
+            fail("Failed to find PersistenceManagerFactoryClass. " + ex.getMessage());
         }
+    }
 
-        String driverName = pmf.getConnectionDriverName();
-        if (!expectedDriverName4NamedPMF.equals(driverName)) {
-            fail("Bad ConnectionDriverName(): " + driverName
-                    + ".  Expected: \"" + expectedDriverName4NamedPMF + "\"");
+    private ClassLoader createResourceClassLoader(String dir) throws IOException {
+        switch (dir.charAt(dir.length() - 1)) {
+            case '\\':
+                dir = dir.substring(0, dir.length() - 1) + '/';
+                break;
+            case '/':
+                break;
+            default:
+                if (new File(dir).isDirectory()) {
+                    dir += '/';
+                }
+        }
+        return new JDOConfigTestClassLoader(getClass().getClassLoader(),
+                JDOCONFIG_CLASSPATH_PREFIX + dir);
+    }
+
+    private void checkConnectionFactory2Name(PersistenceManagerFactory pmf, String expectedName)
{
+        String factory2Name = pmf.getConnectionFactory2Name();
+        if (!expectedName.equals(factory2Name)) {
+            fail("Bad ConnectionFactory2Name(): " + factory2Name + ".  Expected: \"" + expectedName
+ "\"");
         }
     }
+
 }

Modified: db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap01/META-INF/jdoconfig.xml
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap01/META-INF/jdoconfig.xml?rev=1823104&r1=1823103&r2=1823104&view=diff
==============================================================================
--- db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap01/META-INF/jdoconfig.xml (original)
+++ db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap01/META-INF/jdoconfig.xml Sun Feb  4 19:44:20
2018
@@ -28,7 +28,7 @@
     <persistence-manager-factory
         class="javax.jdo.stub.StubPMF">
         <property
-            name="javax.jdo.option.ConnectionDriverName"
+            name="javax.jdo.option.ConnectionFactory2Name"
             value="Jane Doe"/>
     </persistence-manager-factory>
 
@@ -36,7 +36,7 @@
         name="BookSearch"
         class="javax.jdo.stub.StubPMF">
         <property
-            name="javax.jdo.option.ConnectionDriverName"
+            name="javax.jdo.option.ConnectionFactory2Name"
             value="Larry"/>
     </persistence-manager-factory>
 

Modified: db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap02/propsfile.props
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap02/propsfile.props?rev=1823104&r1=1823103&r2=1823104&view=diff
==============================================================================
--- db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap02/propsfile.props (original)
+++ db/jdo/trunk/api/test/schema/jdoconfig/Pmfmapmap02/propsfile.props Sun Feb  4 19:44:20
2018
@@ -15,4 +15,4 @@
 # limitations under the License.
 # 
 javax.jdo.PersistenceManagerFactoryClass    javax.jdo.stub.StubPMF
-javax.jdo.option.ConnectionDriverName       Jane Doe
+javax.jdo.option.ConnectionFactory2Name     Jane Doe



Mime
View raw message