db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject svn commit: r1210131 - in /db/jdo/trunk: api/src/java/javax/jdo/ api/src/java/javax/jdo/spi/ api/test/java/javax/jdo/ api/test/java/javax/jdo/spi/ tck/src/conf/ tck/src/java/org/apache/jdo/tck/ tck/src/java/org/apache/jdo/tck/api/persistencemanagerfact...
Date Sun, 04 Dec 2011 16:05:46 GMT
Author: madams
Date: Sun Dec  4 16:05:45 2011
New Revision: 1210131

URL: http://svn.apache.org/viewvc?rev=1210131&view=rev
Log:
committing changes for JDO-696 & JDO-698

Added:
    db/jdo/trunk/tck/src/conf/throwOnUnknownStandardProperties.conf
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java
Modified:
    db/jdo/trunk/api/src/java/javax/jdo/Bundle.properties
    db/jdo/trunk/api/src/java/javax/jdo/Constants.java
    db/jdo/trunk/api/src/java/javax/jdo/JDOHelper.java
    db/jdo/trunk/api/src/java/javax/jdo/spi/JDOImplHelper.java
    db/jdo/trunk/api/test/java/javax/jdo/JDOHelperTest.java
    db/jdo/trunk/api/test/java/javax/jdo/spi/JDOImplHelperTest.java
    db/jdo/trunk/tck/src/conf/configurations.list
    db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java

Modified: db/jdo/trunk/api/src/java/javax/jdo/Bundle.properties
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/java/javax/jdo/Bundle.properties?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/api/src/java/javax/jdo/Bundle.properties (original)
+++ db/jdo/trunk/api/src/java/javax/jdo/Bundle.properties Sun Dec  4 16:05:45 2011
@@ -154,3 +154,5 @@ MSG_EnhancerClassPath=Enhancer processin
 MSG_EnhancerOutputDirectory=Enhancer processing output directory {0}.
 ERR_EnhancerBadClassPath=Enhancer cannot construct URL from path {0}.
 MSG_EnhancerProperty:Enhancer property key:{0} value:{1}.
+EXC_UnknownStandardProperty=The property {0} begins with javax.jdo but is not a recognized
standard JDO property.
+EXC_UnknownStandardProperties=Multiple properties begin with javax.jdo but are not recognized
standard JDO properties:  {0}

Modified: db/jdo/trunk/api/src/java/javax/jdo/Constants.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/java/javax/jdo/Constants.java?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/api/src/java/javax/jdo/Constants.java (original)
+++ db/jdo/trunk/api/src/java/javax/jdo/Constants.java Sun Dec  4 16:05:45 2011
@@ -26,6 +26,17 @@ package javax.jdo;
 public interface Constants {
 
     /**
+     * The JDO standard package name.
+     * @since 3.1
+     */
+    static String JAVAX_JDO = "javax.jdo";
+    
+    /**
+     * The JDO standard property string and option string prefix.
+     */
+    static String JAVAX_JDO_PREFIX = JAVAX_JDO + ".";
+    
+    /**
      * The name of the standard service configuration resource text file containing
      * the name of an implementation of {@link PersistenceManagerFactory}.
      * Constant value is <code>META-INF/services/javax.jdo.PersistenceManagerFactory</code>.
@@ -1068,5 +1079,4 @@ public interface Constants {
      * @since 2.2
      */
     public static final String TX_SERIALIZABLE = "serializable"; 
-
 }

Modified: db/jdo/trunk/api/src/java/javax/jdo/JDOHelper.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/java/javax/jdo/JDOHelper.java?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/api/src/java/javax/jdo/JDOHelper.java (original)
+++ db/jdo/trunk/api/src/java/javax/jdo/JDOHelper.java Sun Dec  4 16:05:45 2011
@@ -22,14 +22,29 @@
  
 package javax.jdo;
 
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xml.sax.ErrorHandler;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Node;
-import org.w3c.dom.NamedNodeMap;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
 
 import javax.jdo.spi.I18NHelper;
 import javax.jdo.spi.JDOImplHelper;
@@ -45,29 +60,15 @@ import javax.xml.parsers.DocumentBuilder
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Collections;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Properties;
-import java.util.Enumeration;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 
 /**
@@ -794,11 +795,15 @@ public class JDOHelper implements Consta
      */
     protected static PersistenceManagerFactory getPersistenceManagerFactory
             (Map<?, ?> overrides, Map<?, ?> props, ClassLoader pmfClassLoader)
{
+        
         List<Throwable> exceptions = new ArrayList<Throwable>();
         if (pmfClassLoader == null)
             throw new JDOFatalUserException (msg.msg (
                 "EXC_GetPMFNullLoader")); //NOI18N
 
+        JDOImplHelper.assertOnlyKnownStandardProperties(overrides);
+        JDOImplHelper.assertOnlyKnownStandardProperties(props);
+        
         // first try to get the class name from the properties object.
         String pmfClassName = (String) props.get (
                 PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS);

Modified: db/jdo/trunk/api/src/java/javax/jdo/spi/JDOImplHelper.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/src/java/javax/jdo/spi/JDOImplHelper.java?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/api/src/java/javax/jdo/spi/JDOImplHelper.java (original)
+++ db/jdo/trunk/api/src/java/javax/jdo/spi/JDOImplHelper.java Sun Dec  4 16:05:45 2011
@@ -44,11 +44,14 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import java.util.WeakHashMap;
 
+import javax.jdo.Constants;
 import javax.jdo.JDOException;
 import javax.jdo.JDOFatalInternalException;
 import javax.jdo.JDOFatalUserException;
+import javax.jdo.JDOHelper;
 import javax.jdo.JDOUserException;
 import javax.xml.parsers.DocumentBuilderFactory;
 
@@ -124,6 +127,68 @@ public class JDOImplHelper extends java.
      */
     private static ErrorHandler errorHandler;
 
+    /**
+     * JDO standard properties that the user can configure.
+     */
+    public static final Set<String> USER_CONFIGURABLE_STANDARD_PROPERTIES = createUserConfigurableStandardProperties();
+
+    private static Set<String> createUserConfigurableStandardProperties() {
+        Set<String> props = new HashSet<String>();
+        
+        props.add(Constants.PROPERTY_CONNECTION_DRIVER_NAME);
+        props.add(Constants.PROPERTY_CONNECTION_FACTORY2_NAME);
+        props.add(Constants.PROPERTY_CONNECTION_FACTORY_NAME);
+        props.add(Constants.PROPERTY_CONNECTION_PASSWORD);
+        props.add(Constants.PROPERTY_CONNECTION_URL);
+        props.add(Constants.PROPERTY_CONNECTION_USER_NAME);
+        props.add(Constants.PROPERTY_COPY_ON_ATTACH);
+        props.add(Constants.PROPERTY_DATASTORE_READ_TIMEOUT_MILLIS);
+        props.add(Constants.PROPERTY_DATASTORE_WRITE_TIMEOUT_MILLIS);
+        props.add(Constants.PROPERTY_DETACH_ALL_ON_COMMIT);
+        props.add(Constants.PROPERTY_IGNORE_CACHE);
+        props.add(Constants.PROPERTY_INSTANCE_LIFECYCLE_LISTENER);
+        props.add(Constants.PROPERTY_MAPPING);
+        props.add(Constants.PROPERTY_MAPPING_CATALOG);
+        props.add(Constants.PROPERTY_MAPPING_SCHEMA);
+        props.add(Constants.PROPERTY_MULTITHREADED);
+        props.add(Constants.PROPERTY_NAME);
+        props.add(Constants.PROPERTY_NONTRANSACTIONAL_READ);
+        props.add(Constants.PROPERTY_NONTRANSACTIONAL_WRITE);
+        props.add(Constants.PROPERTY_OPTIMISTIC);
+        props.add(Constants.PROPERTY_PERSISTENCE_MANAGER_FACTORY_CLASS);
+        props.add(Constants.PROPERTY_PERSISTENCE_UNIT_NAME);
+        props.add(Constants.PROPERTY_READONLY);
+        props.add(Constants.PROPERTY_RESTORE_VALUES);
+        props.add(Constants.PROPERTY_RETAIN_VALUES);
+        props.add(Constants.PROPERTY_SERVER_TIME_ZONE_ID);
+        props.add(Constants.PROPERTY_SPI_RESOURCE_NAME);
+        props.add(Constants.PROPERTY_TRANSACTION_ISOLATION_LEVEL);
+        props.add(Constants.PROPERTY_TRANSACTION_TYPE);
+        
+        return Collections.unmodifiableSet(props);
+    }
+
+    static final String JAVAX_JDO_PREFIX_LOWER_CASED =
+	    Constants.JAVAX_JDO_PREFIX.toLowerCase();
+    
+    static final String PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER_LOWER_CASED =
+	    Constants.PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER.toLowerCase();
+    
+    static final Set<String> USER_CONFIGURABLE_STANDARD_PROPERTIES_LOWER_CASED =
+	    createUserConfigurableStandardPropertiesLowerCased();
+    
+    static Set<String> createUserConfigurableStandardPropertiesLowerCased() {
+	Set<String> mixedCased = createUserConfigurableStandardProperties();
+	Set<String> lowerCased =
+		new HashSet<String>(mixedCased.size());
+
+	for (String propertyName : mixedCased) {
+	    lowerCased.add(propertyName.toLowerCase());
+	}
+	return Collections.unmodifiableSet(lowerCased);
+    }
+    
+    
     /** Register the default DateFormat instance.
      */
     static {
@@ -133,7 +198,7 @@ public class JDOImplHelper extends java.
     /** Creates new JDOImplHelper */
     private JDOImplHelper() {
     }
-    
+
     /** Get an instance of <code>JDOImplHelper</code>.  This method
      * checks that the caller is authorized for 
      * <code>JDOPermission("getMetadata")</code>, and if not, throws 
@@ -1079,4 +1144,59 @@ public class JDOImplHelper extends java.
          */
         public Object get(Object pc, StateInterrogation si);
     }
+
+    /**
+     * Examines the given map for keys beginning with the JDO standard prefix,
+     * {@link Constants#JAVAX_JDO_PREFIX}. If any property keys are found with
+     * that prefix but are unknown to this version of the JDO standard, a
+     * JDOUserException is thrown with a message indicating the unknown
+     * property. Keys that are not strings are ignored, as are string keys
+     * beginning with
+     * {@link Constants#PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER} or not
+     * beginning with {@link Constants#JAVAX_JDO_PREFIX}.
+     * 
+     * @param properties
+     *            The properties to examine.
+     * 
+     * @see Constants#JAVAX_JDO_PREFIX
+     * @see JDOHelper#USER_CONFIGURABLE_STANDARD_PROPERTIES
+     * @since 3.1
+     */
+    public static void assertOnlyKnownStandardProperties(Map<?, ?> properties) {
+        if (properties == null || properties.isEmpty())
+            return;
+
+        List<JDOUserException> exceptions = new ArrayList<JDOUserException>();
+        StringBuilder unknowns = new StringBuilder();
+
+        for (Object key : properties.keySet()) {
+            if (!(key instanceof String)) {
+                continue; // ignore keys not of type string
+            }
+            String s = ((String) key).toLowerCase(); // compare case-insensitively
+            if (!s.startsWith(JAVAX_JDO_PREFIX_LOWER_CASED)) {
+                continue; // ignore vendor-specific keys
+            }
+            if (s.startsWith(PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER_LOWER_CASED)) {
+                continue; // ignore listener class names
+            }
+            if (!USER_CONFIGURABLE_STANDARD_PROPERTIES_LOWER_CASED.contains(s)) {
+                exceptions.add(new JDOUserException(msg.msg(
+                        "EXC_UnknownStandardProperty", s)));
+
+                if (exceptions.size() > 1) {
+                    unknowns.append(",");
+                }
+                unknowns.append(s);
+            }
+        }
+
+        if (exceptions.size() == 1) {
+            throw exceptions.get(0);
+        } else if (exceptions.size() > 1) {
+            throw new JDOUserException(msg.msg("EXC_UnknownStandardProperties",
+                    unknowns.toString()),
+                    exceptions.toArray(new JDOUserException[] {}));
+        }
+    }
 }

Modified: db/jdo/trunk/api/test/java/javax/jdo/JDOHelperTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/java/javax/jdo/JDOHelperTest.java?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/api/test/java/javax/jdo/JDOHelperTest.java (original)
+++ db/jdo/trunk/api/test/java/javax/jdo/JDOHelperTest.java Sun Dec  4 16:05:45 2011
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import javax.jdo.pc.PCPoint;
+import javax.jdo.spi.JDOImplHelper;
 import javax.jdo.util.AbstractTest;
 import javax.jdo.util.BatchTestRunner;
 
@@ -566,7 +567,55 @@ public class JDOHelperTest extends Abstr
                 println("Caught expected exception " + ex);
         }
     }
+    
+    /** Test that an unknown standard property cause JDOUserException.
+     */
+    public void testUnknownStandardProperty() {
+        Properties p = new Properties();
+        p.setProperty("javax.jdo.unknown.standard.property", "value");
+        try {
+            JDOHelper.getPersistenceManagerFactory(p);
+            fail("testUnknownStandardProperties should result in JDOUserException. "
+                    + "No exception was thrown.");
+        } catch (JDOUserException x) {
+            if (verbose)
+                println("Caught expected exception " + x);
+        }
+    }
+
+    /**
+     * Test that unknown standard properties cause JDOUserException w/nested
+     * exceptions.
+     */
+    public void testUnknownStandardProperties() {
+        Properties p = new Properties();
+        p.setProperty("javax.jdo.unknown.standard.property.1", "value");
+        p.setProperty("javax.jdo.unknown.standard.property.2", "value");
+
+        JDOUserException x = null;
 
+        try {
+            JDOHelper.getPersistenceManagerFactory(p);
+            fail("testUnknownStandardProperties should result in JDOUserException. "
+                    + "No exception was thrown.");
+        } catch (JDOUserException thrown) {
+            if (verbose)
+                println("Caught expected exception " + thrown);
+            x = thrown;
+        }
+
+        Throwable[] nesteds = x.getNestedExceptions();
+
+        assertNotNull(nesteds);
+        assertEquals("should have been 2 nested exceptions", 2, nesteds.length);
+        for (int i = 0; i < nesteds.length; i++) {
+            Throwable t = nesteds[i];
+            assertTrue("nested exception " + i
+                    + " should have been JDOUserException",
+                    t instanceof JDOUserException);
+        }
+    }
+    
     private Context getInitialContext() {
         try {
             return new InitialContext();

Modified: db/jdo/trunk/api/test/java/javax/jdo/spi/JDOImplHelperTest.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api/test/java/javax/jdo/spi/JDOImplHelperTest.java?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/api/test/java/javax/jdo/spi/JDOImplHelperTest.java (original)
+++ db/jdo/trunk/api/test/java/javax/jdo/spi/JDOImplHelperTest.java Sun Dec  4 16:05:45 2011
@@ -18,7 +18,11 @@
 package javax.jdo.spi;
 
 import java.util.Collection;
+import java.util.Properties;
 
+import javax.jdo.Constants;
+import javax.jdo.JDOHelper;
+import javax.jdo.JDOUserException;
 import javax.jdo.pc.PCPoint;
 import javax.jdo.util.AbstractTest;
 import javax.jdo.util.BatchTestRunner;
@@ -193,6 +197,95 @@ public class JDOImplHelperTest extends A
         }
     }
 
+    /**
+     * Test that an unknown standard property causes JDOUserException.
+     */
+    public void testUnknownStandardProperty() {
+        Properties p = new Properties();
+        p.setProperty("javax.jdo.unknown.standard.property", "value");
+
+        JDOUserException x = null;
+
+        try {
+            JDOImplHelper.assertOnlyKnownStandardProperties(p);
+            fail("testUnknownStandardProperty should result in JDOUserException. "
+                    + "No exception was thrown.");
+        } catch (JDOUserException thrown) {
+            if (verbose)
+                println("Caught expected exception " + thrown);
+            x = thrown;
+        }
+        assertNull("should have had no nested exceptions",
+                x.getNestedExceptions());
+    }
+
+    /**
+     * Test that unknown standard properties cause JDOUserException w/nested
+     * exceptions.
+     */
+    public void testUnknownStandardProperties() {
+        Properties p = new Properties();
+        p.setProperty("javax.jdo.unknown.standard.property.1", "value");
+        p.setProperty("javax.jdo.unknown.standard.property.2", "value");
+
+        JDOUserException x = null;
+
+        try {
+            JDOImplHelper.assertOnlyKnownStandardProperties(p);
+            fail("testUnknownStandardProperties should result in JDOUserException. "
+                    + "No exception was thrown.");
+        } catch (JDOUserException thrown) {
+            if (verbose)
+                println("Caught expected exception " + thrown);
+            x = thrown;
+        }
+
+        Throwable[] nesteds = x.getNestedExceptions();
+
+        assertNotNull(nesteds);
+        assertEquals("should have been 2 nested exceptions", 2, nesteds.length);
+        for (int i = 0; i < nesteds.length; i++) {
+            Throwable t = nesteds[i];
+            assertTrue("nested exception " + i
+                    + " should have been JDOUserException",
+                    t instanceof JDOUserException);
+        }
+    }
+
+    /**
+     * Test that unknown non-standard properties & well-formed listener
+     * properties don't cause JDOUserException.
+     */
+    public void testUnknownNonStandardPropertiesAndListeners() {
+        Properties p = new Properties();
+        p.put("unknown.property", "value");
+        p.put(new Object(), "value");
+        p.put(Constants.PROPERTY_PREFIX_INSTANCE_LIFECYCLE_LISTENER
+                + "unknown.listener", "value");
+        JDOImplHelper.assertOnlyKnownStandardProperties(p);
+    }
+
+    /**
+     * Test that all JDO standard properties don't cause JDOUserException.
+     */
+    public void testOnlyStandardProperties() {
+        Properties props = new Properties();
+        for (String p : JDOImplHelper.USER_CONFIGURABLE_STANDARD_PROPERTIES) {
+            props.setProperty(p, p);
+        }
+        JDOImplHelper.assertOnlyKnownStandardProperties(props);
+    }
+    
+    /**
+     * Test that an known standard property in mixed case succeeds.
+     */
+    public void testKnownStandardPropertyThatDiffersInCaseOnly() {
+        Properties p = new Properties();
+        p.setProperty("JaVaX.jDo.oPtIoN.CoNNectionDRiVerNamE", "value");
+        p.setProperty("jAvAx.JdO.lIsTeNeR.InstaNceLifeCycleLisTener.foo.Bar", "");
+        JDOImplHelper.assertOnlyKnownStandardProperties(p);
+    }
+
     /** */
     class SimpleListener implements RegisterClassListener {
 

Modified: db/jdo/trunk/tck/src/conf/configurations.list
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/conf/configurations.list?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/conf/configurations.list (original)
+++ db/jdo/trunk/tck/src/conf/configurations.list Sun Dec  4 16:05:45 2011
@@ -70,4 +70,5 @@ jdo.tck.cfglist = \
                  schemaAttributeClass.conf \
                  schemaAttributeOrm.conf \
                  schemaAttributePackage.conf \
-                 compoundIdentity.conf
+                 compoundIdentity.conf \
+                 throwOnUnknownStandardProperties.conf

Added: db/jdo/trunk/tck/src/conf/throwOnUnknownStandardProperties.conf
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/conf/throwOnUnknownStandardProperties.conf?rev=1210131&view=auto
==============================================================================
--- db/jdo/trunk/tck/src/conf/throwOnUnknownStandardProperties.conf (added)
+++ db/jdo/trunk/tck/src/conf/throwOnUnknownStandardProperties.conf Sun Dec  4 16:05:45 2011
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+jdo.tck.description = Checks that the implementation throws JDOUserException on unknown JDO
standard properties.
+jdo.tck.mapping.companyfactory =
+jdo.tck.classes = org.apache.jdo.tck.api.persistencemanagerfactory.config.ThrowOnUnknownStandardProperties
+jdo.tck.testdata = 
+jdo.tck.mapping = 
+jdo.tck.requiredOptions =

Modified: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java?rev=1210131&r1=1210130&r2=1210131&view=diff
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java (original)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/JDO_Test.java Sun Dec  4 16:05:45 2011
@@ -58,6 +58,7 @@ import junit.framework.TestCase;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.springframework.util.ClassUtils;
 
 public abstract class JDO_Test extends TestCase {
     public static final int TRANSIENT                           = 0;
@@ -249,8 +250,19 @@ public abstract class JDO_Test extends T
      */
     private Collection tearDownClasses = new LinkedList();
     
-    /** */
+    /**
+     * Intended for subclasses so that they may skip this class's normal set up procedure.
+     * @return true to run normal set up, false to skip normal set up
+     */
+    protected boolean preSetUp() {
+        return true;
+    }
+
     protected final void setUp() throws Exception {
+        if (!preSetUp()) {
+            return;
+        }
+
         pmf = getPMF();
         localSetUp();
     }
@@ -305,6 +317,14 @@ public abstract class JDO_Test extends T
     }
     
     /**
+     * Intended for subclasses so that they may skip this class's normal tear down procedure.
+     * @return true to run normal tear down, false to skip normal tear down
+     */
+    protected boolean preTearDown() {
+        return true;
+    }
+    
+    /**
      * This method clears data and resources allocated by testcases.
      * It first closes the persistence manager of this testcase.
      * Then it calls method <code>localTearDown</code>. 
@@ -324,6 +344,10 @@ public abstract class JDO_Test extends T
      *  jdo.tck.closePMFAfterEachTest is set to true.
      */
     protected final void tearDown() {
+        if (!preTearDown()) {
+            return;
+        }
+
         try {
             cleanupPM();
         } 
@@ -498,6 +522,22 @@ public abstract class JDO_Test extends T
         return pmf;
     }
 
+    protected Class getPMFClass()
+    {
+        if (pmf != null) {
+            return pmf.getClass();
+        }
+        
+        PMFPropertiesObject = loadProperties(PMFProperties);
+        String name = PMFPropertiesObject.getProperty(PMF_CLASS_PROP);
+        try {
+            return Class.forName(name);
+        } catch (ClassNotFoundException ex) {
+            throw new JDOException("Cannot find PMF class '" + name + "'.",
+                                   ex);
+        }
+    }
+    
     /**
      * Get the <code>PersistenceManagerFactory</code> instance 
      * for the implementation under test. This method does NOT use the
@@ -510,17 +550,14 @@ public abstract class JDO_Test extends T
     protected PersistenceManagerFactory getUnconfiguredPMF()
     {
         if (pmf == null) {
-            PMFPropertiesObject = loadProperties(PMFProperties); // will exit here if no
properties
-            String name = PMFPropertiesObject.getProperty(PMF_CLASS_PROP);
+            String name = null;
             try {
-                Class pmfClass = Class.forName(name);
+                Class pmfClass = getPMFClass();
+                name = pmfClass.getName();
                 pmf = (PersistenceManagerFactory) pmfClass.newInstance();
                 if (supportedOptions == null) {
                     supportedOptions = pmf.supportedOptions();
                 }
-            } catch (ClassNotFoundException ex) {
-                throw new JDOException("Cannot find PMF class '" + name + "'.",
-                                       ex);
             } catch (InstantiationException ex) {
                 throw new JDOException("Cannot instantiate PMF class '" + 
                                        name + "'.", ex);

Added: db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java?rev=1210131&view=auto
==============================================================================
--- db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java
(added)
+++ db/jdo/trunk/tck/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java
Sun Dec  4 16:05:45 2011
@@ -0,0 +1,109 @@
+package org.apache.jdo.tck.api.persistencemanagerfactory.config;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jdo.JDOException;
+import javax.jdo.JDOUserException;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+public class ThrowOnUnknownStandardProperties extends JDO_Test {
+
+    /**
+     * The <code>main</code> is called when the class
+     * is directly executed from the command line.
+     * @param args The arguments passed to the program.
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(ThrowOnUnknownStandardProperties.class);
+    }
+
+    protected boolean preSetUp() {
+        return false;
+    }
+
+    protected boolean preTearDown() {
+        return false;
+    }
+
+    protected Method getStaticGetPMFMethod() {
+        Class pmfClass = getPMFClass();
+        try {
+            Method m = pmfClass.getDeclaredMethod(
+                    "getPersistenceManagerFactory", new Class[] {Map.class});
+
+            if ((m.getModifiers() & Modifier.STATIC) != Modifier.STATIC) {
+                throw new JDOException(
+                        "PMF class "
+                                + pmfClass.getName()
+                                + " method 'getPersistenceManagerFactory' is not static");
+            }
+
+            return m;
+        } catch (SecurityException e) {
+            throw new JDOException(
+                    "Cannot get method 'getPersistenceManagerFactory' from PMF class "
+                            + pmfClass.getName(), e);
+        } catch (NoSuchMethodException e) {
+            throw new JDOException(
+                    "No method 'getPersistenceManagerFactory' from PMF class "
+                            + pmfClass.getName(), e);
+        }
+    }
+
+    protected void invokeGetPMF(Object... args) throws Exception {
+        Method getPMF = getStaticGetPMFMethod();
+        getPMF.invoke(null, args);
+    }
+    
+    public void testUnknownStandardProperty() {
+        Properties p = new Properties();
+        p.setProperty("javax.jdo.unknown.standard.property", "value");
+        try {
+            invokeGetPMF(p);
+            fail("testUnknownStandardProperty should result in JDOUserException. "
+                    + "No exception was thrown.");
+        } catch (JDOUserException x) {
+            // :)
+        } catch (Exception e) {
+            throw new JDOException(
+                    "failed to invoke static getPersistenceManagerFactory(Map) method on
PMF class",
+                    e);
+        }
+    }
+
+    public void testUnknownStandardProperties() {
+        Properties p = new Properties();
+        p.setProperty("javax.jdo.unknown.standard.property.1", "value");
+        p.setProperty("javax.jdo.unknown.standard.property.2", "value");
+
+        JDOUserException x = null;
+
+        try {
+            invokeGetPMF(p);
+            fail("testUnknownStandardProperties should result in JDOUserException. "
+                    + "No exception was thrown.");
+        } catch (JDOUserException thrown) {
+            x = thrown;
+        } catch (Exception e) {
+            throw new JDOException(
+                    "failed to invoke static getPersistenceManagerFactory(Map) method on
PMF class",
+                    e);
+        }
+
+        Throwable[] nesteds = x.getNestedExceptions();
+
+        assertNotNull(nesteds);
+        assertEquals("should have been 2 nested exceptions", 2, nesteds.length);
+        for (int i = 0; i < nesteds.length; i++) {
+            Throwable t = nesteds[i];
+            assertTrue("nested exception " + i
+                    + " should have been JDOUserException",
+                    t instanceof JDOUserException);
+        }
+    }
+}



Mime
View raw message