Index: src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java (revision 0) +++ src/java/org/apache/jdo/tck/api/persistencemanagerfactory/config/ThrowOnUnknownStandardProperties.java (revision 0) @@ -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 main 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); + } + } +} Property changes on: src\java\org\apache\jdo\tck\api\persistencemanagerfactory\config\ThrowOnUnknownStandardProperties.java ___________________________________________________________________ Added: svn:mime-type + text/plain Index: src/java/org/apache/jdo/tck/JDO_Test.java =================================================================== --- src/java/org/apache/jdo/tck/JDO_Test.java (revision 1163308) +++ src/java/org/apache/jdo/tck/JDO_Test.java (working copy) @@ -58,6 +58,7 @@ 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 @@ */ 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 @@ } /** + * 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 localTearDown. @@ -324,6 +344,10 @@ * jdo.tck.closePMFAfterEachTest is set to true. */ protected final void tearDown() { + if (!preTearDown()) { + return; + } + try { cleanupPM(); } @@ -498,6 +522,22 @@ return pmf; } + protected Class getPMFClass() + { + if (pmf != null) { + return pmf.getClass(); + } + + PMFPropertiesObject = loadProperties(PMFProperties); // will exit here if no properties + 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 PersistenceManagerFactory instance * for the implementation under test. This method does NOT use the @@ -510,17 +550,14 @@ 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); Index: src/conf/throwOnUnknownStandardProperties.conf =================================================================== --- src/conf/throwOnUnknownStandardProperties.conf (revision 0) +++ src/conf/throwOnUnknownStandardProperties.conf (revision 0) @@ -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 JDOUserConfig 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 = Index: src/conf/configurations.list =================================================================== --- src/conf/configurations.list (revision 1163308) +++ src/conf/configurations.list (working copy) @@ -69,4 +69,5 @@ schemaAttributeClass.conf \ schemaAttributeOrm.conf \ schemaAttributePackage.conf \ - compoundIdentity.conf + compoundIdentity.conf \ + throwOnUnknownStandardProperties.conf