You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mc...@apache.org on 2005/04/04 21:43:48 UTC
svn commit: r160090 [16/63] - in incubator/jdo/trunk: ./ tck20/
tck20/assertions/ tck20/iut_jars/ tck20/test/ tck20/test/conf/
tck20/test/java/ tck20/test/java/org/ tck20/test/java/org/apache/
tck20/test/java/org/apache/jdo/ tck20/test/java/org/apache/jdo/tck/
tck20/test/java/org/apache/jdo/tck/api/
tck20/test/java/org/apache/jdo/tck/api/instancecallbacks/
tck20/test/java/org/apache/jdo/tck/api/jdohelper/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/cache/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/close/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/extent/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/flags/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/getobject/
tck20/test/java/org/apache/jdo/tck/api/persistencemanager/lifecycle/
tck20/test/java/org/apache/jdo/tck/api/persistencemanagerfactory/
tck20/test/java/org/apache/jdo/tck/enhancement/
tck20/test/java/org/apache/jdo/tck/extents/
tck20/test/java/org/apache/jdo/tck/lifecycle/
tck20/test/java/org/apache/jdo/tck/lifecycle/nontransactional/
tck20/test/java/org/apache/jdo/tck/models/
tck20/test/java/org/apache/jdo/tck/models/embedded/
tck20/test/java/org/apache/jdo/tck/models/fieldtypes/
tck20/test/java/org/apache/jdo/tck/models/inheritance/
tck20/test/java/org/apache/jdo/tck/pc/
tck20/test/java/org/apache/jdo/tck/pc/company/
tck20/test/java/org/apache/jdo/tck/pc/fieldtypes/
tck20/test/java/org/apache/jdo/tck/pc/inheritance/
tck20/test/java/org/apache/jdo/tck/pc/instancecallbacks/
tck20/test/java/org/apache/jdo/tck/pc/lifecycle/
tck20/test/java/org/apache/jdo/tck/pc/mylib/
tck20/test/java/org/apache/jdo/tck/query/
tck20/test/java/org/apache/jdo/tck/query/operators/
tck20/test/java/org/apache/jdo/tck/transactions/
tck20/test/java/org/apache/jdo/tck/util/ tck20/test/jdo/
tck20/test/jdo/applicationidentity/ tck20/test/jdo/applicationidentity/org/
tck20/test/jdo/applicationidentity/org/apache/
tck20/test/jdo/applicationidentity/org/apache/jdo/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/
tck20/test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/
tck20/test/jdo/datastoreidentity/ tck20/test/jdo/datastoreidentity/org/
tck20/test/jdo/datastoreidentity/org/apache/
tck20/test/jdo/datastoreidentity/org/apache/jdo/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/
tck20/test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/
tck20/test/orm/ tck20/test/orm/applicationidentity/
tck20/test/orm/applicationidentity/org/
tck20/test/orm/applicationidentity/org/apache/
tck20/test/orm/applicationidentity/org/apache/jdo/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/company/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/inheritance/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/lifecycle/
tck20/test/orm/applicationidentity/org/apache/jdo/tck/pc/mylib/
tck20/test/orm/datastoreidentity/ tck20/test/orm/datastoreidentity/org/
tck20/test/orm/datastoreidentity/org/apache/
tck20/test/orm/datastoreidentity/org/apache/jdo/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/company/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/inheritance/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/
tck20/test/orm/datastoreidentity/org/apache/jdo/tck/pc/mylib/
tck20/test/sql/ tck20/test/sql/derby/
Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringKeyCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringKeyCollections.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringKeyCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringKeyCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,191 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.HashtableStringKeyCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Hashtable, varying value type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-25.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the Hashtable optional feature is supported, then JDO implementation must
+support fields of the mutable object class <code>Hashtable</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestHashtableStringKeyCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-25 (TestHashtableStringKeyCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestHashtableStringKeyCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ if (!isHashtableSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature Hashtable");
+ 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();
+ HashtableStringKeyCollections pi = new HashtableStringKeyCollections();
+ 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(HashtableStringKeyCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ Hashtable map = new Hashtable();
+ 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 = (HashtableStringKeyCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values -- reverse the keys and values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(HashtableStringKeyCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ Hashtable map = new Hashtable();
+ 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);
+ }
+
+ 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 = (HashtableStringKeyCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue){
+ int i, j;
+
+ HashtableStringKeyCollections pi = (HashtableStringKeyCollections) 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(HashtableStringKeyCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ Hashtable compareWith = new Hashtable();
+
+ 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));
+ }
+
+ Hashtable val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + HashtableStringKeyCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringKeyCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringValueCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringValueCollections.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringValueCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringValueCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,191 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.HashtableStringValueCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Hashtable, varying key type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-25.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the Hashtable optional feature is supported, then JDO implementation must
+support fields of the mutable object class <code>Hashtable</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestHashtableStringValueCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-25 (TestHashtableStringValueCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestHashtableStringValueCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isHashtableSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature Hashtable");
+ 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();
+ HashtableStringValueCollections pi = new HashtableStringValueCollections();
+ 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(HashtableStringValueCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ Hashtable map = new Hashtable();
+ 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 = (HashtableStringValueCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values -- reverse the keys and values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(HashtableStringValueCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ Hashtable map = new Hashtable();
+ 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);
+ }
+
+ 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 = (HashtableStringValueCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i, j;
+
+ HashtableStringValueCollections pi = (HashtableStringValueCollections) 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(HashtableStringValueCollections.fieldSpecs[i]);
+ String fieldType = (String)fieldSpecs.get(0);
+ String valueType = (String)fieldSpecs.get(1);
+ Hashtable compareWith = new Hashtable();
+
+ 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));
+ }
+
+ Hashtable val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + HashtableStringValueCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestHashtableStringValueCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestLinkedListCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestLinkedListCollections.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestLinkedListCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestLinkedListCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,152 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.LinkedList;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.LinkedListCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type LinkedList
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-26.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the LinkedList optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>LinkedList</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestLinkedListCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-26 (TestLinkedListCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestLinkedListCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ if (!isLinkedListSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature LinkedList");
+ 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();
+ LinkedListCollections pi = new LinkedListCollections();
+ 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(LinkedListCollections.fieldSpecs[i]);
+ pi.set( i, new LinkedList((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 = (LinkedListCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(LinkedListCollections.fieldSpecs[i]);
+ pi.set( i, new LinkedList((Collection)secondValue.get(valueType)));
+ }
+ tx.commit();
+ // cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+ // check new values
+ checkValues(oid, secondValue);
+ pi = (LinkedListCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+
+ LinkedListCollections pi = (LinkedListCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(LinkedListCollections.fieldSpecs[i]);
+ LinkedList compareWith = new LinkedList((Collection)startValue.get(valueType));
+
+ LinkedList val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + LinkedListCollections.fieldSpecs[i]);
+ }
+ }
+ }
+
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestLinkedListCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestListCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestListCollections.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestListCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestListCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,158 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.ListCollections;
+import org.apache.jdo.tck.transactions.Commit;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type List
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-36.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the List optional feature is supported, then JDO implementations must
+support fields of the interface type <code>List</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestListCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-36 (Commit) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(Commit.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isListSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature List");
+ return;
+ }
+
+ if (!isLinkedListSupported() && !isArrayListSupported()) {
+ fail(ASSERTION_FAILED,
+ "JDO Implementation supports List, but neither ArrayList nor LinkedList.");
+ }
+
+ 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();
+ ListCollections pi = new ListCollections();
+ 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(ListCollections.fieldSpecs[i]);
+ pi.set( i, new LinkedList((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 = (ListCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(ListCollections.fieldSpecs[i]);
+ pi.set( i, new LinkedList((Collection)secondValue.get(valueType)));
+ }
+ tx.commit();
+ // cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+ // check new values
+ checkValues(oid, secondValue);
+ pi = (ListCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+
+ ListCollections pi = (ListCollections) pm.getObjectById(oid, true);
+ int n = pi.getLength();
+ for( i = 0; i < n; ++i){
+ String valueType = TestUtil.getFieldSpecs(ListCollections.fieldSpecs[i]);
+ List compareWith = new LinkedList((Collection)startValue.get(valueType));
+
+ List val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + ListCollections.fieldSpecs[i]);
+ }
+ }
+ }
+
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestListCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringKeyCollections.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringKeyCollections.java?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringKeyCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringKeyCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,196 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.MapStringKeyCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Map, varying value type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-35.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the Map optional feature is supported, then JDO implementations
+must support fields of the interface type <code>Map</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+public class TestMapStringKeyCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-35 (TestMapStringKeyCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestMapStringKeyCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isMapSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature Map");
+ return;
+ }
+ if (!isHashMapSupported() && !isTreeMapSupported()) {
+ fail(ASSERTION_FAILED,
+ "JDO Implementation supports Map, but neither HashMap nor TreeMap.");
+ }
+
+ 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();
+ MapStringKeyCollections pi = new MapStringKeyCollections();
+ 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(MapStringKeyCollections.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));
+ }
+
+ 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 = (MapStringKeyCollections) pm.getObjectById(oid, true);
+
+ // Provide new set of values -- reverse the keys and values
+ for(i = 0; i < n; ++i){
+ Vector fieldSpecs = TestUtil.getFieldSpecsForMap(MapStringKeyCollections.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);
+ }
+
+ 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 = (MapStringKeyCollections) pm.getObjectById(oid, true);
+ pm.deletePersistent(pi);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i, j;
+
+ MapStringKeyCollections pi = (MapStringKeyCollections) 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(MapStringKeyCollections.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));
+ }
+
+ Map val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + MapStringKeyCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringKeyCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,202 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.MapStringValueCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Map, varying key type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-35.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the Map optional feature is supported, then JDO implementations
+must support fields of the interface type <code>Map</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestMapStringValueCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-35 (TestMapStringValueCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestMapStringValueCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isMapSupported()) {
+ if (debug)
+ logger.debug("JDO Implementation does not support the optional feature Map");
+ return;
+ }
+ if (!isHashMapSupported() && !isTreeMapSupported()) {
+ fail(ASSERTION_FAILED,
+ "JDO Implementation supports Map, but neither HashMap 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));
+ }
+
+ 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(
+ 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);
+ }
+
+ 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;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i, j;
+
+ 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));
+ }
+
+ Map val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + MapStringValueCollections.fieldSpecs[i]);
+ }
+ }
+ }
+
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestMapStringValueCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,143 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.SetCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Set.
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-34.
+ *<BR>
+ *<B>Assertion Description: </B>
+JDO implementations must support fields of the interface type
+<code>java.util.Set</code>, and may choose to support them
+as Second Class Objects or First Class Objects.
+ */
+
+public class TestSetCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-34 (TestSetCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestSetCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ 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();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+
+ 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]);
+ }
+ }
+ }
+
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestSetCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,191 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.TreeMapStringKeyCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type TreeMap, varying value type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-27.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the TreeMap optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>TreeMap</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestTreeMapStringKeyCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-27 (TestTreeMapStringKeyCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestTreeMapStringKeyCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isTreeMapSupported()) {
+ if (debug)
+ 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));
+ }
+
+ pi.set(i, map);
+ }
+
+ 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();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue){
+ int i, j;
+
+ 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));
+ }
+
+ TreeMap val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + TreeMapStringKeyCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringKeyCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,191 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.TreeMapStringValueCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type TreeMap, varying key type
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-27.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the TreeMap optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>TreeMap</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+public class TestTreeMapStringValueCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-27 (TestTreeMapStringValueCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestTreeMapStringValueCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isTreeMapSupported()) {
+ if (debug)
+ 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));
+ }
+
+ pi.set(i, map);
+ }
+
+ 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();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i, j;
+
+ 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));
+ }
+
+ TreeMap val = pi.get(i);
+
+ if(!val.equals(compareWith)){
+ fail(ASSERTION_FAILED,
+ "Incorrect value for " + TreeMapStringValueCollections.fieldSpecs[i]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeMapStringValueCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,157 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.TreeSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.TreeSetCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type TreeSet.
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-28.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the TreeSet optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>TreeSet</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestTreeSetCollections extends JDO_Test {
+ private PersistenceManager pm;
+ private Transaction tx;
+ private static String prefix = "TestTreeSetCollections: ";
+ private TreeSet defaultValue; // do not initialize, should be 0 for int
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-28 (TestTreeSetCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestTreeSetCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm) {
+ if (!isTreeSetSupported()) {
+ if (debug)
+ 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.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();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+
+ 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]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestTreeSetCollections.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,88 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Vector;
+
+public class TestUtil {
+
+ public TestUtil() {
+ }
+
+ //gets the value type for fields of a collection class
+ public static String getFieldSpecs(String field) {
+ //sample field =public Collection CollectionOfObject0
+ //look for last space and get the String before the numbers
+ String valueType = "";
+
+ int indexOfLastSpace = field.lastIndexOf(" ");
+ String fieldName = field.substring(indexOfLastSpace);
+ int indexOfValueType = fieldName.indexOf("Of") + 2;
+ String valueTypeWithNumber = fieldName.substring(indexOfValueType);
+ int lastIndexOfValueType = 0;
+ for (int i=valueTypeWithNumber.length() -1; i>=0; i--) {
+ if (Character.isDigit(valueTypeWithNumber.charAt(i))) {
+ continue;
+ } else {
+ lastIndexOfValueType = i;
+ break;
+ }
+ }
+ valueType = valueTypeWithNumber.substring(0, lastIndexOfValueType+1);
+
+ return valueType;
+ }
+
+
+ //gets the key type and value type for fields of a Map class
+ public static Vector getFieldSpecsForMap(String field) {
+ //sample field =public HashMap HashMapOfObject_Object0
+ //fieldType -- look for the last space and get the value between Of and _
+ //valueType -- look for last _ and get the String before the numbers
+ String fieldType = "";
+ String valueType = "";
+
+ int indexOfLastSpace = field.lastIndexOf(" ");
+ String fieldName = field.substring(indexOfLastSpace);
+ int indexOfFieldType = fieldName.indexOf("Of") + 2;
+ String fieldTypeWithValueType = fieldName.substring(indexOfFieldType);
+ int indexOfUnderScore = fieldTypeWithValueType.indexOf("_");
+ fieldType = fieldTypeWithValueType.substring(0, indexOfUnderScore);
+
+ String valueTypeWithNumber = fieldTypeWithValueType.substring(indexOfUnderScore + 1);
+ int lastIndexOfValueType = 0;
+ for (int i=valueTypeWithNumber.length() -1; i>=0; i--) {
+ if (Character.isDigit(valueTypeWithNumber.charAt(i))) {
+ continue;
+ } else {
+ lastIndexOfValueType = i;
+ break;
+ }
+ }
+ valueType = valueTypeWithNumber.substring(0, lastIndexOfValueType+1);
+
+ Vector fieldSpecs = new Vector();
+ fieldSpecs.add(fieldType);
+ fieldSpecs.add(valueType);
+
+ return fieldSpecs;
+ }
+
+
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestUtil.java
------------------------------------------------------------------------------
svn:executable = *
Added: 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?view=auto&rev=160090
==============================================================================
--- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java (added)
+++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java Mon Apr 4 12:41:23 2005
@@ -0,0 +1,149 @@
+/*
+ * 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.models.fieldtypes;
+
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.pc.fieldtypes.VectorCollections;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ *<B>Title:</B> Support of field type Vector.
+ *<BR>
+ *<B>Keywords:</B> model
+ *<BR>
+ *<B>Assertion ID:</B> A6.4.3-29.
+ *<BR>
+ *<B>Assertion Description: </B>
+If the Vector optional feature is supported, then JDO implementation
+must support fields of the mutable object class <code>Vector</code>,
+supporting them as Second Class Objects or First Class Objects.
+ */
+
+
+public class TestVectorCollections extends JDO_Test {
+
+ /** */
+ private static final String ASSERTION_FAILED =
+ "Assertion A6.4.3-29 (TestVectorCollections) failed: ";
+
+ /**
+ * The <code>main</code> is called when the class
+ * is directly executed from the command line.
+ * @param args The arguments passed to the program.
+ */
+ public static void main(String[] args) {
+ BatchTestRunner.run(TestVectorCollections.class);
+ }
+
+ /** */
+ public void test() {
+ pm = getPM();
+
+ runTest(pm);
+
+ pm.close();
+ pm = null;
+ }
+
+ /** */
+ void runTest(PersistenceManager pm)
+ {
+ if (!isVectorSupported()) {
+ if (debug)
+ 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();
+
+ // turn on datastore transactions
+ tx.setOptimistic(false);
+ tx.begin();
+ VectorCollections pi = new VectorCollections();
+ 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));
+ }
+ tx.commit();
+// cache will be flushed
+ pi = null;
+ System.gc();
+
+ tx.begin();
+
+ checkValues(oid, firstValue); // check if persistent fields have values set
+ 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));
+ }
+ tx.commit();
+// 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);
+ tx.commit();
+ tx = null;
+ }
+ finally {
+ if ((tx != null) && tx.isActive())
+ tx.rollback();
+ }
+ }
+
+ private void checkValues(Object oid, Hashtable startValue)
+ {
+ int i;
+ 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]);
+ }
+ }
+ }
+}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestVectorCollections.java
------------------------------------------------------------------------------
svn:executable = *