db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r220238 - in /incubator/jdo/trunk/api20: src/java/javax/jdo/JDOHelper.java test/java/javax/jdo/JDOHelperTest.java
Date Fri, 22 Jul 2005 04:50:43 GMT
Author: clr
Date: Thu Jul 21 21:50:42 2005
New Revision: 220238

URL: http://svn.apache.org/viewcvs?rev=220238&view=rev
Log:
Improve handling of getPersistenceManagerFactory; add test cases for error conditions

Modified:
    incubator/jdo/trunk/api20/src/java/javax/jdo/JDOHelper.java
    incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/JDOHelper.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/JDOHelper.java?rev=220238&r1=220237&r2=220238&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/JDOHelper.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/JDOHelper.java Thu Jul 21 21:50:42 2005
@@ -279,7 +279,10 @@
      * <BR>"javax.jdo.option.ConnectionPassword",
      * <BR>"javax.jdo.option.ConnectionURL",
      * <BR>"javax.jdo.option.ConnectionFactoryName",
-     * <BR>"javax.jdo.option.ConnectionFactory2Name".
+     * <BR>"javax.jdo.option.ConnectionFactory2Name",
+     * <BR>"javax.jdo.option.Mapping",
+     * <BR>"javax.jdo.mapping.Catalog",
+     * <BR>"javax.jdo.mapping.Schema".
      * </code><P>JDO implementations
      * are permitted to define key values of their own.  Any key values not
      * recognized by the implementation must be ignored.  Key values that are
@@ -302,45 +305,10 @@
         if (pmfClassName == null) {
             throw new JDOFatalUserException (msg.msg("EXC_GetPMFNoClassNameProperty")); //
NOI18N
         }
-        Method propsMethod = null;
-        Exception propsGetMethodException = null;
-        Method mapMethod = null;
-        Exception mapGetMethodException = null;
-        Method pmfMethod = null;
         try {
             Class pmfClass = cl.loadClass (pmfClassName);
-            try {
-                propsMethod = pmfClass.getMethod("getPersistenceManagerFactory",  //NOI18N
-                    new Class[] {Properties.class});
-            } catch (NoSuchMethodException nsme) {
-                propsGetMethodException = new JDOFatalInternalException 
-                        (msg.msg("EXC_GetPMFNoSuchMethod"), nsme); //NOI18Nnsme;
-            }
-            try {
-                mapMethod = pmfClass.getMethod("getPersistenceManagerFactory",  //NOI18N
+            Method pmfMethod = pmfClass.getMethod("getPersistenceManagerFactory",  //NOI18N
                     new Class[] {Map.class});
-            } catch (NoSuchMethodException nsme) {
-                mapGetMethodException = new JDOFatalInternalException 
-                        (msg.msg("EXC_GetPMFNoSuchMethod"), nsme); //NOI18Nnsme;
-            }
-            /* If the parameter is not a Properties, 
-             * we need a mapMethod or else throw an exception.
-             */
-            if (!(props instanceof Properties)) {
-                if (mapMethod != null) {
-                    pmfMethod = mapMethod;
-                } else {
-                    throw mapGetMethodException;
-                }
-            } else { // the parameter is a Properties; use either method.
-                if (mapMethod != null) {
-                    pmfMethod = mapMethod;
-                } else if (propsMethod != null) {
-                    pmfMethod = propsMethod;
-                } else {
-                    throw mapGetMethodException;
-                }
-            }
             return (PersistenceManagerFactory) pmfMethod.invoke (null, new Object[] {props});
         } catch (ClassNotFoundException cnfe) {
             throw new JDOFatalUserException (msg.msg("EXC_GetPMFClassNotFound", pmfClassName),
cnfe); //NOI18N

Modified: incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java?rev=220238&r1=220237&r2=220238&view=diff
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java (original)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/JDOHelperTest.java Thu Jul 21 21:50:42 2005
@@ -19,6 +19,7 @@
 import java.io.File;
 import java.io.InputStream;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
@@ -387,20 +388,51 @@
         }
     }
 
-    /** Test bad PMF class no method getPersistenceManagerFactory.
+    /** Test bad PMF class no method getPersistenceManagerFactory(Properties).
      */
-    public void testBadPMFNoGetPMFMethod() {
+    public void testBadPMFNoGetPMFPropertiesMethod() {
         PersistenceManagerFactory pmf = null;
         Properties props = new Properties();
         props.put("javax.jdo.PersistenceManagerFactoryClass", 
                 "javax.jdo.JDOHelperTest$BadPMFNoGetPMFMethod");
         try {
             pmf = JDOHelper.getPersistenceManagerFactory(props);
-            fail("Bad PersistenceManagerFactoryClass should result in JDOFatalUserException
");
+            fail("Bad PersistenceManagerFactory should result in JDOFatalInternalException
");
         }
         catch (JDOFatalInternalException ex) {
-            if (verbose)
-                println("Caught expected exception " + ex);
+            if (ex.getCause() instanceof NoSuchMethodException) {
+                if (verbose)
+                    println("Caught expected exception " + ex);
+            } else {
+                fail("Bad PersistenceManagerFactory should result in " +
+                        "JDOFatalInternalException with nested " +
+                        "NoSuchMethodException. " +
+                        "Actual nested exception was " + ex);
+            }
+        }
+    }
+
+    /** Test bad PMF class no method getPersistenceManagerFactory(Map).
+     */
+    public void testBadPMFNoGetPMFMapMethod() {
+        PersistenceManagerFactory pmf = null;
+        Map props = new HashMap();
+        props.put("javax.jdo.PersistenceManagerFactoryClass", 
+                "javax.jdo.JDOHelperTest$BadPMFNoGetPMFMethod");
+        try {
+            pmf = JDOHelper.getPersistenceManagerFactory(props);
+            fail("Bad PersistenceManagerFactory should result in JDOFatalInternalException
");
+        }
+        catch (JDOFatalInternalException ex) {
+            if (ex.getCause() instanceof NoSuchMethodException) {
+                if (verbose)
+                    println("Caught expected exception " + ex);
+            } else {
+                fail("Bad PersistenceManagerFactory should result in " +
+                        "JDOFatalInternalException with nested " +
+                        "NoSuchMethodException. " +
+                        "Actual nested exception was " + ex);
+            }
         }
     }
 
@@ -438,6 +470,25 @@
         }
     }
 
+    /** Test bad PMF class getPersistenceManagerFactory throws Exception.
+     */
+    public void testBadPMFGetPMFMethodThrowsJDOException() {
+        PersistenceManagerFactory pmf = null;
+        Properties props = new Properties();
+        props.put("javax.jdo.PersistenceManagerFactoryClass", 
+                "javax.jdo.JDOHelperTest$BadPMFGetPMFMethodThrowsJDOException");
+        try {
+            pmf = JDOHelper.getPersistenceManagerFactory(props);
+            fail("BadPMFGetPMFMethodThrowsJDOException.GetPersistenceManagerFactory " +
+                    "should result in JDOUnsupportedOptionException. " +
+                    "No exception was thrown.");
+        }
+        catch (JDOUnsupportedOptionException ex) {
+            if (verbose)
+                println("Caught expected exception " + ex);
+        }
+    }
+
     private Context getInitialContext() {
         try {
             return new InitialContext();
@@ -461,6 +512,14 @@
         public static BadPMFWrongReturnType 
                 getPersistenceManagerFactory(Map props) {
             return new BadPMFWrongReturnType();
+        }
+    }
+    
+    private static class BadPMFGetPMFMethodThrowsJDOException {
+        public static PersistenceManagerFactory
+                getPersistenceManagerFactory(Map props) {
+            throw new JDOUnsupportedOptionException(
+                    "GetPMF method throws JDOUnsupportedOptionException");
         }
     }
 }



Mime
View raw message