db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r289665 - in /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck: api/persistencemanager/OneInstanceOfObjectPerPersistenceManager.java lifecycle/PMReturnsIdenticalInstancesForEqualObjIds.java
Date Fri, 16 Sep 2005 22:19:01 GMT
Author: clr
Date: Fri Sep 16 15:18:59 2005
New Revision: 289665

URL: http://svn.apache.org/viewcvs?rev=289665&view=rev
Log:
Added javadoc and cleaned up test to make it a model test case.

Modified:
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/OneInstanceOfObjectPerPersistenceManager.java
    incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/lifecycle/PMReturnsIdenticalInstancesForEqualObjIds.java

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/OneInstanceOfObjectPerPersistenceManager.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/OneInstanceOfObjectPerPersistenceManager.java?rev=289665&r1=289664&r2=289665&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/OneInstanceOfObjectPerPersistenceManager.java
(original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/api/persistencemanager/OneInstanceOfObjectPerPersistenceManager.java
Fri Sep 16 15:18:59 2005
@@ -28,25 +28,26 @@
 import org.apache.jdo.tck.util.BatchTestRunner;
 
 /**
- *<B>Title:</B> Only one instance of persistent object in cache per PersistenceManager
+ *<B>Title:</B> Only one instance of persistent object in cache per 
+ PersistenceManager
  *<BR>
  *<B>Keywords:</B> cache
  *<BR>
- *<B>Assertion ID:</B> A5.4-2.
+ *<B>Assertion ID:</B> A5.4-10.
  *<BR>
  *<B>Assertion Description: </B>
-JDO implementations must manage the cache of JDO Instances such that there is
-only one JDO Instance, associated with each JDO <code>PersistenceManager</code>,
+JDO implementations must manage the cache of JDO instances such that there is
+only one JDO instance, associated with each <code>PersistenceManager</code>
 representing the persistent state of each corresponding data store object.
-(One needs a hashtable that uses <code>==</code> in order to test this).
-
  */
 
-public class OneInstanceOfObjectPerPersistenceManager extends PersistenceManagerTest {
+public class OneInstanceOfObjectPerPersistenceManager extends 
+        PersistenceManagerTest {
     
     /** */
     private static final String ASSERTION_FAILED = 
-        "Assertion A5.4-2 (OneInstanceOfObjectPerPersistenceManager) failed: ";
+        "Assertion A5.4-10 (OneInstanceOfObjectPerPersistenceManager) " +
+		"failed: ";
     
     /**
      * The <code>main</code> is called when the class
@@ -57,45 +58,98 @@
         BatchTestRunner.run(OneInstanceOfObjectPerPersistenceManager.class);
     }
 
-    /** */
+    /** 
+	 * This test creates objects in one transaction and commits.
+	 * The important object is p1.
+	 * Then, in a second transaction, it gets an object p1a by id, 
+	 * gets another object p1b by navigation, and a third object p1c by
+	 * query. All of these represent the same datastore object and
+	 * therefore must be identical in the same PersistenceManager.
+	 */
     public void test() {
-        pm = getPM();
-        Transaction tx = pm .currentTransaction();
-        try {
-            tx.setRetainValues(false);
-            tx.setRestoreValues(false);
-    
-            tx.begin();
-            PCPoint p1 = new PCPoint(10, 20);
-            PCPoint p2 = new PCPoint(20, 40);
-            PCRect rect = new PCRect(0, p1, p2);
-            pm.makePersistent(rect);
-            tx.commit();
-    
-            tx.begin();
-            Object p1Id = pm.getObjectId(p1);
-            PCPoint p1a = (PCPoint)pm.getObjectById(p1Id, true);
-            PCPoint p1b = rect.getUpperLeft();
-            PCPoint p1c = findPoint(10, 20);
-            tx.commit();
-            tx = null;
-    
-            if (p1 != p1a) {
-                fail(ASSERTION_FAILED, "getObjectById results differ");
-            }
-            if (p1 != p1b) {
-                fail(ASSERTION_FAILED, "navigation results differ");
-            }
-            if (p1 != p1c) {
-                fail(ASSERTION_FAILED, "query results differ");
-            }
+        /** The getPM method is declared in a superclass. 
+         * This is the standard way to get a PersistenceManager.
+         * The method automatically gets a PersistenceManagerFactory,
+         * gets a PersistenceManager, and puts the PersistenceManager into
+         * the field pm.
+         */
+        getPM();
+        /** This is the standard way to get a Transaction.
+         */
+        Transaction tx = pm.currentTransaction();
+
+        /** Any values for these flags should be set before 
+         * beginning a transaction.
+         */
+        tx.setRetainValues(false);
+        tx.setRestoreValues(false);
+
+        /** This is the standard way to begin a transaction.
+         */
+        tx.begin();
+        /** Create new objects to be persisted.
+         */
+        PCPoint p1 = new PCPoint(10, 20);
+        PCPoint p2 = new PCPoint(20, 40);
+        PCRect rect = new PCRect(0, p1, p2);
+        /** This test relies on persistence by reachability.
+         */
+        pm.makePersistent(rect);
+        /** This is the standard way to commit a transaction.
+         */
+        tx.commit();
+
+        /** Begin a new transaction so that the navigation 
+         * uses the object id to load the target object into the cache.
+         * The RetainValues flag false guarantees that the object fields
+         * are no longer loaded.
+         */
+        tx.begin();
+        Object p1Id = pm.getObjectId(p1);
+        /** Retrieves the field values from the datastore.
+         */
+        PCPoint p1a = (PCPoint)pm.getObjectById(p1Id, true);
+        /** Navigate to the point.
+         */
+        PCPoint p1b = rect.getUpperLeft();
+        /** Query for the point by its values in the datastore.
+         */
+        PCPoint p1c = findPoint(10, 20);
+        tx.commit();
+        tx = null;
+
+        /** Use a StringBuffer to collect results.
+         */
+        StringBuffer results = new StringBuffer();
+
+        /** Compare the original object with the object obtained
+         * by getObjectById.
+         */
+        if (p1 != p1a) {
+            results.append("getObjectById results differ. ");
+        }
+
+        /** Compare the original object with the object obtained
+         * by navigating from another object.
+         */
+        if (p1 != p1b) {
+            results.append("navigation results differ. ");
         }
-        finally {
-            if ((tx != null) && tx.isActive())
-                tx.rollback();
+        /** Compare the original object with the object obtained
+         * by query.
+         */
+        if (p1 != p1c) {
+            results.append("query results differ. ");
         }
-        pm.close();
-        pm = null;
+        if (results.length() != 0) {
+            fail(ASSERTION_FAILED + results.toString());
+        }
+
+    /** The standard way to end each test method is to simply return.
+     * Exceptions are caught by JUnit.
+     * The tearDown method ends the transaction and closes
+     * the PersistenceManager.
+     */
     }
 
     /** */
@@ -103,7 +157,8 @@
         Query q = getPM().newQuery (PCPoint.class);
         q.declareParameters ("int px, int py");
         q.setFilter ("x == px & y == py");
-        Collection results = (Collection)q.execute (new Integer(x), new Integer(y));
+        Collection results = (Collection)q.execute (new Integer(x), 
+		        new Integer(y));
         Iterator it = results.iterator();
         PCPoint ret = (PCPoint)it.next();
         return ret;

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/lifecycle/PMReturnsIdenticalInstancesForEqualObjIds.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/lifecycle/PMReturnsIdenticalInstancesForEqualObjIds.java?rev=289665&r1=289664&r2=289665&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/lifecycle/PMReturnsIdenticalInstancesForEqualObjIds.java
(original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/lifecycle/PMReturnsIdenticalInstancesForEqualObjIds.java
Fri Sep 16 15:18:59 2005
@@ -30,7 +30,7 @@
  *<BR>
  *<B>Keywords:</B> lifecycle getObjectById
  *<BR>
- *<B>Assertion IDs:</B> A5.4-2, A5.4-8, A5.4-10
+ *<B>Assertion IDs:</B> A5.4-2, A5.4-8
  *<BR>
  *<B>Assertion Description: </B>
  Any instances returned by any calls to getObjectById(Object) with the same object id instance
to the same
@@ -41,7 +41,7 @@
 
     /** */
     private static final String ASSERTION_FAILED = 
-        "Assertions A5.4-2, A5.4-8, A5.4-10 (PMReturnsIdenticalInstancesForEqualObjIds) failed:
";
+        "Assertions A5.4-2, A5.4-8 (PMReturnsIdenticalInstancesForEqualObjIds) failed: ";
     
 	private static final int NUM_OBJECTS = 50;
 



Mime
View raw message