db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcai...@apache.org
Subject svn commit: r292259 [3/3] - /incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/
Date Wed, 28 Sep 2005 19:03:17 GMT
Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java Wed Sep 28 12:03:07 2005
@@ -17,7 +17,6 @@
 package org.apache.jdo.tck.models.fieldtypes;
 
 import java.util.HashMap;
-import java.util.Hashtable;
 import java.util.Map;
 import java.util.Vector;
 
@@ -78,135 +77,102 @@
     void runTest(PersistenceManager pm) {
         if (!isMapSupported()) {
             if (debug)
-                logger.debug("JDO Implementation does not support the optional feature Map");
+                logger.debug("JDO Implementation does not support " +
+                        "the optional feature Map");
             return;
         }
-        if (!isHashMapSupported() && !isTreeMapSupported()) {
+        if (!isMapSupported() && !isTreeMapSupported()) {
             fail(ASSERTION_FAILED,
-                 "JDO Implementation supports Map, but neither HashMap nor TreeMap.");
+                 "JDO Implementation supports Map, but neither " +
+                 "Map nor TreeMap.");
         }
 
         Transaction tx = pm.currentTransaction();
-        try {
-            int i, j, n;
-            FirstSetOfTestValuesForCollection firstValue = 
-                new FirstSetOfTestValuesForCollection();
-            SecondSetOfTestValuesForCollection secondValue = 
-                new SecondSetOfTestValuesForCollection();
-
-            int ret = 0;
-            // turn on datastore transactions
-            tx.setOptimistic(false);
-            tx.begin();
-            MapStringValueCollections pi = new MapStringValueCollections();
-            pi.identifier = 1;
-            pm.makePersistent(pi);
-            Object oid = pm.getObjectId(pi);
-            n = pi.getLength();
-            // Provide initial set of values
-            for(i = 0; i < n; ++i){
-                Vector fieldSpecs = TestUtil.getFieldSpecsForMap(
-                    MapStringValueCollections.fieldSpecs[i]);
-                String fieldType = (String)fieldSpecs.get(0);
-                String valueType = (String)fieldSpecs.get(1);
-                Map map = new HashMap();
-                Vector keys = (Vector) firstValue.get(fieldType);
-                Vector values = (Vector) secondValue.get(valueType);
-
-                for (j = 0; j< keys.size(); j++) {
-                    map.put(keys.get(j), values.get(j));
-                }
+        MapStringValueCollections expectedValue =
+                new MapStringValueCollections();
+        
+        // turn on datastore transactions
+        tx.setOptimistic(false);
+        tx.begin();
+        MapStringValueCollections pi = new MapStringValueCollections();
+        pi.identifier = 1;
+        pm.makePersistent(pi);
+        Object oid = pm.getObjectId(pi);
+        // Provide initial set of values
+        setValues(pi, 1);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+
+        tx.begin();
+        setValues(expectedValue, 1);
+        checkValues(oid, expectedValue);
+        pi = (MapStringValueCollections) pm.getObjectById(oid, true);
+        setValues(pi, 2);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+
+        tx.begin();
+        // check new values
+        setValues(expectedValue, 2);
+        checkValues(oid, expectedValue);
+        tx.commit();
+    }
 
-                pi.set(i, map);
-            }
-            tx.commit();
-            // cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-
-            Hashtable firstSet = new Hashtable();
-            firstSet.put("keys", firstValue);
-            firstSet.put("values", secondValue);
-
-            checkValues(oid, firstSet); // check if persistent fields have values set
-            pi = (MapStringValueCollections) pm.getObjectById(oid, true);
-
-            // Provide new set of values     -- reverse the keys and values
-            for(i = 0; i < n; ++i){
-                Vector fieldSpecs = TestUtil.getFieldSpecsForMap(
+    /** */
+    private void setValues(MapStringValueCollections collect, int order)
+    {
+        int keyOrder = order;
+        int valueOrder = (order == 1) ? 2 : 1; // why??
+        int n = collect.getLength();
+        for (int i = 0; i < n; ++i) {
+            Vector fieldSpecs = TestUtil.getFieldSpecsForMap(
                     MapStringValueCollections.fieldSpecs[i]);
-                String fieldType = (String)fieldSpecs.get(0);
-                String valueType = (String)fieldSpecs.get(1);
-                Map map = new HashMap();
-                Vector keys = (Vector) secondValue.get(fieldType);
-                Vector values = (Vector) firstValue.get(valueType);
-
-                for (j = 0; j< keys.size(); j++) {
-                    map.put(keys.get(j), values.get(j));
-                }
-                pi.set(i, map);
+            Vector key = TestUtil.makeNewVectorInstance(
+                    (String)fieldSpecs.get(0), keyOrder);
+            Vector value = TestUtil.makeNewVectorInstance(
+                    (String)fieldSpecs.get(1), valueOrder);
+
+            HashMap map = new HashMap();
+            for (int j = 0; j< key.size(); j++) {
+                map.put(key.get(j), value.get(j));
             }
-
-            tx.commit();
-            // cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-            // check new values
-            Hashtable secondSet = new Hashtable();
-            secondSet.put("keys", secondValue);
-            secondSet.put("values", firstValue);
-
-            checkValues(oid, secondSet);
-            pi = (MapStringValueCollections) pm.getObjectById(oid, true);
-            pm.deletePersistent(pi);
-            tx.commit();
-            tx = null;
-        }
-        catch (IndexOutOfBoundsException e) {
-            logger.error(e.getMessage());
-        }
-        finally {
-            if ((tx != null) && tx.isActive())
-                tx.rollback();
+            collect.set(i, map);
+            if (debug)
+                logger.debug("Set " + i + "th value to: " + map.toString());
         }
     }
 
-    private void checkValues(Object oid, Hashtable startValue)
+    /** */
+    private void checkValues(Object oid,
+            MapStringValueCollections expectedValue)
     {
-        int i, j;
-
-        MapStringValueCollections pi = 
-            (MapStringValueCollections) pm.getObjectById(oid, true);
+        StringBuffer sbuf = new StringBuffer();
+        MapStringValueCollections pi = (MapStringValueCollections)
+                pm.getObjectById(oid, true);
         int n = pi.getLength();
-
-        Hashtable keySet = (Hashtable) startValue.get("keys");
-        Hashtable valueSet = (Hashtable) startValue.get("values");
-
-        for( i = 0; i < n; ++i){
-            Vector fieldSpecs = TestUtil.getFieldSpecsForMap(
-                MapStringValueCollections.fieldSpecs[i]);
-            String fieldType = (String)fieldSpecs.get(0);
-            String valueType = (String)fieldSpecs.get(1);
-            Map compareWith = new HashMap();
-
-            Vector keys = (Vector) keySet.get(fieldType);
-            Vector values = (Vector) valueSet.get(valueType);
-            int sz = keys.size();
-            for (j = 0; j < sz; j++) {
-                compareWith.put(keys.get(j), values.get(j));
-            }
-
+        for (int i = 0; i < n; ++i) {
+            Map compareWith = expectedValue.get(i);
             Map val = pi.get(i);
-
-            if(!val.equals(compareWith)){
-                fail(ASSERTION_FAILED,
-                     "Incorrect value for " + MapStringValueCollections.fieldSpecs[i]);
+            if (val.size() != compareWith.size()) {
+                sbuf.append("\nFor element " + i + ", expected size = " +
+                        compareWith.size() + ", actual size = " + val.size()
+                        + " . ");
+                continue;
+            }
+            if (! val.equals(compareWith)) {
+                sbuf.append("\nFor element " + i + ", expected = " +
+                        compareWith + ", actual = " + val + " . ");
             }
         }
+        if (sbuf.length() > 0) {
+            fail(ASSERTION_FAILED,
+                 "Expected and observed do not match!!" + sbuf.toString());
+        }
     }
-
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java Wed Sep 28 12:03:07 2005
@@ -18,8 +18,8 @@
 
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Hashtable;
 import java.util.Set;
+import java.util.Vector;
 
 import javax.jdo.PersistenceManager;
 import javax.jdo.Transaction;
@@ -75,76 +75,86 @@
     /** */
     void runTest(PersistenceManager pm) {
         Transaction tx = pm.currentTransaction();
-        try {
-            int i, n;
-            FirstSetOfTestValuesForCollection firstValue = new FirstSetOfTestValuesForCollection();
-            SecondSetOfTestValuesForCollection secondValue = new SecondSetOfTestValuesForCollection();
-
-            int ret = 0;
-            // turn on datastore transactions
-            tx.setOptimistic(false);
-            tx.begin();
-            SetCollections pi = new SetCollections();
-            pi.identifier = 1;
-            pm.makePersistent(pi);
-            Object oid = pm.getObjectId(pi);
-            n = pi.getLength();
-            // Provide initial set of values
-            for(i = 0; i < n; ++i){
-                String valueType = TestUtil.getFieldSpecs(SetCollections.fieldSpecs[i]);
-                pi.set( i, new HashSet((Collection)firstValue.get(valueType)));
-            }
-            tx.commit();
-            // cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-
-            checkValues(oid, firstValue); // check if persistent fields have values set
-            pi = (SetCollections) pm.getObjectById(oid, true);
-
-            // Provide new set of values
-            for( i = 0; i < n; ++i){
-                String valueType = TestUtil.getFieldSpecs(SetCollections.fieldSpecs[i]);
-                pi.set( i, new HashSet((Collection)secondValue.get(valueType)));
-            }
-            tx.commit();
-            // cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-            // check new values
-            checkValues(oid, secondValue);
-            pi = (SetCollections) pm.getObjectById(oid, true);
-            pm.deletePersistent(pi);
-            tx.commit();
-            tx = null;
-        }
-        finally {
-            if ((tx != null) && tx.isActive())
-                tx.rollback();
+        SetCollections expectedValue = new SetCollections();
+
+        // turn on datastore transactions
+        tx.setOptimistic(false);
+        tx.begin();
+        SetCollections pi = new SetCollections();
+        pi.identifier = 1;
+        pm.makePersistent(pi);
+        Object oid = pm.getObjectId(pi);
+        // Provide initial set of values
+        setValues(pi, 1);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+        
+        tx.begin();
+        setValues(expectedValue, 1);
+        // check if persistent fields have values set
+        checkValues(oid, expectedValue);
+        pi = (SetCollections) pm.getObjectById(oid, true);
+        // Provide new set of values
+        setValues(pi, 2);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+        
+        tx.begin();
+        // check new values
+        setValues(expectedValue, 2);
+        checkValues(oid, expectedValue);
+        tx.commit();
+    }
+
+    /** */
+    private void setValues(SetCollections collect, int order)
+    {
+        Collection value;
+        int n = collect.getLength();
+        for (int i = 0; i < n; ++i) {
+            String valueType = TestUtil.getFieldSpecs(
+                    SetCollections.fieldSpecs[i]);
+            value = (Collection)TestUtil.makeNewVectorInstance(
+                    valueType, order);
+            collect.set(i, (Set)value);
+            if (debug)
+                logger.debug("Set " + i + "th value to: " + value.toString());
         }
     }
 
-    private void checkValues(Object oid, Hashtable startValue)
+    /** */
+    private void checkValues(Object oid, SetCollections expectedValue)
     {
         int i;
-
-        SetCollections pi = (SetCollections) pm.getObjectById(oid, true);
+        StringBuffer sbuf = new StringBuffer();
+        SetCollections pi = (SetCollections)
+                pm.getObjectById(oid, true);
         int n = pi.getLength();
-        for( i = 0; i < n; ++i){
-            String valueType = TestUtil.getFieldSpecs(SetCollections.fieldSpecs[i]);
-            Set compareWith = new HashSet((Collection)startValue.get(valueType));
-
-            Set val = pi.get(i);
-
-            if(!val.equals(compareWith)){
-                fail(ASSERTION_FAILED,
-                     "Incorrect value for " + SetCollections.fieldSpecs[i]);
+        for (i = 0; i < n; ++i) {
+            Collection compareWith = expectedValue.get(i);
+            Collection val = pi.get(i);
+            if (val.size() != compareWith.size()) {
+                sbuf.append("\nFor element " + i + ", expected size = " +
+                        compareWith.size() + ", actual size = " + val.size()
+                        + " . ");
+                continue;
             }
+            if (! val.equals(compareWith)) {
+                sbuf.append("\nFor element " + i + ", expected = " +
+                        compareWith + ", actual = " + val + " . ");
+            }
+        }
+        if (sbuf.length() > 0) {
+            fail(ASSERTION_FAILED,
+                 "Expected and observed do not match!!" + sbuf.toString());
         }
     }
+
 
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java Wed Sep 28 12:03:07 2005
@@ -16,7 +16,6 @@
  
 package org.apache.jdo.tck.models.fieldtypes;
 
-import java.util.Hashtable;
 import java.util.TreeMap;
 import java.util.Vector;
 
@@ -77,122 +76,97 @@
     void runTest(PersistenceManager pm) {
         if (!isTreeMapSupported()) {
             if (debug)
-                logger.debug("JDO Implementation does not support the optional feature TreeMap");
+                logger.debug("JDO Implementation does not support " +
+                        "the optional feature TreeMap");
             return;
         }
 
         Transaction tx = pm.currentTransaction();
-        try {
-            int i, j, n;
-            FirstSetOfTestValuesForCollection firstValue =
-                new FirstSetOfTestValuesForCollection();
-            SecondSetOfTestValuesForCollection secondValue =
-                new SecondSetOfTestValuesForCollection();
-
-            // turn on datastore transactions
-            tx.setOptimistic(false);
-            tx.begin();
-            TreeMapStringKeyCollections pi = new TreeMapStringKeyCollections();
-            pi.identifier = 1;
-            pm.makePersistent(pi);
-            Object oid = pm.getObjectId(pi);
-            n = pi.getLength();
-            // Provide initial set of values
-            for(i = 0; i < n; ++i){
-                Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringKeyCollections.fieldSpecs[i]);
-                String fieldType = (String)fieldSpecs.get(0);
-                String valueType = (String)fieldSpecs.get(1);
-                TreeMap map = new TreeMap();
-                Vector keys = (Vector) firstValue.get(fieldType);
-                Vector values = (Vector) secondValue.get(valueType);
-
-                for (j = 0; j< keys.size(); j++) {
-                    map.put(keys.get(j), values.get(j));
-                }
-
-                pi.set(i, map);
-            }
-            tx.commit();
-            // cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-
-            Hashtable firstSet = new Hashtable();
-            firstSet.put("keys", firstValue);
-            firstSet.put("values", secondValue);
-
-            checkValues(oid, firstSet); // check if persistent fields have values set
-            pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
-
-            // Provide new set of values     -- reverse the keys and values
-            for(i = 0; i < n; ++i){
-                Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringKeyCollections.fieldSpecs[i]);
-                String fieldType = (String)fieldSpecs.get(0);
-                String valueType = (String)fieldSpecs.get(1);
-                TreeMap map = new TreeMap();
-                Vector keys = (Vector) secondValue.get(fieldType);
-                Vector values = (Vector) firstValue.get(valueType);
-
-                for (j = 0; j< keys.size(); j++) {
-                    map.put(keys.get(j), values.get(j));
-                }
+        TreeMapStringKeyCollections expectedValue =
+                new TreeMapStringKeyCollections();
+        
+        // turn on datastore transactions
+        tx.setOptimistic(false);
+        tx.begin();
+        TreeMapStringKeyCollections pi = new TreeMapStringKeyCollections();
+        pi.identifier = 1;
+        pm.makePersistent(pi);
+        Object oid = pm.getObjectId(pi);
+        // Provide initial set of values
+        setValues(pi, 1);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+
+        tx.begin();
+        setValues(expectedValue, 1);
+        checkValues(oid, expectedValue);
+        pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
+        setValues(pi, 2);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+
+        tx.begin();
+        // check new values
+        setValues(expectedValue, 2);
+        checkValues(oid, expectedValue);
+        tx.commit();
+    }
 
-                pi.set(i, map);
+    /** */
+    private void setValues(TreeMapStringKeyCollections collect, int order)
+    {
+        int keyOrder = order;
+        int valueOrder = (order == 1) ? 2 : 1; // why??
+        int n = collect.getLength();
+        for (int i = 0; i < n; ++i) {
+            Vector fieldSpecs = TestUtil.getFieldSpecsForMap(
+                    TreeMapStringKeyCollections.fieldSpecs[i]);
+            Vector key = TestUtil.makeNewVectorInstance(
+                    (String)fieldSpecs.get(0), keyOrder);
+            Vector value = TestUtil.makeNewVectorInstance(
+                    (String)fieldSpecs.get(1), valueOrder);
+
+            TreeMap map = new TreeMap();
+            for (int j = 0; j< key.size(); j++) {
+                map.put(key.get(j), value.get(j));
             }
-
-            tx.commit();
-            // cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-            // check new values
-            Hashtable secondSet = new Hashtable();
-            secondSet.put("keys", secondValue);
-            secondSet.put("values", firstValue);
-
-            checkValues(oid, secondSet);
-            pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
-            pm.deletePersistent(pi);
-            tx.commit();
-            tx = null;
-        }
-        finally {
-            if ((tx != null) && tx.isActive())
-                tx.rollback();
+            collect.set(i, map);
+            if (debug)
+                logger.debug("Set " + i + "th value to: " + map.toString());
         }
     }
 
-    private void checkValues(Object oid, Hashtable startValue){
-        int i, j;
-
-        TreeMapStringKeyCollections pi = (TreeMapStringKeyCollections) pm.getObjectById(oid, true);
+    /** */
+    private void checkValues(Object oid,
+            TreeMapStringKeyCollections expectedValue)
+    {
+        StringBuffer sbuf = new StringBuffer();
+        TreeMapStringKeyCollections pi = (TreeMapStringKeyCollections)
+                pm.getObjectById(oid, true);
         int n = pi.getLength();
-
-        Hashtable keySet = (Hashtable) startValue.get("keys");
-        Hashtable valueSet = (Hashtable) startValue.get("values");
-
-        for( i = 0; i < n; ++i){
-            Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringKeyCollections.fieldSpecs[i]);
-            String fieldType = (String)fieldSpecs.get(0);
-            String valueType = (String)fieldSpecs.get(1);
-            TreeMap compareWith = new TreeMap();
-
-            Vector keys = (Vector) keySet.get(fieldType);
-            Vector values = (Vector) valueSet.get(valueType);
-            
-            for (j = 0; j< keys.size(); j++) {
-                compareWith.put(keys.get(j), values.get(j));
-            }
-
+        for (int i = 0; i < n; ++i) {
+            TreeMap compareWith = expectedValue.get(i);
             TreeMap val = pi.get(i);
-
-            if(!val.equals(compareWith)){
-                fail(ASSERTION_FAILED,
-                     "Incorrect value for " + TreeMapStringKeyCollections.fieldSpecs[i]);
+            if (val.size() != compareWith.size()) {
+                sbuf.append("\nFor element " + i + ", expected size = " +
+                        compareWith.size() + ", actual size = " + val.size()
+                        + " . ");
+                continue;
             }
+            if (! val.equals(compareWith)) {
+                sbuf.append("\nFor element " + i + ", expected = " +
+                        compareWith + ", actual = " + val + " . ");
+            }
+        }
+        if (sbuf.length() > 0) {
+            fail(ASSERTION_FAILED,
+                 "Expected and observed do not match!!" + sbuf.toString());
         }
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java Wed Sep 28 12:03:07 2005
@@ -16,7 +16,6 @@
  
 package org.apache.jdo.tck.models.fieldtypes;
 
-import java.util.Hashtable;
 import java.util.TreeMap;
 import java.util.Vector;
 
@@ -76,123 +75,97 @@
     void runTest(PersistenceManager pm) {
         if (!isTreeMapSupported()) {
             if (debug)
-                logger.debug("JDO Implementation does not support the optional feature TreeMap");
+                logger.debug("JDO Implementation does not support " +
+                        "the optional feature TreeMap");
             return;
         }
 
         Transaction tx = pm.currentTransaction();
-        try {
-            int i, j, n;
-            FirstSetOfTestValuesForCollection firstValue =
-                new FirstSetOfTestValuesForCollection();
-            SecondSetOfTestValuesForCollection secondValue =
-                new SecondSetOfTestValuesForCollection();
-
-            // turn on datastore transactions
-            tx.setOptimistic(false);
-            tx.begin();
-            TreeMapStringValueCollections pi = new TreeMapStringValueCollections();
-            pi.identifier = 1;
-            pm.makePersistent(pi);
-            Object oid = pm.getObjectId(pi);
-            n = pi.getLength();
-// Provide initial set of values
-            for(i = 0; i < n; ++i){
-                Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringValueCollections.fieldSpecs[i]);
-                String fieldType = (String)fieldSpecs.get(0);
-                String valueType = (String)fieldSpecs.get(1);
-                TreeMap map = new TreeMap();
-                Vector keys = (Vector) firstValue.get(fieldType);
-                Vector values = (Vector) secondValue.get(valueType);
-
-                for (j = 0; j< keys.size(); j++) {
-                    map.put(keys.get(j), values.get(j));
-                }
-
-                pi.set(i, map);
-            }
-            tx.commit();
-// cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-
-            Hashtable firstSet = new Hashtable();
-            firstSet.put("keys", firstValue);
-            firstSet.put("values", secondValue);
-
-            checkValues(oid, firstSet); // check if persistent fields have values set
-            pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
-
-// Provide new set of values     -- reverse the keys and values
-            for(i = 0; i < n; ++i){
-                Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringValueCollections.fieldSpecs[i]);
-                String fieldType = (String)fieldSpecs.get(0);
-                String valueType = (String)fieldSpecs.get(1);
-                TreeMap map = new TreeMap();
-                Vector keys = (Vector) secondValue.get(fieldType);
-                Vector values = (Vector) firstValue.get(valueType);
-
-                for (j = 0; j< keys.size(); j++) {
-                    map.put(keys.get(j), values.get(j));
-                }
+        TreeMapStringValueCollections expectedValue =
+                new TreeMapStringValueCollections();
+        
+        // turn on datastore transactions
+        tx.setOptimistic(false);
+        tx.begin();
+        TreeMapStringValueCollections pi = new TreeMapStringValueCollections();
+        pi.identifier = 1;
+        pm.makePersistent(pi);
+        Object oid = pm.getObjectId(pi);
+        // Provide initial set of values
+        setValues(pi, 1);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+
+        tx.begin();
+        setValues(expectedValue, 1);
+        checkValues(oid, expectedValue);
+        pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
+        setValues(pi, 2);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+
+        tx.begin();
+        // check new values
+        setValues(expectedValue, 2);
+        checkValues(oid, expectedValue);
+        tx.commit();
+    }
 
-                pi.set(i, map);
+    /** */
+    private void setValues(TreeMapStringValueCollections collect, int order)
+    {
+        int keyOrder = order;
+        int valueOrder = (order == 1) ? 2 : 1; // why??
+        int n = collect.getLength();
+        for (int i = 0; i < n; ++i) {
+            Vector fieldSpecs = TestUtil.getFieldSpecsForMap(
+                    TreeMapStringValueCollections.fieldSpecs[i]);
+            Vector key = TestUtil.makeNewVectorInstance(
+                    (String)fieldSpecs.get(0), keyOrder);
+            Vector value = TestUtil.makeNewVectorInstance(
+                    (String)fieldSpecs.get(1), valueOrder);
+
+            TreeMap map = new TreeMap();
+            for (int j = 0; j< key.size(); j++) {
+                map.put(key.get(j), value.get(j));
             }
-
-            tx.commit();
-// cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-// check new values
-            Hashtable secondSet = new Hashtable();
-            secondSet.put("keys", secondValue);
-            secondSet.put("values", firstValue);
-
-            checkValues(oid, secondSet);
-            pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
-            pm.deletePersistent(pi);
-            tx.commit();
-            tx = null;
-        }
-        finally {
-            if ((tx != null) && tx.isActive())
-                tx.rollback();
+            collect.set(i, map);
+            if (debug)
+                logger.debug("Set " + i + "th value to: " + map.toString());
         }
     }
 
-    private void checkValues(Object oid, Hashtable startValue)
+    /** */
+    private void checkValues(Object oid,
+            TreeMapStringValueCollections expectedValue)
     {
-        int i, j;
-
-        TreeMapStringValueCollections pi = (TreeMapStringValueCollections) pm.getObjectById(oid, true);
+        StringBuffer sbuf = new StringBuffer();
+        TreeMapStringValueCollections pi = (TreeMapStringValueCollections)
+                pm.getObjectById(oid, true);
         int n = pi.getLength();
-
-        Hashtable keySet = (Hashtable) startValue.get("keys");
-        Hashtable valueSet = (Hashtable) startValue.get("values");
-
-        for( i = 0; i < n; ++i){
-            Vector fieldSpecs = TestUtil.getFieldSpecsForMap(TreeMapStringValueCollections.fieldSpecs[i]);
-            String fieldType = (String)fieldSpecs.get(0);
-            String valueType = (String)fieldSpecs.get(1);
-            TreeMap compareWith = new TreeMap();
-
-            Vector keys = (Vector) keySet.get(fieldType);
-            Vector values = (Vector) valueSet.get(valueType);
-
-            for (j = 0; j< keys.size(); j++) {
-                compareWith.put(keys.get(j), values.get(j));
-            }
-
+        for (int i = 0; i < n; ++i) {
+            TreeMap compareWith = expectedValue.get(i);
             TreeMap val = pi.get(i);
-
-            if(!val.equals(compareWith)){
-                fail(ASSERTION_FAILED,
-                     "Incorrect value for " + TreeMapStringValueCollections.fieldSpecs[i]);
+            if (val.size() != compareWith.size()) {
+                sbuf.append("\nFor element " + i + ", expected size = " +
+                        compareWith.size() + ", actual size = " + val.size()
+                        + " . ");
+                continue;
             }
+            if (! val.equals(compareWith)) {
+                sbuf.append("\nFor element " + i + ", expected = " +
+                        compareWith + ", actual = " + val + " . ");
+            }
+        }
+        if (sbuf.length() > 0) {
+            fail(ASSERTION_FAILED,
+                 "Expected and observed do not match!!" + sbuf.toString());
         }
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java Wed Sep 28 12:03:07 2005
@@ -17,8 +17,8 @@
 package org.apache.jdo.tck.models.fieldtypes;
 
 import java.util.Collection;
-import java.util.Hashtable;
 import java.util.TreeSet;
+import java.util.Vector;
 
 import javax.jdo.PersistenceManager;
 import javax.jdo.Transaction;
@@ -81,84 +81,89 @@
     void runTest(PersistenceManager pm) {
         if (!isTreeSetSupported()) {
             if (debug)
-                logger.debug("JDO Implementation does not support the optional feature TreeSet");
+                logger.debug("JDO Implementation does not support " +
+                        "the optional feature TreeSet");
             return;
         }
 
         Transaction tx = pm.currentTransaction();
-        try {
-            int i, n;
-            FirstSetOfTestValuesForCollection firstValue =
-                new FirstSetOfTestValuesForCollection();
-            SecondSetOfTestValuesForCollection secondValue =
-                new SecondSetOfTestValuesForCollection();
-
-            // turn on datastore transactions
-            tx.setOptimistic(false);
-            tx.begin();
-            TreeSetCollections pi = new TreeSetCollections();
-            pi.identifier = 1;
-            pm.makePersistent(pi);
-            Object oid = pm.getObjectId(pi);
-            n = pi.getLength();
-// Provide initial set of values
-            for(i = 0; i < n; ++i){
-                String valueType = TestUtil.getFieldSpecs(
+        TreeSetCollections expectedValue = new TreeSetCollections();
+
+        // turn on datastore transactions
+        tx.setOptimistic(false);
+        tx.begin();
+        TreeSetCollections pi = new TreeSetCollections();
+        pi.identifier = 1;
+        pm.makePersistent(pi);
+        Object oid = pm.getObjectId(pi);
+        // Provide initial set of values
+        setValues(pi, 1);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+        
+        tx.begin();
+        setValues(expectedValue, 1);
+        // check if persistent fields have values set
+        checkValues(oid, expectedValue);
+        pi = (TreeSetCollections) pm.getObjectById(oid, true);
+        // Provide new set of values
+        setValues(pi, 2);
+        tx.commit();
+
+        // cache will be flushed
+        pi = null;
+        System.gc();
+        
+        tx.begin();
+        // check new values
+        setValues(expectedValue, 2);
+        checkValues(oid, expectedValue);
+        tx.commit();
+    }
+
+    /** */
+    private void setValues(TreeSetCollections collect, int order)
+    {
+        Vector value;
+        int n = collect.getLength();
+        for (int i = 0; i < n; ++i) {
+            String valueType = TestUtil.getFieldSpecs(
                     TreeSetCollections.fieldSpecs[i]);
-                pi.set( i, new TreeSet((Collection)firstValue.get(valueType)));
-            }
-            tx.commit();
-// cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-
-            checkValues(oid, firstValue); // check if persistent fields have values set
-            pi = (TreeSetCollections) pm.getObjectById(oid, true);
-
-// Provide new set of values
-            for( i = 0; i < n; ++i){
-                String valueType = TestUtil.getFieldSpecs(
-                     TreeSetCollections.fieldSpecs[i]);
-                pi.set( i, new TreeSet((Collection)secondValue.get(valueType)));
-            }
-            tx.commit();
-// cache will be flushed
-            pi = null;
-            System.gc();
-
-            tx.begin();
-// check new values
-            checkValues(oid, secondValue);
-            pi = (TreeSetCollections) pm.getObjectById(oid, true);
-            pm.deletePersistent(pi);
-            tx.commit();
-            tx = null;
-        }
-        finally {
-            if ((tx != null) && tx.isActive())
-                tx.rollback();
+            value = TestUtil.makeNewVectorInstance(valueType, order);
+            TreeSet treeSet = new TreeSet((Collection)value);
+            collect.set(i, treeSet);
+            if (debug)
+                logger.debug("Set " + i + "th value to: " + treeSet.toString());
         }
     }
 
-    private void checkValues(Object oid, Hashtable startValue)
+    /** */
+    private void checkValues(Object oid, TreeSetCollections expectedValue)
     {
-        int i;
-
-        TreeSetCollections pi = (TreeSetCollections) pm.getObjectById(oid, true);
+        StringBuffer sbuf = new StringBuffer();
+        TreeSetCollections pi = (TreeSetCollections)
+                pm.getObjectById(oid, true);
         int n = pi.getLength();
-        for( i = 0; i < n; ++i){
-            String valueType = TestUtil.getFieldSpecs(
-                TreeSetCollections.fieldSpecs[i]);
-            TreeSet compareWith = new TreeSet((Collection)startValue.get(valueType));
-
-            TreeSet val = pi.get(i);
-
-            if(!val.equals(compareWith)){
-                fail(ASSERTION_FAILED,
-                     "Incorrect value for " + TreeSetCollections.fieldSpecs[i]);
+        for (int i = 0; i < n; ++i) {
+            Collection compareWith = expectedValue.get(i);
+            Collection val = pi.get(i);
+            if (val.size() != compareWith.size()) {
+                sbuf.append("\nFor element " + i + ", expected size = " +
+                        compareWith.size() + ", actual size = " + val.size()
+                        + " . ");
+                continue;
             }
+            if (! val.equals(compareWith)) {
+                sbuf.append("\nFor element " + i + ", expected = " +
+                        compareWith + ", actual = " + val + " . ");
+            }
+        }
+        if (sbuf.length() > 0) {
+            fail(ASSERTION_FAILED,
+                 "Expected and observed do not match!!" + sbuf.toString());
         }
     }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java Wed Sep 28 12:03:07 2005
@@ -18,7 +18,11 @@
 
 package org.apache.jdo.tck.models.fieldtypes;
 
-import java.util.Vector;
+import java.util.*;
+import java.math.*;
+
+import org.apache.jdo.tck.pc.fieldtypes.AllTypes;
+import org.apache.jdo.tck.pc.fieldtypes.SimpleClass;
 
 public class TestUtil {
 
@@ -65,7 +69,8 @@
       int indexOfUnderScore = fieldTypeWithValueType.indexOf("_");
       fieldType = fieldTypeWithValueType.substring(0, indexOfUnderScore);
 
-      String valueTypeWithNumber = fieldTypeWithValueType.substring(indexOfUnderScore + 1);
+      String valueTypeWithNumber =
+              fieldTypeWithValueType.substring(indexOfUnderScore + 1);
       int lastIndexOfValueType = 0;
       for (int i=valueTypeWithNumber.length() -1; i>=0; i--) {
         if (Character.isDigit(valueTypeWithNumber.charAt(i))) {
@@ -84,5 +89,235 @@
       return fieldSpecs;
   }
 
+  public static String [] elementTypes = new String[]
+            {"Object", "SimpleClass", "SimpleInterface",
+            "String", "Date", "Locale", "BigDecimal",
+            "BigInteger", "Byte", "Double", "Float",
+            "Integer", "Long", "Short"};
+
+  private static int getIndexOf(String type) {
+      for (int i=0; i < elementTypes.length; i++) {
+          if (type.equals(elementTypes[i]))
+              return i;
+      }
+      return 9999;
+  }
+
+  public static Vector makeNewVectorInstance(String type, int order) {
+
+      Vector vec = new Vector();
 
+      switch (order) {
+          case(1):
+              switch (getIndexOf(type)) {
+                  case(0):
+                      vec.add(0, new SimpleClass(1, "Hello World"));
+                      vec.add(1, new SimpleClass(2, "Java Data Objects"));
+                      vec.add(2, new SimpleClass(2, "Java"));
+                      vec.add(3, new SimpleClass(4, "Origami"));
+                      vec.add(4, new SimpleClass(5, "watch"));
+                      break;
+                  case(1):
+                  case(2):
+                      vec.add(0, new SimpleClass(1, "Welcome"));
+                      vec.add(1, new SimpleClass(2, "To"));
+                      vec.add(2, new SimpleClass(3, "The"));
+                      vec.add(3, new SimpleClass(4, "Beautiful"));
+                      vec.add(4, new SimpleClass(5, "World"));
+                      break;
+                  case(3):
+                      vec.add(0, new String("Hello"));
+                      vec.add(1, new String("Welcome"));
+                      vec.add(2, new String("To The"));
+                      vec.add(3, new String("Beautiful"));
+                      vec.add(4, new String("World"));
+                      break;
+                  case(4):
+                      vec.add(0, new Date(2007908));
+                      vec.add(1, new Date(89067382l));
+                      vec.add(2, new Date(890673822));
+                      vec.add(3, new Date(890673823));
+                      vec.add(4, new Date(890673824));
+                      break;
+                  case(5):
+                      vec.add(0, Locale.CHINA);
+                      vec.add(1, Locale.FRANCE);
+                      vec.add(2, Locale.GERMANY);
+                      vec.add(3, Locale.JAPAN);
+                      vec.add(4, Locale.ITALY);
+                      break;
+                  case(6):
+                      vec.add(0, new BigDecimal("2007908.54548"));
+                      vec.add(1, new BigDecimal("0.544"));
+                      vec.add(2, new BigDecimal("3002323232.545454"));
+                      vec.add(3, new BigDecimal("64564645656.78657"));
+                      vec.add(4, new BigDecimal("4564565465.2342"));
+                      break;
+                  case(7):
+                      vec.add(0, new BigInteger("2007908"));
+                      vec.add(1, new BigInteger("767575"));
+                      vec.add(2, new BigInteger("3002323232"));
+                      vec.add(3, new BigInteger("64564645656"));
+                      vec.add(4, new BigInteger("456445645"));
+                      break;
+                  case(8):
+                      vec.add(0, new Byte((byte)Byte.MIN_VALUE));
+                      vec.add(1, new Byte((byte)Byte.MAX_VALUE));
+                      vec.add(2, new Byte((byte)(Byte.MAX_VALUE- 20)));
+                      vec.add(3, new Byte((byte)(Byte.MAX_VALUE - 50)));
+                      vec.add(4, new Byte((byte)(Byte.MAX_VALUE - 75)));
+                      break;
+                  case(9):
+                      vec.add(0, new Double(AllTypes.DOUBLE_SMALLEST));
+                      vec.add(1, new Double(AllTypes.DOUBLE_LARGEST));
+                      vec.add(2, new Double(AllTypes.DOUBLE_LARGEST - 20000));
+                      vec.add(3, new Double(AllTypes.DOUBLE_LARGEST
+                                  - 454545.436664));
+                      vec.add(4, new Double(AllTypes.DOUBLE_LARGEST
+                                  - 2323235.76764677));
+                      break;
+                  case(10):
+                      vec.add(0, new Float(AllTypes.FLOAT_SMALLEST));
+                      vec.add(1, new Float(AllTypes.FLOAT_LARGEST));
+                      vec.add(2, new Float(AllTypes.FLOAT_LARGEST - 20000));
+                      vec.add(3, new Float(AllTypes.FLOAT_LARGEST
+                                  - 454545.434));
+                      vec.add(4, new Float(AllTypes.FLOAT_LARGEST
+                                  - 565656.43434));
+                      break;
+                  case(11):
+                      vec.add(0, new Integer(Integer.MIN_VALUE));
+                      vec.add(1, new Integer(Integer.MAX_VALUE));
+                      vec.add(2, new Integer(Integer.MAX_VALUE - 20000));
+                      vec.add(3, new Integer(Integer.MAX_VALUE - 343434343));
+                      vec.add(4, new Integer(Integer.MAX_VALUE - 565656));
+                      break;
+                  case(12):
+                      vec.add(0, new Long(Long.MIN_VALUE));
+                      vec.add(1, new Long(Long.MAX_VALUE));
+                      vec.add(2, new Long(Long.MAX_VALUE - 20000));
+                      vec.add(3, new Long(Long.MAX_VALUE - 343434343));
+                      vec.add(4, new Long(Long.MAX_VALUE - 565656));
+                      break;
+                  case(13):
+                      vec.add(0, new Short(Short.MIN_VALUE));
+                      vec.add(1, new Short(Short.MAX_VALUE));
+                      vec.add(2, new Short((short)(Short.MAX_VALUE - 20000)));
+                      vec.add(3, new Short((short)(Short.MAX_VALUE - 343)));
+                      vec.add(4, new Short((short)(Short.MAX_VALUE - 5656)));
+                      break;
+                 default:
+                      throw new IndexOutOfBoundsException();
+              }
+                  return vec;
+          case(2):
+              switch (getIndexOf(type)) {
+                  case(0):
+                    vec.add(0, new SimpleClass(1, "Hi There"));
+                    vec.add(1, new SimpleClass(1, "Hi"));
+                    vec.add(2, new SimpleClass(2, "Object"));
+                    vec.add(3, new SimpleClass(0, "Relational"));
+                    vec.add(4, new SimpleClass(3, "Hi There"));
+                    break;
+                  case(1):
+                    vec.add(0, new SimpleClass(1, "Peaches"));
+                    vec.add(1, new SimpleClass(2, "Oranges"));
+                    vec.add(2, new SimpleClass(3, "Blue Berries"));
+                    vec.add(3, new SimpleClass(4, "Apples"));
+                    vec.add(4, new SimpleClass(5, "Strawberries"));
+                    break;
+                  case(2):
+                    vec.add(0, new SimpleClass(1, "Peaches"));
+                    vec.add(1, new SimpleClass(2, "Oranges"));
+                    vec.add(2, new SimpleClass(3, "Blue Berries"));
+                    vec.add(3, new SimpleClass(4, "Apples"));
+                    vec.add(4, new SimpleClass(5, "Strawberries"));
+                    break;
+                  case(3):
+                    vec.add(0, new String("Peaches"));
+                    vec.add(1, new String("Oranges"));
+                    vec.add(2, new String("Blue Berries"));
+                    vec.add(3, new String("Apples"));
+                    vec.add(4, new String("Strawberries"));
+                    break;
+                  case(4):
+                    vec.add(0, new Date(54545));
+                    vec.add(1, new Date(8905454l));
+                    vec.add(2, new Date(323545445));
+                    vec.add(3, new Date(890748967382l));
+                    vec.add(4, new Date(954545));
+                    break;
+                  case(5):
+                    vec.add(0, Locale.ENGLISH);
+                    vec.add(1, Locale.JAPANESE);
+                    vec.add(2, Locale.CANADA_FRENCH);
+                    vec.add(3, Locale.KOREA);
+                    vec.add(4, Locale.UK);
+                    break;
+                  case(6):
+                    vec.add(0, new BigDecimal("434238.5454898989"));
+                    vec.add(1, new BigDecimal("6.544"));
+                    vec.add(2, new BigDecimal("55552323232.545454"));
+                    vec.add(3, new BigDecimal("6456456.7543543534865785"));
+                    vec.add(4, new BigDecimal("456456.4353452342"));
+                    break;
+                  case(7):
+                    vec.add(0, new BigInteger("345345345"));
+                    vec.add(1, new BigInteger("543543543543544"));
+                    vec.add(2, new BigInteger("65323423432423423"));
+                    vec.add(3, new BigInteger("87845634534543"));
+                    vec.add(4, new BigInteger("53452567766657567"));
+                    break;
+                  case(8):
+                    vec.add(0, new Byte((byte)(Byte.MAX_VALUE-34)));
+                    vec.add(1, new Byte((byte)Byte.MIN_VALUE));
+                    vec.add(2, new Byte((byte)(Byte.MAX_VALUE- 76)));
+                    vec.add(3, new Byte((byte)Byte.MAX_VALUE));
+                    vec.add(4, new Byte((byte)(Byte.MAX_VALUE - 12)));
+                    break;
+                  case(9):
+                    vec.add(0, new Double(AllTypes.DOUBLE_LARGEST - 343434));
+                    vec.add(1, new Double(AllTypes.DOUBLE_SMALLEST));
+                    vec.add(2, new Double(AllTypes.DOUBLE_LARGEST));
+                    vec.add(3, new Double(AllTypes.DOUBLE_LARGEST
+                                - 65423445.436664));
+                    vec.add(4, new Double(AllTypes.DOUBLE_LARGEST
+                                - 7235.236764677));
+                    break;
+                  case(10):
+                    vec.add(0, new Float(AllTypes.FLOAT_LARGEST - 5452));
+                    vec.add(1, new Float(AllTypes.FLOAT_SMALLEST));
+                    vec.add(2, new Float(AllTypes.FLOAT_LARGEST - 6564560.54));
+                    vec.add(3, new Float(AllTypes.FLOAT_LARGEST));
+                    vec.add(4, new Float(AllTypes.FLOAT_LARGEST - 9756.634));
+                    break;
+                  case(11):
+                    vec.add(0, new Integer(Integer.MAX_VALUE - 54454));
+                    vec.add(1, new Integer(Integer.MIN_VALUE));
+                    vec.add(2, new Integer(Integer.MAX_VALUE));
+                    vec.add(3, new Integer(Integer.MAX_VALUE - 767234));
+                    vec.add(4, new Integer(Integer.MAX_VALUE - 23673446));
+                    break;
+                  case(12):
+                    vec.add(0, new Long(Long.MAX_VALUE - 545345454));
+                    vec.add(1, new Long(Long.MIN_VALUE));
+                    vec.add(2, new Long(Long.MAX_VALUE));
+                    vec.add(3, new Long(Long.MAX_VALUE - 3543343));
+                    vec.add(4, new Long(Long.MAX_VALUE - 556));
+                    break;
+                  case(13):
+                    vec.add(0, new Short((short)(Short.MAX_VALUE - 3434)));
+                    vec.add(1, new Short(Short.MIN_VALUE));
+                    vec.add(2, new Short((short)(Short.MAX_VALUE)));
+                    vec.add(3, new Short((short)(Short.MAX_VALUE - 23344)));
+                    vec.add(4, new Short((short)(Short.MAX_VALUE - 723)));
+                    break;
+                 default:
+                    throw new IndexOutOfBoundsException();
+              }
+              return vec;
+          default:
+               throw new IndexOutOfBoundsException();
+          }
+      }
 }

Modified: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java?rev=292259&r1=292258&r2=292259&view=diff
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java (original)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java Wed Sep 28 12:03:07 2005
@@ -16,7 +16,7 @@
  
 package org.apache.jdo.tck.models.fieldtypes;
 
-import java.util.Hashtable;
+import java.util.Collection;
 import java.util.Vector;
 
 import javax.jdo.PersistenceManager;
@@ -77,17 +77,13 @@
     {
         if (!isVectorSupported()) {
             if (debug)
-                logger.debug("JDO Implementation does not support the optional feature Vector");
+                logger.debug("JDO Implementation does not support " +
+                        "the optional feature Vector");
             return;
         }
         
         Transaction tx = pm.currentTransaction();
-        try {
-        int i, n;
-        FirstSetOfTestValuesForCollection firstValue =
-            new FirstSetOfTestValuesForCollection();
-        SecondSetOfTestValuesForCollection secondValue =
-            new SecondSetOfTestValuesForCollection();
+        VectorCollections expectedValue = new VectorCollections();
 
         // turn on datastore transactions
         tx.setOptimistic(false);
@@ -96,61 +92,73 @@
         pi.identifier = 1;
         pm.makePersistent(pi);
         Object oid = pm.getObjectId(pi);
-        n = pi.getLength();
-// Provide initial set of values
-        for(i = 0; i < n; ++i){
-            String valueType = TestUtil.getFieldSpecs(VectorCollections.fieldSpecs[i]);
-            pi.set( i, (Vector)firstValue.get(valueType));
-        }
+        // Provide initial set of values
+        setValues(pi, 1);
         tx.commit();
-// cache will be flushed
+
+        // cache will be flushed
         pi = null;
         System.gc();
-
+        
         tx.begin();
-
-        checkValues(oid, firstValue); // check if persistent fields have values set
+        setValues(expectedValue, 1);
+        // check if persistent fields have values set
+        checkValues(oid, expectedValue);
         pi = (VectorCollections) pm.getObjectById(oid, true);
-
-// Provide new set of values
-        for( i = 0; i < n; ++i){
-            String valueType = TestUtil.getFieldSpecs(VectorCollections.fieldSpecs[i]);
-            pi.set( i, (Vector)secondValue.get(valueType));
-        }
+        // Provide new set of values
+        setValues(pi, 2);
         tx.commit();
-// cache will be flushed
+
+        // cache will be flushed
         pi = null;
         System.gc();
-
+        
         tx.begin();
-// check new values
-        checkValues(oid, secondValue);
-        pi = (VectorCollections) pm.getObjectById(oid, true);
-        pm.deletePersistent(pi);
+        // check new values
+        setValues(expectedValue, 2);
+        checkValues(oid, expectedValue);
         tx.commit();
-        tx = null;
-    }
-    finally {
-        if ((tx != null) && tx.isActive())
-            tx.rollback();
     }
+
+    /** */
+    private void setValues(VectorCollections collect, int order)
+    {
+        Vector value;
+        int n = collect.getLength();
+        for (int i = 0; i < n; ++i) {
+            String valueType = TestUtil.getFieldSpecs(
+                    VectorCollections.fieldSpecs[i]);
+            value = TestUtil.makeNewVectorInstance(valueType, order);
+            collect.set(i, value);
+            if (debug)
+                logger.debug("Set " + i + "th value to: " + value.toString());
+        }
     }
 
-    private void checkValues(Object oid, Hashtable startValue)
+    /** */
+    private void checkValues(Object oid, VectorCollections expectedValue)
     {
-        int i;
-        VectorCollections pi = (VectorCollections) pm.getObjectById(oid, true);
+        StringBuffer sbuf = new StringBuffer();
+        VectorCollections pi = (VectorCollections)
+                pm.getObjectById(oid, true);
         int n = pi.getLength();
-        for( i = 0; i < n; ++i){
-            String valueType = TestUtil.getFieldSpecs(VectorCollections.fieldSpecs[i]);
-            Vector compareWith = (Vector)startValue.get(valueType);
-
-            Vector val = pi.get(i);
-
-            if(!val.equals(compareWith)){
-                fail(ASSERTION_FAILED,
-                     "Incorrect value for " + VectorCollections.fieldSpecs[i]);
+        for (int i = 0; i < n; ++i) {
+            Collection compareWith = expectedValue.get(i);
+            Collection val = pi.get(i);
+            if (val.size() != compareWith.size()) {
+                sbuf.append("\nFor element " + i + ", expected size = " +
+                        compareWith.size() + ", actual size = " + val.size()
+                        + " . ");
+                continue;
             }
+            if (! val.equals(compareWith)) {
+                sbuf.append("\nFor element " + i + ", expected = " +
+                        compareWith + ", actual = " + val + " . ");
+            }
+        }
+        if (sbuf.length() > 0) {
+            fail(ASSERTION_FAILED,
+                 "Expected and observed do not match!!" + sbuf.toString());
         }
     }
 }



Mime
View raw message