Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/embedded/SecondClassObjectsTrackTheirChanges.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/embedded/SecondClassObjectsTrackTheirChanges.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/embedded/SecondClassObjectsTrackTheirChanges.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/embedded/SecondClassObjectsTrackTheirChanges.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,135 @@ +/* + * 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.embedded; + +import javax.jdo.PersistenceManager; +import java.util.Date; +import java.util.Set; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; +import org.apache.jdo.tck.pc.company.Company; +import org.apache.jdo.tck.pc.company.Address; +import org.apache.jdo.tck.pc.company.Department; + +/** + *<B>Title:</B> Embedded Objects Track Their Changes + *<BR> + *<B>Keywords:</B> embedded lifecycle + *<BR> + *<B>Assertion ID:</B> A6.3-1. + *<BR> + *<B>Assertion Description: </B> +Second Class Objects track changes made to themselves and notify their owning +First Class Object that they have changed, and the change is reflected as a +change to that First Class Object (e.g. the owning instance changes state from +persistent-clean to persistent-dirty). + + */ + +public class SecondClassObjectsTrackTheirChanges extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.3-1 (SecondClassObjectsTrackTheirChanges) 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(SecondClassObjectsTrackTheirChanges.class); + } + + /** This tests that persistence-capable instances track changes or notify their owning instance that they are dirty */ + public void testPCInstance() { + pm = getPM(); + pm.currentTransaction().begin(); + Company comp = getPersistentNewInstance(0); + pm.currentTransaction().commit(); // obj should transition to hollow + testHollowInstance(comp); + pm.currentTransaction().begin(); + makePersistentCleanInstance(comp); + + Address addr = comp.getAddress(); + addr.setStreet("200 Orange Street"); // comp or addr should transition to persistent-dirty + int currComp = currentState(comp); + int currAddr = currentState(addr); + if ((currComp != PERSISTENT_DIRTY) && (currAddr != PERSISTENT_DIRTY)){ + fail(ASSERTION_FAILED, + "Unable to create persistent-dirty instance " + + "from persistent-clean instance via changing Address instance, state of Company instance is " + states[currComp] + " and state of Address instance is " + states[currAddr]); + } + } + + /** This tests that mutable system class instances track changes or notify their owning instance that they are dirty */ + public void testMutableSystemClass() { + pm = getPM(); + pm.currentTransaction().begin(); + Company comp = getPersistentNewInstance(1); + pm.currentTransaction().commit(); // obj should transition to hollow + testHollowInstance(comp); + pm.currentTransaction().begin(); + makePersistentCleanInstance(comp); + + Set depts = comp.getDepartments(); + comp.addDepartment(new Department(0,"HR",comp)); // comp or depts should transition to persistent-dirty + int currComp = currentState(comp); + int currDepts = currentState(depts); + if ((currComp != PERSISTENT_DIRTY) && (currDepts != PERSISTENT_DIRTY)){ + fail(ASSERTION_FAILED, + "Unable to create persistent-dirty instance " + + "from persistent-clean instance via changing Departments instance, state of Company instance is " + states[currComp] + " and state of Departments instance is " + states[currDepts]); + } + } + + public Company getPersistentNewInstance(long companyid) + { + Company obj = new Company(companyid, "MyCompany", new Date(), new Address(0,"","","","","")); + pm.makePersistent(obj); // obj should transition to persistent-new + int curr = currentState(obj); + if( curr != PERSISTENT_NEW ){ + fail(ASSERTION_FAILED, + "Unable to create persistent-new instance " + + "from transient instance via makePersistent(), state is " + states[curr]); + } + return obj; + } + + public void testHollowInstance(Company obj) + { + int curr = currentState(obj); + if( curr != HOLLOW ){ + fail(ASSERTION_FAILED, + "Unable to create hollow instance " + + "from persistent-new instance via commit(), state is " + states[curr]); + } + } + + public void makePersistentCleanInstance(Company obj) + { + pm.makeTransactional(obj); // obj should transition to persistent-clean + int curr = currentState(obj); + if( curr != PERSISTENT_CLEAN ){ + fail(ASSERTION_FAILED, + "Unable to create persistent-clean instance " + + "from hollow instance via makeTransactional(obj), state is " + states[curr]); + } + } +}
Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/embedded/SecondClassObjectsTrackTheirChanges.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/FirstSetOfTestValuesForCollection.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/FirstSetOfTestValuesForCollection.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/FirstSetOfTestValuesForCollection.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/FirstSetOfTestValuesForCollection.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,141 @@ +/* + * 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.*; +import java.math.*; + +import org.apache.jdo.tck.pc.fieldtypes.SimpleClass; + +public class FirstSetOfTestValuesForCollection extends Hashtable { + + public FirstSetOfTestValuesForCollection() { + String [] elementTypes = {"Object", "SimpleClass", "SimpleInterface", + "String", "Date", "Locale", "BigDecimal", + "BigInteger", "Byte", "Double", "Float", + "Integer", "Long", "Short"}; + + Vector objectVector = new Vector(); + objectVector.add(0, new SimpleClass(1, "Hello World")); + objectVector.add(1, new SimpleClass(2, "Java Data Objects")); + objectVector.add(2, new SimpleClass(2, "Java")); + objectVector.add(3, new SimpleClass(4, "Origami")); + objectVector.add(4, new SimpleClass(5, "watch")); + put("Object", objectVector); + + Vector simpleClassVector = new Vector(); + simpleClassVector.add(0, new SimpleClass(1, "Welcome")); + simpleClassVector.add(1, new SimpleClass(2, "To")); + simpleClassVector.add(2, new SimpleClass(3, "The")); + simpleClassVector.add(3, new SimpleClass(4, "Beautiful")); + simpleClassVector.add(4, new SimpleClass(5, "World")); + put("SimpleClass", simpleClassVector); + put("SimpleInterface", simpleClassVector); + + + Vector stringVector = new Vector(); + stringVector.add(0, new String("Hello")); + stringVector.add(1, new String("Welcome")); + stringVector.add(2, new String("To The")); + stringVector.add(3, new String("Beautiful")); + stringVector.add(4, new String("World")); + put("String", stringVector); + + Vector dateVector = new Vector(); + dateVector.add(0, new Date(2007908)); + dateVector.add(1, new Date(89067382l)); + dateVector.add(2, new Date(890673822)); + dateVector.add(3, new Date(890673823)); + dateVector.add(4, new Date(890673824)); + put("Date", dateVector); + + Vector localeVector = new Vector(); + localeVector.add(0, Locale.CHINA); + localeVector.add(1, Locale.FRANCE); + localeVector.add(2, Locale.GERMANY); + localeVector.add(3, Locale.JAPAN); + localeVector.add(4, Locale.ITALY); + put("Locale", localeVector); + + + Vector bigDecVector = new Vector(); + bigDecVector.add(0, new BigDecimal("2007908.54548")); + bigDecVector.add(1, new BigDecimal("0.544")); + bigDecVector.add(2, new BigDecimal("3002323232.545454")); + bigDecVector.add(3, new BigDecimal("64564645656.78657")); + bigDecVector.add(4, new BigDecimal("4564565465.2342")); + put("BigDecimal", bigDecVector); + + Vector bigIntVector = new Vector(); + bigIntVector.add(0, new BigInteger("2007908")); + bigIntVector.add(1, new BigInteger("767575")); + bigIntVector.add(2, new BigInteger("3002323232")); + bigIntVector.add(3, new BigInteger("64564645656")); + bigIntVector.add(4, new BigInteger("456445645")); + put("BigInteger", bigIntVector); + + Vector byteVector = new Vector(); + byteVector.add(0, new Byte((byte)Byte.MIN_VALUE)); + byteVector.add(1, new Byte((byte)Byte.MAX_VALUE)); + byteVector.add(2, new Byte((byte)(Byte.MAX_VALUE- 20))); + byteVector.add(3, new Byte((byte)(Byte.MAX_VALUE - 50))); + byteVector.add(4, new Byte((byte)(Byte.MAX_VALUE - 75))); + put("Byte", byteVector); + + Vector doubleVector = new Vector(); + doubleVector.add(0, new Double(Double.MIN_VALUE)); + doubleVector.add(1, new Double(Double.MAX_VALUE)); + doubleVector.add(2, new Double(Double.MAX_VALUE - 20000)); + doubleVector.add(3, new Double(Double.MAX_VALUE - 454545.436664)); + doubleVector.add(4, new Double(Double.MAX_VALUE - 2323235.76764677)); + put("Double", doubleVector); + + Vector floatVector = new Vector(); + floatVector.add(0, new Float(Float.MIN_VALUE)); + floatVector.add(1, new Float(Float.MAX_VALUE)); + floatVector.add(2, new Float(Float.MAX_VALUE - 20000)); + floatVector.add(3, new Float(Float.MAX_VALUE - 454545.434)); + floatVector.add(4, new Float(Float.MAX_VALUE - 565656.43434)); + put("Float", floatVector); + + Vector integerVector = new Vector(); + integerVector.add(0, new Integer(Integer.MIN_VALUE)); + integerVector.add(1, new Integer(Integer.MAX_VALUE)); + integerVector.add(2, new Integer(Integer.MAX_VALUE - 20000)); + integerVector.add(3, new Integer(Integer.MAX_VALUE - 343434343)); + integerVector.add(4, new Integer(Integer.MAX_VALUE - 565656)); + put("Integer", integerVector); + + + Vector longVector = new Vector(); + longVector.add(0, new Long(Long.MIN_VALUE)); + longVector.add(1, new Long(Long.MAX_VALUE)); + longVector.add(2, new Long(Long.MAX_VALUE - 20000)); + longVector.add(3, new Long(Long.MAX_VALUE - 343434343)); + longVector.add(4, new Long(Long.MAX_VALUE - 565656)); + put("Long", longVector); + + Vector shortVector = new Vector(); + shortVector.add(0, new Short(Short.MIN_VALUE)); + shortVector.add(1, new Short(Short.MAX_VALUE)); + shortVector.add(2, new Short((short)(Short.MAX_VALUE - 20000))); + shortVector.add(3, new Short((short)(Short.MAX_VALUE - 343))); + shortVector.add(4, new Short((short)(Short.MAX_VALUE - 5656))); + put("Short", shortVector); + } + +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/FirstSetOfTestValuesForCollection.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/SecondSetOfTestValuesForCollection.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/SecondSetOfTestValuesForCollection.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/SecondSetOfTestValuesForCollection.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/SecondSetOfTestValuesForCollection.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,141 @@ +/* + * 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.*; +import java.math.*; + +import org.apache.jdo.tck.pc.fieldtypes.SimpleClass; + +public class SecondSetOfTestValuesForCollection extends Hashtable { + + public SecondSetOfTestValuesForCollection() { + String [] elementTypes = {"Object", "SimpleClass", "SimpleInterface", + "String", "Date", "Locale", "BigDecimal", + "BigInteger", "Byte", "Double", "Float", + "Integer", "Long", "Short"}; + + Vector objectVector = new Vector(); + objectVector.add(0, new SimpleClass(1, "Hi There")); + objectVector.add(1, new SimpleClass(1, "Hi")); + objectVector.add(2, new SimpleClass(2, "Object")); + objectVector.add(3, new SimpleClass(0, "Relational")); + objectVector.add(4, new SimpleClass(3, "Hi There")); + put("Object", objectVector); + + Vector simpleClassVector = new Vector(); + simpleClassVector.add(0, new SimpleClass(1, "Peaches")); + simpleClassVector.add(1, new SimpleClass(2, "Oranges")); + simpleClassVector.add(2, new SimpleClass(3, "Blue Berries")); + simpleClassVector.add(3, new SimpleClass(4, "Apples")); + simpleClassVector.add(4, new SimpleClass(5, "Strawberries")); + put("SimpleClass", simpleClassVector); + put("SimpleInterface", simpleClassVector); + + + Vector stringVector = new Vector(); + stringVector.add(0, new String("Peaches")); + stringVector.add(1, new String("Oranges")); + stringVector.add(2, new String("Blue Berries")); + stringVector.add(3, new String("Apples")); + stringVector.add(4, new String("Strawberries")); + put("String", stringVector); + + Vector dateVector = new Vector(); + dateVector.add(0, new Date(54545)); + dateVector.add(1, new Date(8905454l)); + dateVector.add(2, new Date(323545445)); + dateVector.add(3, new Date(890748967382l)); + dateVector.add(4, new Date(954545)); + put("Date", dateVector); + + Vector localeVector = new Vector(); + localeVector.add(0, Locale.ENGLISH); + localeVector.add(1, Locale.JAPANESE); + localeVector.add(2, Locale.CANADA_FRENCH); + localeVector.add(3, Locale.KOREA); + localeVector.add(4, Locale.UK); + put("Locale", localeVector); + + + Vector bigDecVector = new Vector(); + bigDecVector.add(0, new BigDecimal("434238.5454898989")); +// bigDecVector.add(1, new BigDecimal("8348967382l.544")); + bigDecVector.add(1, new BigDecimal("6.544")); + bigDecVector.add(2, new BigDecimal("55552323232.545454")); + bigDecVector.add(3, new BigDecimal("6456456.7543543534865785")); + bigDecVector.add(4, new BigDecimal("456456.4353452342")); + put("BigDecimal", bigDecVector); + + Vector bigIntVector = new Vector(); + bigIntVector.add(0, new BigInteger("345345345")); + bigIntVector.add(1, new BigInteger("543543543543544")); + bigIntVector.add(2, new BigInteger("65323423432423423")); + bigIntVector.add(3, new BigInteger("87845634534543")); + bigIntVector.add(4, new BigInteger("53452567766657567")); + put("BigInteger", bigIntVector); + + Vector byteVector = new Vector(); + byteVector.add(0, new Byte((byte)(Byte.MAX_VALUE-34))); + byteVector.add(1, new Byte((byte)Byte.MIN_VALUE)); + byteVector.add(2, new Byte((byte)(Byte.MAX_VALUE- 76))); + byteVector.add(3, new Byte((byte)Byte.MAX_VALUE)); + byteVector.add(4, new Byte((byte)(Byte.MAX_VALUE - 12))); + put("Byte", byteVector); + + Vector doubleVector = new Vector(); + doubleVector.add(0, new Double(Double.MAX_VALUE - 343434)); + doubleVector.add(1, new Double(Double.MIN_VALUE)); + doubleVector.add(2, new Double(Double.MAX_VALUE)); + doubleVector.add(3, new Double(Double.MAX_VALUE - 65423445.436664)); + doubleVector.add(4, new Double(Double.MAX_VALUE - 7235.236764677)); + put("Double", doubleVector); + + Vector floatVector = new Vector(); + floatVector.add(0, new Float(Float.MAX_VALUE - 5452)); + floatVector.add(1, new Float(Float.MIN_VALUE)); + floatVector.add(2, new Float(Float.MAX_VALUE - 6564560.54)); + floatVector.add(3, new Float(Float.MAX_VALUE)); + floatVector.add(4, new Float(Float.MAX_VALUE - 9756.634)); + put("Float", floatVector); + + Vector integerVector = new Vector(); + integerVector.add(0, new Integer(Integer.MAX_VALUE - 54454)); + integerVector.add(1, new Integer(Integer.MIN_VALUE)); + integerVector.add(2, new Integer(Integer.MAX_VALUE)); + integerVector.add(3, new Integer(Integer.MAX_VALUE - 767234)); + integerVector.add(4, new Integer(Integer.MAX_VALUE - 23673446)); + put("Integer", integerVector); + + + Vector longVector = new Vector(); + longVector.add(0, new Long(Long.MAX_VALUE - 545345454)); + longVector.add(1, new Long(Long.MIN_VALUE)); + longVector.add(2, new Long(Long.MAX_VALUE)); + longVector.add(3, new Long(Long.MAX_VALUE - 3543343)); + longVector.add(4, new Long(Long.MAX_VALUE - 556)); + put("Long", longVector); + + Vector shortVector = new Vector(); + shortVector.add(0, new Short((short)(Short.MAX_VALUE - 3434))); + shortVector.add(1, new Short(Short.MIN_VALUE)); + shortVector.add(2, new Short((short)(Short.MAX_VALUE))); + shortVector.add(3, new Short((short)(Short.MAX_VALUE - 23344))); + shortVector.add(4, new Short((short)(Short.MAX_VALUE - 723))); + put("Short", shortVector); + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/SecondSetOfTestValuesForCollection.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayCollections.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayCollections.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayCollections.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayCollections.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,174 @@ +/* + * 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.Arrays; +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.ArrayCollections; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type array. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-39. + *<BR> + *<B>Assertion Description: </B> +JDO implementations may optionally support fields of array types. + */ + +public class TestArrayCollections extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion (TestArrayCollections) 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(TestArrayCollections.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + if (!isArraySupported()) { + if (debug) + logger.debug("JDO Implementation does not support optional feature Array"); + return; + } + + Transaction tx = pm.currentTransaction(); + try { + int i, n; + FirstSetOfTestValuesForCollection firstSetOfValues = + new FirstSetOfTestValuesForCollection(); + SecondSetOfTestValuesForCollection secondSetOfValues = + new SecondSetOfTestValuesForCollection(); + + // turn on datastore transactions + tx.setOptimistic(false); + tx.begin(); + ArrayCollections pi = new ArrayCollections(); + 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( + ArrayCollections.fieldSpecs[i]); + //create an array of initial values for each value type + Object[] firstValueArray = null; + Vector firstValueVector = (Vector)firstSetOfValues.get(valueType); + firstValueArray = (Object[])java.lang.reflect.Array.newInstance(firstValueVector.get(0).getClass(), + firstValueVector.size()); + for (int j=0; j<firstValueVector.size(); j++) { + firstValueArray[j] = firstValueVector.get(j); + } + + //set the initial set of values + pi.set( i, firstValueArray); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + checkValues(oid, firstSetOfValues); // check if persistent fields have values set + pi = (ArrayCollections) pm.getObjectById(oid, true); + + // Provide new set of values + for( i = 0; i < n; ++i){ + String valueType = TestUtil.getFieldSpecs(ArrayCollections.fieldSpecs[i]); + //create an array of second set of values for each value type + Object[] secondValueArray = null; + Vector secondValueVector = (Vector)secondSetOfValues.get(valueType); + secondValueArray = (Object[])java.lang.reflect.Array.newInstance(secondValueVector.get(0).getClass(), + secondValueVector.size()); + for (int j=0; j<secondValueVector.size(); j++) { + secondValueArray[j] = secondValueVector.get(j); + } + pi.set( i, secondValueArray); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondSetOfValues); + pi = (ArrayCollections) 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; + ArrayCollections pi = (ArrayCollections) pm.getObjectById(oid, true); + int n = pi.getLength(); + for (i = 0; i < n; ++i) { + String valueType = TestUtil.getFieldSpecs(ArrayCollections.fieldSpecs[i]); + //build the compareWith array + Object[] compareWith = null; + Vector compareWithVector = (Vector)startValue.get(valueType); + compareWith = (Object[])java.lang.reflect.Array.newInstance(compareWithVector.get(0).getClass(), + compareWithVector.size()); + for (int j=0; j<compareWithVector.size(); j++) { + compareWith[j] = compareWithVector.get(j); + } + + Object[] val = pi.get(i); + + if(!Arrays.equals(val, compareWith)){ + fail(ASSERTION_FAILED, + "Incorrect value for " + ArrayCollections.fieldSpecs[i]); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayCollections.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayListCollections.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayListCollections.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayListCollections.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayListCollections.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,150 @@ +/* + * 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.ArrayList; +import java.util.Collection; +import java.util.Hashtable; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.ArrayListCollections; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type ArrayList. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-23. + *<BR> + *<B>Assertion Description: </B> + If the ArrayList optional feature is supported, then JDO implementation must + support fields of the mutable object class <code>ArrayList</code>, + supporting them as Second Class Objects or First Class Objects. + */ + +public class TestArrayListCollections extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-23 (TestArrayListCollections) 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(TestArrayListCollections.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + if (!isArrayListSupported()) { + if (debug) + logger.debug("JDO Implementation does not support optional feature ArrayList"); + 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(); + ArrayListCollections pi = new ArrayListCollections(); + 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(ArrayListCollections.fieldSpecs[i]); + pi.set( i, new ArrayList((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 = (ArrayListCollections) pm.getObjectById(oid, true); + + // Provide new set of values + for( i = 0; i < n; ++i){ + String valueType = TestUtil.getFieldSpecs(ArrayListCollections.fieldSpecs[i]); + pi.set( i, new ArrayList((Collection)secondValue.get(valueType))); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (ArrayListCollections) 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; + ArrayListCollections pi = (ArrayListCollections) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + String valueType = TestUtil.getFieldSpecs(ArrayListCollections.fieldSpecs[i]); + ArrayList compareWith = new ArrayList((Collection)startValue.get(valueType)); + + ArrayList val = pi.get(i); + + if(!val.equals(compareWith)){ + fail(ASSERTION_FAILED, + "Incorrect value for " + ArrayListCollections.fieldSpecs[i]); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestArrayListCollections.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestCollectionCollections.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestCollectionCollections.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestCollectionCollections.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestCollectionCollections.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,144 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.CollectionCollections; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Collection. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-33. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the interface type + <code>java.util.Collection</code>, and may choose to support them + as Second Class Objects or First Class Objects. + */ + + +public class TestCollectionCollections extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-33 (TestCollectionCollections) 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(TestCollectionCollections.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(); + + // turn on datastore transactions + tx.setOptimistic(false); + tx.begin(); + CollectionCollections pi = new CollectionCollections(); + 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(CollectionCollections.fieldSpecs[i]); + pi.set( i, (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 = (CollectionCollections) pm.getObjectById(oid, true); + + // Provide new set of values + for( i = 0; i < n; ++i){ + String valueType = TestUtil.getFieldSpecs(CollectionCollections.fieldSpecs[i]); + pi.set( i, (Collection)secondValue.get(valueType)); + + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (CollectionCollections) 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 ret = 0; + int i; + Collection value; + CollectionCollections pi = (CollectionCollections) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + String valueType = TestUtil.getFieldSpecs(CollectionCollections.fieldSpecs[i]); + Collection compareWith = (Collection)startValue.get(valueType); + + Collection val = pi.get(i); + if(! val.equals(compareWith) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + CollectionCollections.fieldSpecs[i]); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestCollectionCollections.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigDecimal.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigDecimal.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigDecimal.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigDecimal.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,136 @@ +/* + * 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.math.BigDecimal; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfBigDecimal; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type BigDecimal. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-19. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the immutable object class + <code>java.math.BigDecimal</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfBigDecimal extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-19 (TestFieldsOfBigDecimal) 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(TestFieldsOfBigDecimal.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + BigDecimal firstValue = new BigDecimal("20079.0237"); + BigDecimal secondValue = new BigDecimal("8907489.658"); + int ret = 0; + tx.begin(); + FieldsOfBigDecimal pi = new FieldsOfBigDecimal(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfBigDecimal) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfBigDecimal) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, BigDecimal startValue){ + int ret = 0; + int i; + BigDecimal value; + FieldsOfBigDecimal pi = (FieldsOfBigDecimal) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0, value = startValue; i < n; ++i){ + if( !FieldsOfBigDecimal.isPersistent[i] ) continue; + BigDecimal val = pi.get(i); + if(!val.equals(value)){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfBigDecimal.fieldSpecs[i] + + ", expected value " + value.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigDecimal.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigInteger.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigInteger.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigInteger.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigInteger.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,136 @@ +/* + * 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.math.BigInteger; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfBigInteger; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type BigInteger. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-20. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the immutable object class + <code>java.math.BigInteger</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfBigInteger extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-20 (TestFieldsOfBigInteger) 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(TestFieldsOfBigInteger.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + BigInteger firstValue = new BigInteger("2007908"); + BigInteger secondValue = new BigInteger("896738"); + tx.begin(); + FieldsOfBigInteger pi = new FieldsOfBigInteger(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfBigInteger) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfBigInteger) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, BigInteger startValue){ + int ret = 0; + int i; + BigInteger value = startValue; + FieldsOfBigInteger pi = (FieldsOfBigInteger) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfBigInteger.isPersistent[i] ) + continue; + BigInteger val = pi.get(i); + if(!val.equals(value) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfBigInteger.fieldSpecs[i] + + ", expected value " + value.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBigInteger.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBoolean.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBoolean.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBoolean.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBoolean.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,132 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfBoolean; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Boolean. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-9. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the immutable object class + <code>java.lang.Boolean</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfBoolean extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-9 (TestFieldsOfBoolean) 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(TestFieldsOfBoolean.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Boolean firstValue = new Boolean(true); + Boolean secondValue = new Boolean(false); + tx.begin(); + FieldsOfBoolean pi = new FieldsOfBoolean(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfBoolean) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfBoolean) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Boolean startValue){ + int i; + FieldsOfBoolean pi = (FieldsOfBoolean) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfBoolean.isPersistent[i] ) + continue; + Boolean val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfBoolean.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfBoolean.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfByte.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfByte.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfByte.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfByte.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,133 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfByte; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Byte. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-11. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the immutable object class + <code>java.lang.Byte</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + + +public class TestFieldsOfByte extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-11 (TestFieldsOfByte) 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(TestFieldsOfByte.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Byte firstValue = new Byte((byte)Byte.MIN_VALUE); + Byte secondValue = new Byte((byte)Byte.MAX_VALUE); + tx.begin(); + FieldsOfByte pi = new FieldsOfByte(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfByte) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfByte) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Byte startValue){ + int i; + FieldsOfByte pi = (FieldsOfByte) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfByte.isPersistent[i] ) + continue; + Byte val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfByte.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfByte.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfCharacter.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfCharacter.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfCharacter.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfCharacter.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,133 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfCharacter; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Character. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-10. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the immutable object class + <code>java.lang.Character</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + + +public class TestFieldsOfCharacter extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-10 (TestFieldsOfCharacter) 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(TestFieldsOfCharacter.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Character firstValue = new Character((char)Character.MIN_VALUE); + Character secondValue = new Character((char)Character.MAX_VALUE); + tx.begin(); + FieldsOfCharacter pi = new FieldsOfCharacter(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfCharacter) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfCharacter) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Character startValue){ + int i; + FieldsOfCharacter pi = (FieldsOfCharacter) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfCharacter.isPersistent[i] ) + continue; + Character val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfCharacter.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfCharacter.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDate.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDate.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDate.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDate.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,133 @@ +/* + * 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.Date; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfDate; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Date. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-21. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the mutable object class + <code>java.util.Date</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfDate extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-21 (TestFieldsOfDate) 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(TestFieldsOfDate.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Date firstValue = new Date(2007908); + Date secondValue = new Date(890748967382l); + tx.begin(); + FieldsOfDate pi = new FieldsOfDate(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfDate) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfDate) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Date startValue){ + int i; + FieldsOfDate pi = (FieldsOfDate) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfDate.isPersistent[i] ) continue; + Date val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfDate.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDate.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDouble.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDouble.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDouble.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDouble.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,131 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfDouble; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Double. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-16. + *<BR> + *<B>Assertion Description: </B> + JDO implementations must support fields of the immutable object class + <code>java.lang.Double</code>, and may choose to support them as + Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfDouble extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-16 (TestFieldsOfDouble) 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(TestFieldsOfDouble.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Double firstValue = new Double(Double.MIN_VALUE); + Double secondValue = new Double(Double.MAX_VALUE); + tx.begin(); + FieldsOfDouble pi = new FieldsOfDouble(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfDouble) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfDouble) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Double startValue){ + int i; + FieldsOfDouble pi = (FieldsOfDouble) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfDouble.isPersistent[i] ) continue; + Double val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfDouble.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfDouble.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfFloat.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfFloat.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfFloat.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfFloat.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,133 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfFloat; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Float. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-15. + *<BR> + *<B>Assertion Description: </B> +JDO implementations must support fields of the immutable object class +<code>java.lang.Float</code>, and may choose to support them as +Second Class Objects or First Class Objects. + */ + + +public class TestFieldsOfFloat extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-15 (TestFieldsOfFloat) 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(TestFieldsOfFloat.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Float firstValue = new Float(Float.MIN_VALUE); + Float secondValue = new Float(Float.MAX_VALUE); + tx.begin(); + FieldsOfFloat pi = new FieldsOfFloat(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfFloat) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfFloat) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Float startValue){ + int i; + FieldsOfFloat pi = (FieldsOfFloat) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfFloat.isPersistent[i] ) continue; + Float val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfFloat.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfFloat.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfInteger.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfInteger.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfInteger.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfInteger.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,131 @@ +/* + * 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 javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfInteger; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Integer. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-13. + *<BR> + *<B>Assertion Description: </B> +JDO implementations must support fields of the immutable object class +<code>java.lang.Integer</code>, and may choose to support them as +Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfInteger extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-13 (TestFieldsOfInteger) 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(TestFieldsOfInteger.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Integer firstValue = new Integer(Integer.MIN_VALUE); + Integer secondValue = new Integer(Integer.MAX_VALUE); + tx.begin(); + FieldsOfInteger pi = new FieldsOfInteger(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfInteger) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfInteger) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Integer startValue){ + int i; + FieldsOfInteger pi = (FieldsOfInteger) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfInteger.isPersistent[i] ) continue; + Integer val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfInteger.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfInteger.java ------------------------------------------------------------------------------ svn:executable = * Added: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfLocale.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfLocale.java?view=auto&rev=160090 ============================================================================== --- incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfLocale.java (added) +++ incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfLocale.java Mon Apr 4 12:41:23 2005 @@ -0,0 +1,134 @@ +/* + * 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.Locale; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.fieldtypes.FieldsOfLocale; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Support of field type Locale. + *<BR> + *<B>Keywords:</B> model + *<BR> + *<B>Assertion ID:</B> A6.4.3-18. + *<BR> + *<B>Assertion Description: </B> +JDO implementations must support fields of the immutable object class +<code>java.util.Locale</code>, and may choose to support them as +Second Class Objects or First Class Objects. + */ + +public class TestFieldsOfLocale extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A6.4.3-18 (TestFieldsOfLocale) 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(TestFieldsOfLocale.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTest(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTest(PersistenceManager pm) + { + Transaction tx = pm.currentTransaction(); + try { + int i, n; + Locale firstValue = Locale.CHINA; + Locale secondValue = Locale.JAPANESE; + tx.begin(); + FieldsOfLocale pi = new FieldsOfLocale(); + 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){ + pi.set( i, firstValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + + pi = (FieldsOfLocale) pm.getObjectById(oid, true); + checkValues(oid, firstValue); // check if persistent fields have values set + + // Provide new set of values + for( i = 0; i < n; ++i){ + pi.set(i, secondValue); + } + tx.commit(); + // cache will be flushed + pi = null; + System.gc(); + + tx.begin(); + // check new values + checkValues(oid, secondValue); + pi = (FieldsOfLocale) pm.getObjectById(oid, true); + pm.deletePersistent(pi); + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } + + /** */ + private void checkValues(Object oid, Locale startValue){ + int i; + Locale value; + FieldsOfLocale pi = (FieldsOfLocale) pm.getObjectById(oid, true); + int n = pi.getLength(); + for( i = 0; i < n; ++i){ + if( !FieldsOfLocale.isPersistent[i] ) continue; + Locale val = pi.get(i); + if(!val.equals(startValue) ){ + fail(ASSERTION_FAILED, + "Incorrect value for " + FieldsOfLocale.fieldSpecs[i] + + ", expected value " + startValue.toString() + + ", value is " + val.toString()); + } + } + } +} Propchange: incubator/jdo/trunk/tck20/test/java/org/apache/jdo/tck/models/fieldtypes/TestFieldsOfLocale.java ------------------------------------------------------------------------------ svn:executable = *