Index: src/conf/pm.conf =================================================================== --- src/conf/pm.conf (revision 453386) +++ src/conf/pm.conf (working copy) @@ -98,4 +98,5 @@ org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientFailsWithDirtyInstance \ org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientFieldsPreservedUnchanged \ org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientHasNoEffectOnTransientInstances \ -org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientNotSubjectToRollback +org.apache.jdo.tck.api.persistencemanager.lifecycle.MakeTransientNotSubjectToRollback \ +org.apache.jdo.tck.api.persistencemanager.nullargs.MakePersistentNullArgs Index: src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/MakePersistentNullArgs.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/MakePersistentNullArgs.java (revision 0) +++ src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/MakePersistentNullArgs.java (revision 0) @@ -0,0 +1,245 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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. + */ + + +package org.apache.jdo.tck.api.persistencemanager.nullargs; + +import java.util.Collection; +import java.util.HashSet; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Make Persistent with Null Arguments + *
+ *Keywords: + *
+ *Assertion IDs: A12.6.3, A12.6.4, A12.6.5 + *
+ *Assertion Description: +A12.6-3 [Null arguments to APIs that take an Object parameter cause the API to have no effect.] A12.6-4 [Null arguments to APIs that take Object[] or Collection will cause the API to throw NullPointerException.] A12.6-5 [Non-null Object[] or Collection arguments that contain null elements will have the documented behavior for non-null elements, and the null elements will be ignored.] + */ + +public class MakePersistentNullArgs extends PersistenceManagerNullsTest { + + /** */ + private static final String ASSERTION3_FAILED = + "Assertion A12.6-3 on makePersistent() failed: "; + + private static final String ASSERTION4_FAILED = + "Assertion A12.6-4 on makePersistentAll() failed: "; + + private static final String ASSERTION5_FAILED = + "Assertion A12.6-5 on makePersistentAll() failed: "; + + /** + * 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(MakePersistentNullArgs.class); + } + + /** + * Test that makePersistent() with null valued argument does nothing. + */ + public void testMakePersistentNullObj() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + try { + tx = pm.currentTransaction(); + + tx.begin(); + try { + pm.makePersistent(pNull1); + } catch (Exception e) { + fail(ASSERTION3_FAILED, + "makePersistent() on a null object should do nothing." + + " Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (debug) logger.debug( + " \nPASSED in testMakePersistentNullObj()"); + } + finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with null valued Collection argument + * throws NullPointerException. + */ + public void testMakePersistentNullCollection() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + + try { + tx.begin(); + try { + pm.makePersistentAll(collNull); + fail(ASSERTION4_FAILED, + "makePersistentAll(Collecton=null) should throw NPE."); + } catch (NullPointerException npe) { + // this is what we want + } catch (Exception e) { + fail(ASSERTION4_FAILED, + "makePersistentAll(Collecton=null) should throw NPE." + + " Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (debug) logger.debug( + " \nPASSED in testMakePersistentNullCollection()"); + } + finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with null valued array argument + * throws NullPointerException. + */ + public void testMakePersistentNullArray() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + + try { + tx.begin(); + try { + pm.makePersistentAll(arrayNull); + fail(ASSERTION4_FAILED, + "makePersistentAll(Object[]=null) should throw NPE."); + } catch (NullPointerException npe) { + // this is what we want + } catch (Exception e) { + fail(ASSERTION4_FAILED, + "makePersistentAll(Array=null) should throw NPE." + + " Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (debug) logger.debug( + " \nPASSED in testMakePersistentNullArray()"); + } + finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with a null element of a + * Collection argument throws NullPointerException. + */ + public void testMakePersistentCollNullElem() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + try { + tx = pm.currentTransaction(); + + tx.begin(); + try { + pm.makePersistentAll(collNullElem); + } catch (Exception e) { + fail(ASSERTION5_FAILED, + "makePersistent() on a null Collection element should" + + " do nothing. Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (!elementPersisted(collNullElem)) { + fail(ASSERTION5_FAILED, + "makePersistent() on Collection element failed!"); + } + + if (debug) logger.debug( + " \nPASSED in testMakePersistentCollNullElem()"); + } finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with a null element of a + * array argument throws NullPointerException. + */ + public void testMakePersistentArrayNullElem() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + try { + tx = pm.currentTransaction(); + + tx.begin(); + try { + pm.makePersistentAll(arrayNullElem); + } catch (Exception e) { + fail(ASSERTION5_FAILED, + "makePersistentAll() on a null array element should " + + "do nothing. Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (!elementPersisted(arrayNullElem)) { + fail(ASSERTION5_FAILED, + "makePersistentAll() on array element failed!"); + } + + if (debug) logger.debug( + " \nPASSED in testMakePersistentArrayNullElem()"); + } finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + +} Index: src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/PersistenceManagerNullsTest.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/PersistenceManagerNullsTest.java (revision 0) +++ src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/PersistenceManagerNullsTest.java (revision 0) @@ -0,0 +1,112 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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. + */ + +package org.apache.jdo.tck.api.persistencemanager.nullargs; + + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; + +/** + * This is the superclass for the tests of null arguments + * to pm methods. + * + * Null arguments to APIs that take an Object parameter cause the API + * to have no effect. Null arguments to APIs that take Object[] or Collection + * will cause the API to throw NullPointerException. Non-null Object[] or + * Collection arguments that contain null elements will have the documented + * behavior for non-null elements, and the null elements will be ignored. + * + */ + +public class PersistenceManagerNullsTest extends JDO_Test { + + protected PCPoint pNull1 = null; + protected PCPoint pNull2 = null; + protected PCPoint pNull3 = null; + protected PCPoint pNotNull1 = null; + protected PCPoint pNotNull2 = null; + protected PCPoint pNotNull3 = null; + protected Collection collNull = null; + protected Collection collNullElem = null; + protected Object[] arrayNull = null; + protected Object[] arrayNullElem = null; + + /** */ + protected PersistenceManagerNullsTest() { } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + // The order of addTearDownClass calls is significant + // as it takes into account database FKs. + addTearDownClass(PCPoint.class); + } + + protected void setUp() { + + // Initialize non-null Point objects + pNotNull1 = new PCPoint(3, 5); + pNotNull2 = new PCPoint(4, 8); + pNotNull3 = new PCPoint(1, 20); + + // Initialize Collection with null element + collNullElem = new HashSet(); + collNullElem.add(pNotNull2); + collNullElem.add(pNull2); + + // Initialize array with null element + Collection collTmp = new HashSet(); + collTmp.add(pNotNull3); + collTmp.add(pNull3); + arrayNullElem = collTmp.toArray(); + } + + protected boolean elementPersisted(Object[] objs) { + + for (int i=0; i < objs.length; i++) { + if (objs[i] == null) + continue; + if (!JDOHelper.isPersistent(objs[i])) + return false; + } + return true; + } + + protected boolean elementPersisted(Collection objs) { + + Iterator it = objs.iterator(); + while (it.hasNext()) { + if (it.next() == null) + continue; + if (!JDOHelper.isPersistent(it.next())) + return false; + } + return true; + } + +} + + Index: src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/MakePersistentNullArgs.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/MakePersistentNullArgs.java (revision 0) +++ src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/MakePersistentNullArgs.java (revision 0) @@ -0,0 +1,245 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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. + */ + + +package org.apache.jdo.tck.api.persistencemanager.nullargs; + +import java.util.Collection; +import java.util.HashSet; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *Title: Make Persistent with Null Arguments + *
+ *Keywords: + *
+ *Assertion IDs: A12.6.3, A12.6.4, A12.6.5 + *
+ *Assertion Description: +A12.6-3 [Null arguments to APIs that take an Object parameter cause the API to have no effect.] A12.6-4 [Null arguments to APIs that take Object[] or Collection will cause the API to throw NullPointerException.] A12.6-5 [Non-null Object[] or Collection arguments that contain null elements will have the documented behavior for non-null elements, and the null elements will be ignored.] + */ + +public class MakePersistentNullArgs extends PersistenceManagerNullsTest { + + /** */ + private static final String ASSERTION3_FAILED = + "Assertion A12.6-3 on makePersistent() failed: "; + + private static final String ASSERTION4_FAILED = + "Assertion A12.6-4 on makePersistentAll() failed: "; + + private static final String ASSERTION5_FAILED = + "Assertion A12.6-5 on makePersistentAll() failed: "; + + /** + * 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(MakePersistentNullArgs.class); + } + + /** + * Test that makePersistent() with null valued argument does nothing. + */ + public void testMakePersistentNullObj() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + try { + tx = pm.currentTransaction(); + + tx.begin(); + try { + pm.makePersistent(pNull1); + } catch (Exception e) { + fail(ASSERTION3_FAILED, + "makePersistent() on a null object should do nothing." + + " Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (debug) logger.debug( + " \nPASSED in testMakePersistentNullObj()"); + } + finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with null valued Collection argument + * throws NullPointerException. + */ + public void testMakePersistentNullCollection() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + + try { + tx.begin(); + try { + pm.makePersistentAll(collNull); + fail(ASSERTION4_FAILED, + "makePersistentAll(Collecton=null) should throw NPE."); + } catch (NullPointerException npe) { + // this is what we want + } catch (Exception e) { + fail(ASSERTION4_FAILED, + "makePersistentAll(Collecton=null) should throw NPE." + + " Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (debug) logger.debug( + " \nPASSED in testMakePersistentNullCollection()"); + } + finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with null valued array argument + * throws NullPointerException. + */ + public void testMakePersistentNullArray() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + + try { + tx.begin(); + try { + pm.makePersistentAll(arrayNull); + fail(ASSERTION4_FAILED, + "makePersistentAll(Object[]=null) should throw NPE."); + } catch (NullPointerException npe) { + // this is what we want + } catch (Exception e) { + fail(ASSERTION4_FAILED, + "makePersistentAll(Array=null) should throw NPE." + + " Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (debug) logger.debug( + " \nPASSED in testMakePersistentNullArray()"); + } + finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with a null element of a + * Collection argument throws NullPointerException. + */ + public void testMakePersistentCollNullElem() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + try { + tx = pm.currentTransaction(); + + tx.begin(); + try { + pm.makePersistentAll(collNullElem); + } catch (Exception e) { + fail(ASSERTION5_FAILED, + "makePersistent() on a null Collection element should" + + " do nothing. Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (!elementPersisted(collNullElem)) { + fail(ASSERTION5_FAILED, + "makePersistent() on Collection element failed!"); + } + + if (debug) logger.debug( + " \nPASSED in testMakePersistentCollNullElem()"); + } finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + + /** + * Test that makePersistentAll() with a null element of a + * array argument throws NullPointerException. + */ + public void testMakePersistentArrayNullElem() { + pm = getPM(); + + Transaction tx = pm.currentTransaction(); + try { + tx = pm.currentTransaction(); + + tx.begin(); + try { + pm.makePersistentAll(arrayNullElem); + } catch (Exception e) { + fail(ASSERTION5_FAILED, + "makePersistentAll() on a null array element should " + + "do nothing. Instead we get: " + e.toString()); + e.printStackTrace(); + } + tx.commit(); + + if (!elementPersisted(arrayNullElem)) { + fail(ASSERTION5_FAILED, + "makePersistentAll() on array element failed!"); + } + + if (debug) logger.debug( + " \nPASSED in testMakePersistentArrayNullElem()"); + } finally { + if (tx.isActive()) + tx.rollback(); + } + + pm.close(); + pm = null; + } + +} Index: src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/PersistenceManagerNullsTest.java =================================================================== --- src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/PersistenceManagerNullsTest.java (revision 0) +++ src/java/org/apache/jdo/tck/api/persistencemanager/nullargs/PersistenceManagerNullsTest.java (revision 0) @@ -0,0 +1,112 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed 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. + */ + +package org.apache.jdo.tck.api.persistencemanager.nullargs; + + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; + +/** + * This is the superclass for the tests of null arguments + * to pm methods. + * + * Null arguments to APIs that take an Object parameter cause the API + * to have no effect. Null arguments to APIs that take Object[] or Collection + * will cause the API to throw NullPointerException. Non-null Object[] or + * Collection arguments that contain null elements will have the documented + * behavior for non-null elements, and the null elements will be ignored. + * + */ + +public class PersistenceManagerNullsTest extends JDO_Test { + + protected PCPoint pNull1 = null; + protected PCPoint pNull2 = null; + protected PCPoint pNull3 = null; + protected PCPoint pNotNull1 = null; + protected PCPoint pNotNull2 = null; + protected PCPoint pNotNull3 = null; + protected Collection collNull = null; + protected Collection collNullElem = null; + protected Object[] arrayNull = null; + protected Object[] arrayNullElem = null; + + /** */ + protected PersistenceManagerNullsTest() { } + + /** + * @see JDO_Test#localSetUp() + */ + protected void localSetUp() { + // The order of addTearDownClass calls is significant + // as it takes into account database FKs. + addTearDownClass(PCPoint.class); + } + + protected void setUp() { + + // Initialize non-null Point objects + pNotNull1 = new PCPoint(3, 5); + pNotNull2 = new PCPoint(4, 8); + pNotNull3 = new PCPoint(1, 20); + + // Initialize Collection with null element + collNullElem = new HashSet(); + collNullElem.add(pNotNull2); + collNullElem.add(pNull2); + + // Initialize array with null element + Collection collTmp = new HashSet(); + collTmp.add(pNotNull3); + collTmp.add(pNull3); + arrayNullElem = collTmp.toArray(); + } + + protected boolean elementPersisted(Object[] objs) { + + for (int i=0; i < objs.length; i++) { + if (objs[i] == null) + continue; + if (!JDOHelper.isPersistent(objs[i])) + return false; + } + return true; + } + + protected boolean elementPersisted(Collection objs) { + + Iterator it = objs.iterator(); + while (it.hasNext()) { + if (it.next() == null) + continue; + if (!JDOHelper.isPersistent(it.next())) + return false; + } + return true; + } + +} + +