Return-Path: Delivered-To: apmail-db-jdo-commits-archive@www.apache.org Received: (qmail 86216 invoked from network); 19 Mar 2005 05:06:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Mar 2005 05:06:14 -0000 Received: (qmail 87509 invoked by uid 500); 19 Mar 2005 05:06:14 -0000 Mailing-List: contact jdo-commits-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-commits@db.apache.org Delivered-To: moderator for jdo-commits@db.apache.org Received: (qmail 7097 invoked by uid 99); 19 Mar 2005 01:36:39 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Message-ID: <20050319010955.29728.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Sat, 19 Mar 2005 01:09:55 -0000 Subject: svn commit: r158179 [50/61] - in incubator/jdo/trunk/tck11: ./ assertions/ iut_jars/ test/ test/conf/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/jdo/ test/java/org/apache/jdo/tck/ test/java/org/apache/jdo/tck/api/ test/java/org/apache/jdo/tck/api/instancecallbacks/ test/java/org/apache/jdo/tck/api/jdohelper/ test/java/org/apache/jdo/tck/api/persistencemanager/ test/java/org/apache/jdo/tck/api/persistencemanagerfactory/ test/java/org/apache/jdo/tck/enhancement/ test/java/org/apache/jdo/tck/extents/ test/java/org/apache/jdo/tck/lifecycle/ test/java/org/apache/jdo/tck/lifecycle/nontransactional/ test/java/org/apache/jdo/tck/models/ test/java/org/apache/jdo/tck/models/embedded/ test/java/org/apache/jdo/tck/models/fieldtypes/ test/java/org/apache/jdo/tck/models/inheritance/ test/java/org/apache/jdo/tck/pc/ test/java/org/apache/jdo/tck/pc/company/ test/java/org/apache/jdo/tck/pc/fieldtypes/ test/java/org/apache/jdo/tck/pc/inheritance/ test/java/org/apache/jdo/tck/pc/instancecallbacks/ test/java/org/apache/jdo/tck/pc/lifecycle/ test/java/org/apache/jdo/tck/pc/mylib/ test/java/org/apache/jdo/tck/query/ test/java/org/apache/jdo/tck/query/operators/ test/java/org/apache/jdo/tck/transactions/ test/java/org/apache/jdo/tck/util/ test/jdo/ test/jdo/applicationidentity/ test/jdo/applicationidentity/org/ test/jdo/applicationidentity/org/apache/ test/jdo/applicationidentity/org/apache/jdo/ test/jdo/applicationidentity/org/apache/jdo/tck/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/company/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/fieldtypes/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/inheritance/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/instancecallbacks/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ test/jdo/applicationidentity/org/apache/jdo/tck/pc/mylib/ test/jdo/datastoreidentity/ test/jdo/datastoreidentity/org/ test/jdo/datastoreidentity/org/apache/ test/jdo/datastoreidentity/org/apache/jdo/ test/jdo/datastoreidentity/org/apache/jdo/tck/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/company/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/fieldtypes/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/inheritance/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/instancecallbacks/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/ test/jdo/datastoreidentity/org/apache/jdo/tck/pc/mylib/ To: jdo-commits@db.apache.org From: mbo@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetOptimisticCalledDuringTxCompletion.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetOptimisticCalledDuringTxCompletion.java?view= =3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= OptimisticCalledDuringTxCompletion.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= OptimisticCalledDuringTxCompletion.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,134 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Optimistic Called During TX Completion + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-3. + *
+ *Assertion Description: + If the setOptimistic method of the Transaction interface is called during= commit or rollback processing (within the + beforeCompletion and afterCompletion synchronization methods), a JDOUserE= xception is thrown.=20 + + + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/20/01 1.0 + *=20 + */ +public class SetOptimisticCalledDuringTxCompletion=20 + extends JDO_Test=20 + implements Synchronization { + + private Transaction tx; + + private boolean optimisticFlag; + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-3 (SetOptimisticCalledDuringTxCompletion) faile= d: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetOptimisticCalledDuringTxCompletion.class); + } + =20 + /** */ + public void beforeCompletion(){ + if (debug) logger.debug ("beforeCompletion"); + try { + tx.setOptimistic(optimisticFlag); + fail(ASSERTION_FAILED, + "tx.setOptimistic called in beforeCompletion should throw= JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) logger.debug("caught expected exception " + ex); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.setOptimistic called in beforeCompletion throws unexp= ected exception: " + ex); + } + } + =20 + /** */ + public void afterCompletion(int status) { + if (debug) logger.debug("afterCompletion"); + try { + tx.setOptimistic(optimisticFlag); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.setOptimistic called in afterCompletion throws unexpe= cted exception: " + ex); + } + } + =20 + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetOptimisticCalledDuringTxCompletion(pm);=20 + + pm.close();=20 + pm =3D null; + } + + /** test transactions.setOptimistic() */ + void runTestSetOptimisticCalledDuringTxCompletion(PersistenceManager p= m) { + tx =3D pm.currentTransaction(); + try { + tx.setSynchronization(this); =20 + + optimisticFlag =3D false; + tx.begin(); + tx.commit(); + =20 + if (isOptimisticSupported()) { + optimisticFlag =3D true; + tx.begin(); + tx.commit(); + } + + tx =3D null; + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetOptimisticDuringTransaction.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetOptimisticDuringTransaction.java?view=3Dauto= &rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= OptimisticDuringTransaction.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= OptimisticDuringTransaction.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,107 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Optimistic During Transaction + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-15. + *
+ *Assertion Description: + If Transaction.setOptimistic is called while there is an active transacti= on, a JDOUserException is thrown.=20 + + + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/09/01 1.0 + */ +public class SetOptimisticDuringTransaction extends JDO_Test { +=20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-15 (SetOptimisticDuringTransaction) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetOptimisticDuringTransaction.class); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetOptimisticDuringTransaction(pm);=20 + + pm.close();=20 + pm =3D null; + } + + /** */ + void runTestSetOptimisticDuringTransaction(PersistenceManager pm) { + Transaction tx =3D pm.currentTransaction(); + try { + tx.begin(); + // try to call tx.setOptimistic(true) + if (isOptimisticSupported()) { + try { + tx.setOptimistic(true); + fail(ASSERTION_FAILED, + "calling tx.setOptimistic in the context of an ac= tive transaction should throw a JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) logger.debug("caught expected exception " += ex); + } + } + // try to call tx.setOptimistic(false) + try { + tx.setOptimistic(false); + fail(ASSERTION_FAILED, + "calling tx.setOptimistic in the context of an active= transaction should throw a JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) logger.debug("caught expected exception " + ex); + } + tx.commit(); + tx =3D null; + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetOptimisticTrueWhenNotSupported.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetOptimisticTrueWhenNotSupported.java?view=3Da= uto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= OptimisticTrueWhenNotSupported.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= OptimisticTrueWhenNotSupported.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,90 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.JDOUnsupportedOptionException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Optimistic True When Not Supported + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-7. + *
+ *Assertion Description: + If the optional feature Optimistic is not supported, then a call to Trans= action.setOptimistic with a value of true will + throw a JDOUnsupportedOptionException.=20 + + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/18/01 1.0 + */ +public class SetOptimisticTrueWhenNotSupported extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-7 (SetOptimisticTrueWhenNotSupported) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetOptimisticTrueWhenNotSupported.class); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetOptimisticTrueWhenNotSupported(pm); =20 + + pm.close();=20 + pm =3D null; + } + + /** */ + void runTestSetOptimisticTrueWhenNotSupported(PersistenceManager pm) { + if (isOptimisticSupported()) { + if (debug) logger.debug("Optimistic supported."); + return; + } + =20 + Transaction tx =3D pm.currentTransaction(); + try { + tx.setOptimistic(true); + fail(ASSERTION_FAILED, + "tx.setOptimistic(true) should throw JDOUnsupportedOption= Exception, if the implementation does not support optimistic transactions."= ); + } + catch (JDOUnsupportedOptionException ex) { + // expected excepted + if (debug) logger.debug("caught expected exception " + ex); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetRetainValues.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetRetainValues.java?view=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= RetainValues.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= RetainValues.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,89 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Retain Values + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-18. + *
+ *Assertion Description: + The retainValues setting passed to setRetainValues replaces=20 + the retainValues setting currently active.=20 + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/09/01 1.0 + */ +public class SetRetainValues extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-18 (SetRetainValues) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetRetainValues.class); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetRetainValues(pm); + + pm.close();=20 + pm =3D null; + } + + /** */ + void runTestSetRetainValues(PersistenceManager pm) { + if (!isRetainValuesSupported()) { + if (debug) logger.debug("RetainValues not supported."); + return; + } + =20 + Transaction tx =3D pm.currentTransaction(); + boolean orig =3D tx.getRetainValues(); + tx.setRetainValues(!orig); + if (tx.getRetainValues() =3D=3D orig) { + fail(ASSERTION_FAILED, + "changing the retainValues flag by calling tx.setRetainVa= lues does not have a effect."); + } + if ((tx !=3D null) && tx.isActive()) { + tx.rollback(); + } + } +} + Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetRetainValuesCalledDuringTxCompletion.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetRetainValuesCalledDuringTxCompletion.java?vi= ew=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= RetainValuesCalledDuringTxCompletion.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= RetainValuesCalledDuringTxCompletion.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,137 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.JDOUserException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Optimistic Called During TX Completion + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-4. + *
+ *Assertion Description: + If the setOptimistic method of the Transaction interface is called during + * commit or rollback processing (within the beforeCompletion and + * afterCompletion synchronization methods), a JDOUserException is thrown.=20 + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/20/01 1.0 + */ +public class SetRetainValuesCalledDuringTxCompletion=20 + extends JDO_Test=20 + implements Synchronization { + + private Transaction tx; + =20 + private boolean retainValuesFlag; + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-4 (SetRetainValuesCalledDuringTxCompletion) fai= led: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetRetainValuesCalledDuringTxCompletion.class); + } + + /** */ + public void beforeCompletion(){ + if (debug) logger.debug ("beforeCompletion"); + try { + tx.setRetainValues(retainValuesFlag); + fail(ASSERTION_FAILED, + "tx.setRetainValues called in beforeCompletion should thr= ow JDOUserException."); + } + catch (JDOUserException ex) { + // expected exception + if (debug) logger.debug("caught expected exception " + ex); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.setRetainValues called in beforeCompletion throws une= xpected exception: " + ex); + } + } + =20 + /** */ + public void afterCompletion(int status) { + if (debug) logger.debug ("afterCompletion"); + try { + tx.setRetainValues(retainValuesFlag); + } + catch (JDOUserException ex) { + // TBD: need to remove this catch block as soon as the JDORI is + // fixed see 'Issue 61: Transaction.isActive issues' + if (debug) logger.debug("caught exception " + ex); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.setRetainValues called in afterCompletion throws unex= pected exception: " + ex); + } + } + =20 + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetRetainValuesCalledDuringTxCompletion(pm); + + pm.close(); + pm =3D null; + } + + /** */ + void runTestSetRetainValuesCalledDuringTxCompletion(PersistenceManager= pm) { + tx =3D pm.currentTransaction(); + try { + tx.setSynchronization(this); =20 + =20 + retainValuesFlag =3D false; + tx.begin(); + tx.commit(); + =20 + if (isRetainValuesSupported()) { + retainValuesFlag =3D true; + tx.begin(); + tx.commit(); + } + + tx =3D null; + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetRetainValuesTrueWhenNotSupported.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetRetainValuesTrueWhenNotSupported.java?view= =3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= RetainValuesTrueWhenNotSupported.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= RetainValuesTrueWhenNotSupported.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,90 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.JDOUnsupportedOptionException; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Retain Values True When Not Supported + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-8. + *
+ *Assertion Description: + If the optional feature RetainValues is not supported, then a call to Tra= nsaction.setRetainValues with a + value of true will cause a JDOUnsupportedOptionException to be thrown.=20 + + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/22/01 1.0 + */ +public class SetRetainValuesTrueWhenNotSupported extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-8 (SetRetainValuesTrueWhenNotSupported) failed:= "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetRetainValuesTrueWhenNotSupported.class); + } + =20 + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetRetainValuesTrueWhenNotSupported(pm); + + pm.close();=20 + pm =3D null; + } + =20 + /** test transactions.setRetainValues() */ + void runTestSetRetainValuesTrueWhenNotSupported(PersistenceManager pm)= { + if (isRetainValuesSupported()) { + if (debug) logger.debug("RetainValues supported."); + return; + } + + Transaction tx =3D pm.currentTransaction(); + try { + tx.setRetainValues(true); + fail(ASSERTION_FAILED, + "tx.setRetainValues(true) should throw JDOUnsupportedOpti= onException, if the implementation does not support retainValues."); + } + catch (JDOUnsupportedOptionException ex) { + // expected excepted + if (debug) logger.debug("caught expected exception " + ex); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetSynchronization.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetSynchronization.java?view=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= Synchronization.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= Synchronization.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,125 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Synchronization + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.3-1. + *
+ *Assertion Description: + A call to Transaction.setSynchronization registers a Synchronization inst= ance with the + Transaction for transaction completion notifications. Any Synchronization= instance already registered will be replaced. + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/11/01 1.0 + */ +public class SetSynchronization extends JDO_Test implements Synchronizatio= n { + =20 + private Transaction tx; + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.3-1 (SetSynchronization) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetSynchronization.class); + } + =20 + /** */ + public void beforeCompletion(){ + try { + if (debug)=20 + logger.debug("before Complition isActive returns :" + + tx.isActive()); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in beforeCompletion throws unexpected= exception: " + ex); + } + =20 + } + + /** */ + public void afterCompletion(int status) { + try { + if (debug)=20 + logger.debug("after Complition isActive returns :" + + tx.isActive()); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in afterCompletion throws unexpected = exception: " + ex); + } + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetSynchronization(pm);=20 + + pm.close();=20 + pm =3D null; + } + + /** */=20 + void runTestSetSynchronization(PersistenceManager pm) { + tx =3D pm.currentTransaction(); + try { + tx.begin(); + Synchronization orig =3D tx.getSynchronization(); + tx.setSynchronization(this); + Synchronization current =3D tx.getSynchronization(); + if (current =3D=3D orig) { + fail(ASSERTION_FAILED, + "tx.setSynchronization does not replace Synchronizati= on instances registered with the transaction."); + } + if (current !=3D this) { + fail(ASSERTION_FAILED, + "unexpected sxnchronization isntance, expected " + th= is + ", got " + current); + } =20 + + tx.commit(); + tx =3D null; + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= SetSynchronizationToNull.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/SetSynchronizationToNull.java?view=3Dauto&rev= =3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= SynchronizationToNull.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Set= SynchronizationToNull.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,104 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: Set Synchronization To Null + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.3-2. + *
+ *Assertion Description: + If the parameter to Transaction.setSynchronization is null, then no insta= nce + will be notified.=20 + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Azita Kamangar 10/11/01 1.0 + */ +public class SetSynchronizationToNull=20 + extends JDO_Test=20 + implements javax.transaction.Synchronization { + =20 + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.3-2 (SetSynchronizationToNull) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetSynchronizationToNull.class); + } + + /** */ + public void beforeCompletion(){ + fail(ASSERTION_FAILED, + "Instance should not be registered, thus this beforeCompletio= n methgod should not be called."); + } + + /** */ + public void afterCompletion(int status) { + fail(ASSERTION_FAILED, + "Instance should not be registered, thus this afterCompletion= methgod should not be called."); + } + =20 + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestSetSynchronizationToNull(pm);=20 + + pm.close();=20 + pm =3D null; + } + + /** */ + void runTestSetSynchronizationToNull(PersistenceManager pm) { + Transaction tx =3D pm.currentTransaction(); + try { + tx.begin(); + tx.setSynchronization(this); + tx.setSynchronization(null); + if (tx.getSynchronization() !=3D null) { + fail(ASSERTION_FAILED, + "tx.setSynchronization(null) should overwrite previou= s registered synchronization instance."); + } + + tx.commit(); + tx =3D null; + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/= WhenNontransactionalReadIsFalse.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/transactions/WhenNontransactionalReadIsFalse.java?view=3Daut= o&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Whe= nNontransactionalReadIsFalse.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Whe= nNontransactionalReadIsFalse.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,140 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 +package org.apache.jdo.tck.transactions; + +import java.util.Collection; +import java.util.Date; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; +import javax.jdo.JDOUserException; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.company.Company; +import org.apache.jdo.tck.pc.company.Department; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title: When Nontransactional Read Is False + *
+ *Keywords: transactions + *
+ *Assertion ID: A13.4.2-10. + *
+ *Assertion Description: + If this flag is set to false, then queries and field read access + (including navigation) outside an active transaction + throw a JDOUserException. + */ + + +/* + * Revision History + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * Author : Date : Version =20 + * Michelle Caisse 11/11/04 1.0 + */ +public class WhenNontransactionalReadIsFalse extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED =3D=20 + "Assertion A13.4.2-10 (WhenNontransactionalReadIsFalse) failed: "; + =20 + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(WhenNontransactionalReadIsFalse.class); + } + + /** */ + public void test() { + pm =3D getPM(); + =20 + runTestWhenNontransactionalReadIsFalse(pm); + + pm.close();=20 + pm =3D null; + } + + /** test transactions.setNontransactionalReadIsFalse() */ + public void runTestWhenNontransactionalReadIsFalse(PersistenceManager = pm) { + Transaction tx =3D pm.currentTransaction(); + try { + tx.setNontransactionalRead(false); + tx.begin(); + Company c =3D new Company(1L, "MyCompany", new Date(), null); + Department d =3D new Department(999, "MyDepartment", c); + pm.makePersistent(c); + pm.makePersistent(d); + if (tx.getNontransactionalRead()) { + fail(ASSERTION_FAILED, + "tx.getNontransactionalRead before commit returns tru= e after setting the flag to false."); + } + tx.commit(); + if (tx.getNontransactionalRead()) { + fail(ASSERTION_FAILED, + "tx.getNontransactionalRead after commit returns true= after setting the flag to false."); + } + + // make sure transaction is not active + if (tx.isActive()) { + fail(ASSERTION_FAILED, + "transaction still active after tx.commit."); + } + tx =3D null; + + try { + // read department name + String name =3D d.getName(); + fail(ASSERTION_FAILED, + "Field read permitted outside an active transaction w= hen NontransactionalRead is false."); + } catch (JDOUserException juex) { + if (debug) + logger.debug(" Caught expected JDOUserException " + j= uex); + } + try { + // navigate from department to company + c =3D d.getCompany(); + fail(ASSERTION_FAILED, + "Navigation permitted outside an active transaction w= hen NontransactionalRead is false."); + } catch (JDOUserException juex) { + if (debug) + logger.debug(" Caught expected JDOUserException " + j= uex); + } + try { + // run query + Query q =3D pm.newQuery(Department.class); + q.setFilter("name =3D=3D \"MyDepartment\""); + Collection result =3D (Collection)q.execute(); + fail(ASSERTION_FAILED, + "Query permitted outside an active transaction when N= ontransactionalRead is false."); + } catch (JDOUserException juex) { + if (debug) + logger.debug(" Caught expected JDOUserException " + j= uex); + } + } + finally { + if ((tx !=3D null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/BatchRes= ultPrinter.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/util/BatchResultPrinter.java?view=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/BatchResult= Printer.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/BatchResult= Printer.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,103 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.tck.util; + +import java.io.PrintStream; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.textui.ResultPrinter; + +/** + * Default result printer implementation for running tests in batch mode. + *=20 + * @author Michael Bouschen + */ +public class BatchResultPrinter + extends ResultPrinter +{ + /** */ + public BatchResultPrinter(PrintStream writer) { + super(writer); + } + =20 + /** Called in case of a test error. */ + public void addError(Test test, Throwable t) { + getWriter().print(" ERROR"); + } + =20 + /** Called in case of a test failure. */=20 + public void addFailure(Test test, AssertionFailedError t) { + getWriter().print(" FAILURE"); + } + =20 + /** Called when a test case is finished. */ + public void endTest(Test test) { + getWriter().println(); + } + =20 + /** Called when a test case is started. */ + public void startTest(Test test) { + String testName; + if (test instanceof TestCase) { + testName =3D getClassBaseName(test) + "." + ((TestCase)test).g= etName(); + } + else { + testName =3D test.toString(); + } + getWriter().print("RUN " + testName); + } + =20 + /** */ + protected void printHeader(long runTime) { + getWriter().println("Time: "+elapsedTimeAsString(runTime)); + } + =20 + /** */ + protected void printFooter(TestResult result) { + if (result.wasSuccessful()) { + getWriter().print("OK"); + getWriter().println (" (" + result.runCount() + " test" + (res= ult.runCount() =3D=3D 1 ? "": "s") + ")"); + =20 + } else { + getWriter().println("FAILURES!!!"); + getWriter().println("Tests run: "+result.runCount()+=20 + ", Failures: "+result.failureCount()+ + ", Errors: "+result.errorCount()); + } + } + =20 + // helper method + =20 + /**=20 + * @return Name of the class of the given object without package prefix + */ + private String getClassBaseName(Object obj) { + if (obj =3D=3D null) return null; + String className =3D obj.getClass().getName(); + int index =3D className.lastIndexOf('.'); + if (index !=3D -1) { + className =3D className.substring(index + 1); + } + return className; + } + =20 +} + + Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/BatchTes= tRunner.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/util/BatchTestRunner.java?view=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/BatchTestRu= nner.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/BatchTestRu= nner.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,175 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.tck.util; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.io.PrintStream; +import java.util.Arrays; + +import junit.framework.Test; +import junit.framework.TestResult; +import junit.framework.TestSuite; +import junit.textui.ResultPrinter; +import junit.textui.TestRunner; + +/** + * TestRunner class for running a single test or a test suite in batch + * mode. The format of the test output is specified by the result printer + * class. The main method sets an exit code according to the test result: + *
    + *
  • 0: success + *
  • 1: failure, the test shows an unexpected behavior + *
  • 2: exception, the test throws an unhandled excption=20 + *
+ *=20 + * @author Michael Bouschen + */ +public class BatchTestRunner + extends TestRunner +{ + /** Name of the system property to specify the result printer class. */ + public static final String RESULTPRINTER_PROPERTY =3D "ResultPrinterCl= ass";=20 + =20 + /** Default of the system property ResultPrinterClass. */ + public static final String RESULTPRINTER_DEFAULT =3D BatchResultPrinte= r=2Eclass.getName(); + =20 + /**=20 + * Constructor.=20 + * It creates a result printer instance based on the system property + * and delegates to the constructor taking a result printer argument.=20 + */ + public BatchTestRunner() { + super(); + setPrinter(getResultPrinter()); + } + =20 + /** =20 + * Constructor. Uses the specified resultPrinter to format the test re= sult. + */ + public BatchTestRunner(ResultPrinter resultPrinter) { + super(resultPrinter); + } + + /** Runs all test methods from the specified class. */ + public static void run(Class clazz) { + run(new TestSuite(clazz)); + } + =20 + /** Runs the specified test. */ + public static TestResult run(Test test) { + return new BatchTestRunner().doRun(test); + } + + /** Runs the specified test and waits until the user types RETURN. */ + public static void runAndWait(Test suite) { + new BatchTestRunner().doRun(suite, true); + } + + /**=20 + * Runs in batch mode and sets an exit code. If the specified String + * array includes a single fully qualified class name, this test class + * is executed. If it is empty it runs the TestListSuite. + */ + public static void main(String args[]) { + try { + TestResult r =3D new BatchTestRunner().start(args); + if (!r.wasSuccessful())=20 + System.exit(FAILURE_EXIT); + System.exit(SUCCESS_EXIT); + } catch(Exception e) { + System.err.println(e.getMessage()); + System.exit(EXCEPTION_EXIT); + } + } + + /** */ + public TestResult start(String[] args) { + Test suite =3D null; + if ((args =3D=3D null) || args.length =3D=3D 0) { + suite =3D getTest(TestListSuite.class.getName()); + } + else if (args.length =3D=3D 1) { + suite =3D getTest(args[0]); + } + else { + suite =3D new TestListSuite("JDO TCK", Arrays.asList(args)); + } + return doRun(suite); + } + + /**=20 + * Returns a result printer instance. The system property + * ResultPrinterClass specifies the class of the returned instanec. The + * class must extend junit.textui.ResultPrinter. + */ + protected ResultPrinter getResultPrinter() { + String className =3D System.getProperty(RESULTPRINTER_PROPERTY); + if (className !=3D null) { + className =3D className.trim(); + if (className.length() !=3D 0) { + String msg =3D null; + try { + // get class instance + Class clazz =3D Class.forName(className); + // constructor taking PrintStream arg + Constructor ctor =3D clazz.getConstructor( + new Class[] { PrintStream.class } ); + // create instance + return (ResultPrinter)ctor.newInstance( + new Object[] { System.out }); + } + catch (ClassNotFoundException ex) { + // specified ResultPrinter class not=20 + msg =3D "Cannot find specified result printer class " = +=20 + className + "."; + } + catch (NoSuchMethodException ex) { + msg =3D "Class " + className +=20 + " does not provide constructor taking a PrintStrea= m=2E"; + } + catch (InstantiationException ex) { + msg =3D "Class " + className + " is abstract."; + } + catch (IllegalAccessException ex) { + msg =3D "Constructor taking a PrintStream of class " +=20 + className + " is not accessible."; + } + catch (InvocationTargetException ex) { + msg =3D "Constructor call results in exception " + ex = + "."; + } + + // ResultPrinter class specified, but not avaiable + System.out.println(msg); + ResultPrinter printer =3D getDefaultResultPrinter(); + System.out.println("Using default result printer of class = " +=20 + printer.getClass().getName()); + } + } + =20 + // ResultPrinter class not specified =3D> use default + return getDefaultResultPrinter(); + } + + /**=20 + * Returns an instance of the default result printer class + * BatchResultPrinter. + */ + protected ResultPrinter getDefaultResultPrinter() { + return new BatchResultPrinter(System.out); + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/ClassGen= erator.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/util/ClassGenerator.java?view=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/ClassGenera= tor.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/ClassGenera= tor.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,916 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ +=20 + +//Title: Your Product Name +//Version: +//Copyright: Copyright (c) 1998 +//Author: +//Company: Your Company +//Description: Your description + + +package org.apache.jdo.tck.util; + +import java.io.*; + +public class ClassGenerator { + private final String [] fieldTypes =3D {"boolean", "byte", "short"= , "int", "long", + "char", "float", "double", + "Boolean", "Character", "Byt= e", "Short", "Integer", + "Long", "Float", "Double", "= String", + "Locale", "Date", "BigDecima= l", "BigInteger", + "Object", "SimpleClass", "Si= mpleInterface" + }; + //includes a place holder for default package access + private final String [] accessSpecifiers =3D {"private ", "public ", "pr= otected ", "" }; + + private final String [] fieldModifiers =3D {"", "static ", "transient = ", "final ", "volatile ", + "static transient ", "static= final ", "static volatile ", + "transient final ", "transie= nt volatile ", + "static transient final ", "= static transient volatile " }; + + private final String [] xmlPersistenceModifiers =3D {"", "persistence-mo= difier=3D\"none\"", + "persistence-modifie= r=3D\"persistent\"", + "persistence-modifie= r=3D\"transactional\""}; + + private final String [] xmlEmbeddedModifiers =3D {"", "embedded=3D\"t= rue\"", "embedded=3D\"false\""}; + + private final String [] collectionTypes =3D {"Collection", "Map", "Se= t", "List", + "HashSet", "ArrayList", "Ha= shMap", "Hashtable", + "LinkedList", "TreeMap", "T= reeSet", "Vector", "Array"}; + + //Note: Any updates to elementtypes should include an update to elements= WithPackageInfo + private final String [] elementTypes =3D {"Object", "SimpleClass", "S= impleInterface", "String", + "Date", "Locale", "BigDecimal"= , "BigInteger", + "Byte", "Double", "Float", "In= teger", "Long", + "Short"}; + + private final String [] elementsWithPackageInfo =3D {"java.lang.Object", + "org.apache.jdo.tck.pc= .fieldtypes.SimpleClass", + "org.apache.jdo.tck.pc= .fieldtypes.SimpleInterface", + "java.lang.String", "j= ava.util.Date", + "java.util.Locale", "j= ava.math.BigDecimal", + "java.math.BigInteger"= , "java.lang.Byte", + "java.lang.Double", "j= ava.lang.Float", + "java.lang.Integer","j= ava.lang.Long", + "java.lang.Short"}; + + private StringBuffer fieldSpecs =3D new StringBuffer(2000); + private StringBuffer isPersistent =3D new StringBuffer(200); + private StringBuffer isStatic =3D new StringBuffer(200); + private StringBuffer isFinalArray =3D new StringBuffer(2000); + =20 + // can accomodate only 4000 fields, have to increase the capacity if the= fields exceed 4000 + private static boolean [] isFinal =3D new boolean[4000]; + + void generate() throws Exception + { + final String twoSpaces =3D " "; + final String space =3D " "; + + for (int i=3D0; i < fieldTypes.length; i++) + { + String classFile =3D (isPrimitive(fieldTypes[i]) ? "FieldsOfPrimitiv= e" : "FieldsOf") + fieldTypes[i]; + + FileOutputStream xmlFout =3D new FileOutputStream(classFile + ".jdo.= n"); + PrintWriter xmlPw =3D new PrintWriter(xmlFout); + FileOutputStream xmlFout1 =3D new FileOutputStream(classFile + ".jdo= .a"); + PrintWriter xmlPw1 =3D new PrintWriter(xmlFout1); + FileOutputStream xmlFout2 =3D new FileOutputStream(classFile + ".jdo= .d"); + PrintWriter xmlPw2 =3D new PrintWriter(xmlFout2); + startXmlMetaData(xmlPw); + startXmlMetaData(xmlPw1); + startXmlMetaData(xmlPw2); + + startXmlClass(xmlPw, classFile, 0); + startXmlClass(xmlPw1, classFile, 1); + startXmlClass(xmlPw2, classFile, 2); + + FileOutputStream fout =3D new FileOutputStream(classFile + ".java"); + PrintWriter pw =3D new PrintWriter(fout); + startClass(pw, classFile); + int fieldCounter =3D 0; + for(int j=3D0; j < accessSpecifiers.length; j++) + { + for (int k=3D0; k < fieldModifiers.length; k++) + { + for(int l =3D 0; l < xmlPersistenceModifiers.length; l++) + { + // do not generate persistence modifiers (persistent or trans= actional or none) + // for fields that cannot be persisted + + + if( (fieldModifiers[k].indexOf("static") >=3D 0 || fieldModifiers= [k].indexOf("final") >=3D 0 ) && + !xmlPersistenceModifiers[l].equals("")) + continue; =20 + =20 +/* original code + if(!isPersistenceCapable(fieldModifiers[k]) + && !xmlPersistenceModifiers[l].equals("")) + continue; +*/ + for(int m=3D0; m < xmlEmbeddedModifiers.length; m++) { + // generate persistence modifiers (persistent or transact= ional or none) + // only for fields that can be persisted + // generate embedded modifiers only for persistent fields + =20 + boolean fieldIsPersistent =3D !( fieldModifiers[k].indexO= f("static") >=3D 0 || + fieldModifiers[k].indexOf(= "final") >=3D 0 || + xmlPersistenceModifiers[l]= .indexOf("none") >=3D 0 || + xmlPersistenceModifiers[l]= .indexOf("transactional") >=3D 0 || + (fieldModifiers[k].indexOf= ("transient") >=3D 0 && xmlPersistenceModifiers[l].indexOf("persistent") = =3D=3D -1) + );=20 + =20 + if(!xmlEmbeddedModifiers[m].equals("") && !fieldIsPersist= ent ) + continue; + + StringBuffer sb =3D new StringBuffer(); + sb.append(twoSpaces); + sb.append(accessSpecifiers[j]); + sb.append(fieldModifiers[k]); + sb.append(fieldTypes[i]); + sb.append(space); + String fieldName =3D (fieldTypes[i] + fieldCounter++); +//temporary fix to get around the bug in the enhancer code +if(!(xmlEmbeddedModifiers[m].equals("") && xmlPersistenceModifiers[l].equ= als(""))) +{ + printXmlField(xmlPw, "name=3D\"" + fieldName + "\" " + + xmlPersistenceModifiers[l]+ " " + + xmlEmbeddedModifiers[m]); + printXmlField(xmlPw1, "name=3D\"" + fieldName + "\" " + + xmlPersistenceModifiers[l]+ " " + + xmlEmbeddedModifiers[m]); + printXmlField(xmlPw2, "name=3D\"" + fieldName + "\" " + + xmlPersistenceModifiers[l]+ " " + + xmlEmbeddedModifiers[m]); +}//end temporary fix + sb.append(fieldName); + buildisPersistentArray(fieldIsPersistent); // add to isPe= rsistentArray + buildisStaticArray(isStatic(fieldModifiers[k])); // add t= o isStaticArray + buildFieldSpecs(xmlPersistenceModifiers[l].replace('"',' = ') + " " + + xmlEmbeddedModifiers[m].replace('"',' ') + + sb.toString()); // add to the field specs= array + isFinal[fieldCounter-1] =3D fieldModifiers[k].indexOf("fi= nal") >=3D 0; + if(isFinal[fieldCounter-1]) + sb.append(getInitializerForFinalTypes(fieldTypes[i])); + buildisFinalArray(isFinal[fieldCounter-1]); + sb.append(";"); + pw.println(sb.toString()); + } + } + } + } + writeisPersistentArray(pw); + writeisStaticArray(pw); + writeisFinalArray(pw); + writeFieldSpecs(pw); + writeMethodGetLength(pw); + writeMethodGet(pw, fieldTypes[i], fieldCounter); + writeMethodSet(pw, fieldTypes[i], fieldCounter); + endClass(pw); + pw.close(); + fout.close(); + + endXmlClass(xmlPw); + endXmlClass(xmlPw1); + endXmlClass(xmlPw2); + endXmlMetaDeta(xmlPw); + endXmlMetaDeta(xmlPw1); + endXmlMetaDeta(xmlPw2); + xmlPw.close(); + xmlFout.close(); + xmlPw1.close(); + xmlFout1.close(); + xmlPw2.close(); + xmlFout2.close(); + } + } + + + private void startClass(PrintWriter pw, String className) + { + pw.println("package org.apache.jdo.tck.pc.fieldtypes;"); + pw.println(""); + pw.println(getImportStatements(className)); + pw.println("public class " + className + " { " ); + pw.println(" public int identifier;"); + } + + private void endClass(PrintWriter pw) + { + pw.println(""); + pw.println("}"); + } + + private void startXmlMetaData(PrintWriter pw) + { + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + + private void endXmlMetaDeta(PrintWriter pw) + { + pw.println(""); + pw.println(""); + } + + private void startXmlClass(PrintWriter pw, String className, int type) + { + switch(type) + { + case(0): + pw.println(""); + break; + case(1): + pw.println(""); + break; + case(2): + pw.println(""); + break; + default: + System.out.println("Unsupported Type"); + } + } + + private void endXmlClass(PrintWriter pw) + { + pw.println(""); + } + + // need to check if we should support extents + // fieldName includes modifiers + private void printXmlField(PrintWriter pw, String fieldName) + { + pw.println(""); + pw.println(""); + } + + // fieldname does not include any modifiers. + // element type includes package informaiton. + private void printXmlCollectionFieldWithEmbeddedElement(PrintWriter pw, = String fieldName, + String elementTy= pe, String embeddedValue) + { + pw.println(""); + pw.print(""); + pw.println(""); + pw.println(""); + } + + private void printXmlArrayFieldWithEmbeddedElement(PrintWriter pw, Strin= g fieldName, + String embeddedValue) + { + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + } + + private void printXmlMapField(PrintWriter pw, String fieldName, String k= eyType, + String embeddedKey, String valueType, Stri= ng embeddedValue) + { + pw.println(""); + pw.print(""); + pw.println(""); + pw.println(""); + } + + private String getInitializerForFinalTypes(String fieldType) throws Exce= ption + { + if (fieldType.equals("char")) + return " =3D 'a'"; //primitive character, return 'a'; + else if (fieldType.equals("boolean")) + return " =3D false"; //primitive boolean, return 'a'; + else if (Character.isLowerCase(fieldType.charAt(0))) + return " =3D 5"; // return 0 for all other primitive types + else if (fieldType.equals("Byte")) + return " =3D new Byte((byte)5)"; + else if (fieldType.equals("Boolean")) + return " =3D new Boolean(false)"; + else if (fieldType.equals("Character")) + return " =3D new Character('a')"; + else if (fieldType.equals("Short")) + return " =3D new Short((short)5)"; + else if (fieldType.equals("Integer")) + return " =3D new Integer((int)5)"; + else if (fieldType.equals("Long")) + return " =3D new Long((long)5)"; + else if (fieldType.equals("Float")) + return " =3D new Float((float)5)"; + else if (fieldType.equals("Double")) + return " =3D new Double((double)5)"; + else if (fieldType.equals("String")) + return " =3D new String(\"JDO TCK\")"; + else if (fieldType.equals("Locale")) + return " =3D Locale.US"; + else if (fieldType.equals("BigDecimal")) + return " =3D new BigDecimal(100.15)"; + else if (fieldType.equals("BigInteger")) + return " =3D new BigInteger(\"100\")"; + else if (fieldType.equals("Collection")) + return " =3D new HashSet()"; + else if (fieldType.equals("Set")) + return " =3D new HashSet()"; + else if (fieldType.equals("HashSet")) + return " =3D new HashSet()"; + else if (fieldType.equals("Object")) + return " =3D new Object()"; + else if (fieldType.equals("SimpleClass")) + return " =3D new SimpleClass()"; + else if (fieldType.equals("SimpleInterface")) + return " =3D new SimpleClass()"; + else if (fieldType.equals("Date")) + return " =3D new Date()"; + else + throw new Exception("Unsupported FieldType " + fieldType); + } + + private String getImportStatements(String fieldType) + { + if (fieldType.equals("FieldsOfLocale")) + return "import java.util.*;"; + if (fieldType.equals("FieldsOfDate")) + return "import java.util.*;"; + else if (fieldType.equals("FieldsOfBigDecimal")) + return "import java.math.*;"; + else if (fieldType.equals("FieldsOfBigInteger")) + return "import java.math.*;"; + else if (fieldType.equals("FieldsOfCollection")) + return "import java.util.*;"; + else if (fieldType.equals("FieldsOfSet")) + return "import java.util.*;"; + else if (fieldType.equals("FieldsOfHashSet")) + return "import java.util.*;"; + else if (fieldType.indexOf("Collections") >=3D0) + return "import java.util.*;\r\nimport java.math.*;"; + else + return ""; + } + + private boolean isPrimitive(String fieldType) + { + if (Character.isUpperCase(fieldType.charAt(0))) + return false; + else + return true; + } + + private boolean isPersistenceCapable(String fieldModifier) + { + if (fieldModifier.indexOf("static") >=3D 0 + || fieldModifier.indexOf("final") >=3D 0 + || fieldModifier.indexOf("transient") >=3D 0) + return false; + else + return true; + } + + private boolean isStatic(String fieldModifier) + { + if (fieldModifier.indexOf("static") >=3D 0) + return true; + else + return false; + } + private boolean isFinal(String fieldModifier) + { + return fieldModifier.indexOf("final") >=3D 0; + } + private void buildisPersistentArray(boolean value) + { + if(isPersistent.length() !=3D 0) + isPersistent.append(","); + if(value) + isPersistent.append("true"); + else + isPersistent.append("false"); + } + + private void buildisStaticArray(boolean value) + { + if(isStatic.length() !=3D 0) + isStatic.append(","); + if(value) + isStatic.append("true"); + else + isStatic.append("false"); + } + + private void buildisFinalArray(boolean value) + { + if(isFinalArray.length() !=3D 0) + isFinalArray.append(","); + if(value) + isFinalArray.append("true"); + else + isFinalArray.append("false"); + } + + + private void writeisPersistentArray(PrintWriter pw) + { + // have to go through this hoopla because pw.println(fieldSpecs.toStr= ing()); outputs only + // 1024 characters + char [] charArray =3D new char[isPersistent.length()]; + isPersistent.getChars(0,isPersistent.length(),charArray,0); + pw.println(""); + pw.println("public static final boolean [] isPersistent =3D { "); + + int fieldCounter=3D0; + for(int i =3D 0; i < charArray.length; i++) + { + pw.print(charArray[i]); + if(charArray[i] =3D=3D ',') + { + fieldCounter++; + if(fieldCounter =3D=3D 10) + { + pw.println(""); + pw.flush(); + fieldCounter =3D 0; + } + } + } + pw.println(""); + pw.println(" };"); + isPersistent =3D new StringBuffer(2000); + } + + + private void writeisStaticArray(PrintWriter pw) + { + // have to go through this hoopla because pw.println(fieldSpecs.toStr= ing()); outputs only + // 1024 characters + char [] charArray =3D new char[isStatic.length()]; + isStatic.getChars(0,isStatic.length(),charArray,0); + pw.println(""); + pw.println("public static final boolean [] isStatic =3D { "); + + int fieldCounter=3D0; + for(int i =3D 0; i < charArray.length; i++) + { + pw.print(charArray[i]); + if(charArray[i] =3D=3D ',') + { + fieldCounter++; + if(fieldCounter =3D=3D 10) + { + pw.println(""); + pw.flush(); + fieldCounter =3D 0; + } + } + } + pw.println(""); + pw.println(" };"); + isStatic =3D new StringBuffer(2000); + } + private void writeisFinalArray(PrintWriter pw) + { + // have to go through this hoopla because pw.println(fieldSpecs.toStr= ing()); outputs only + // 1024 characters + char [] charArray =3D new char[isFinalArray.length()]; + isFinalArray.getChars(0,isFinalArray.length(),charArray,0); + pw.println(""); + pw.println("public static final boolean [] isFinal =3D { "); + + int fieldCounter=3D0; + for(int i =3D 0; i < charArray.length; i++) + { + pw.print(charArray[i]); + if(charArray[i] =3D=3D ',') + { + fieldCounter++; + if(fieldCounter =3D=3D 10) + { + pw.println(""); + pw.flush(); + fieldCounter =3D 0; + } + } + } + pw.println(""); + pw.println(" };"); + isFinalArray =3D new StringBuffer(2000); + } + + private void buildFieldSpecs(String field) + { + if(fieldSpecs.length() !=3D 0) + fieldSpecs.append(","); + + fieldSpecs.append("\""); + fieldSpecs.append(field.trim()); + fieldSpecs.append("\""); + } + + + private void writeFieldSpecs(PrintWriter pw) + { + // have to go through this hoopla because pw.println(fieldSpecs.toStri= ng()); outputs only + // 1024 characters + char [] charArray =3D new char[fieldSpecs.length()]; + fieldSpecs.getChars(0,fieldSpecs.length(),charArray,0); + pw.println(""); + pw.println(" public static final String [] fieldSpecs =3D { "); + + pw.print(" "); + for(int i =3D 0; i < charArray.length; i++) + { + pw.print(charArray[i]); + if(charArray[i] =3D=3D ',') + { + pw.println(""); + pw.print(" "); + pw.flush(); + } + } + pw.println(""); + pw.println(" };"); + fieldSpecs =3D new StringBuffer(2000); + } + + private void writeMethodGetLength(PrintWriter pw) + { + pw.println(" public int getLength()"); + pw.println(" {"); + pw.println(" return fieldSpecs.length;"); + pw.println(" }"); + } + + private void writeMethodGet(PrintWriter pw, String fieldType, int number= OfFields) + { + pw.println(" public " +fieldType+ " get(int index)"); + pw.println(" {"); + + pw.println(" switch (index)"); + pw.println(" {"); + for(int i =3D 0; i < numberOfFields; i++) + { + pw.println(" case(" + i + "):"); + pw.println(" return " + fieldType + i +";"); + } + pw.println(" default:"); + pw.println(" throw new IndexOutOfBoundsException();"); + pw.println(" }"); + pw.println(" }"); + } + + private void writeMethodGet(PrintWriter pw, String fieldType, String[] f= ieldNames, int numFields) + { + pw.println(" public " +fieldType+ " get(int index)"); + pw.println(" {"); + + pw.println(" switch (index)"); + pw.println(" {"); + for(int i =3D 0; i < numFields; i++) + { + pw.println(" case(" + i + "):"); + pw.println(" return " + fieldNames[i] +";"); + } + pw.println(" default:"); + pw.println(" throw new IndexOutOfBoundsException();"); + pw.println(" }"); + pw.println(" }"); + } + private void writeMethodSet(PrintWriter pw, String fieldType, int number= OfFields) + { + pw.println(" public boolean set(int index," + fieldType + " value"+ = ")"); + pw.println(" {"); + pw.println(" if(fieldSpecs[index].indexOf(\"final\") !=3D -1)"); + pw.println(" return false;"); + + pw.println(" switch (index)"); + pw.println(" {"); + for(int i =3D 0; i < numberOfFields; i++) + { + if(!isFinal[i]) + { + pw.println(" case(" + i + "):"); + pw.println(" " + fieldType + i + "=3D value" + ";"); + pw.println(" break;" ); + } + } + pw.println(" default:"); + pw.println(" throw new IndexOutOfBoundsException();"); + pw.println(" }"); + pw.println(" return true;"); + pw.println(" }"); + } + + private void writeMethodSet(PrintWriter pw, String fieldType, String [] = fieldNames, int numFields) + { + pw.println(" public boolean set(int index," + fieldType + " value"+ = ")"); + pw.println(" {"); + pw.println(" if(fieldSpecs[index].indexOf(\"final\") !=3D -1)"); + pw.println(" return false;"); + + pw.println(" switch (index)"); + pw.println(" {"); + for(int i =3D 0; i < numFields; i++) + { +// if(!isFinal[i]) { + pw.println(" case(" + i + "):"); + pw.println(" " + fieldNames[i] + "=3D value" + ";"); + pw.println(" break;" ); +// } + } + pw.println(" default:"); + pw.println(" throw new IndexOutOfBoundsException();"); + pw.println(" }"); + pw.println(" return true;"); + pw.println(" }"); + } + + + private void writeMethodSetForArray(PrintWriter pw, String fieldType, St= ring [] fieldNames, int numFields) + { + pw.println(" public boolean set(int index," + fieldType + " value"+ = ")"); + pw.println(" {"); + pw.println(" if(fieldSpecs[index].indexOf(\"final\") !=3D -1)"); + pw.println(" return false;"); + + pw.println(" switch (index)"); + pw.println(" {"); + for(int i =3D 0; i < numFields; i++) + { +// if(!isFinal[i]) { + String fieldName =3D fieldNames[i]; + String valueType; + pw.println(" case(" + i + "):"); + int indexOfValueType =3D fieldName.indexOf("Of") + 2; + String valueTypeWithNumber =3D fieldName.substring(indexOfValueTy= pe); + int lastIndexOfValueType =3D 0; + for (int j=3DvalueTypeWithNumber.length() -1; j>=3D0; j--) + { + if (Character.isDigit(valueTypeWithNumber.charAt(j))) + { + continue; + }else { + lastIndexOfValueType =3D j; + break; + } + } + valueType =3D valueTypeWithNumber.substring(0, lastIndexOfValueT= ype+1); + pw.println(" " + fieldNames[i] + "=3D (" +valueType + " []= ) value ;"); + pw.println(" break;" ); +// } + } + pw.println(" default:"); + pw.println(" throw new IndexOutOfBoundsException();"); + pw.println(" }"); + pw.println(" return true;"); + pw.println(" }"); + } + + // generates Collection files for the different collectionTypes + // also, updates the corresponding xml files + // called by generate, after it is done dealing with the generic field t= ypes + void generateCollections() throws Exception + { + final String [] embeddedElements =3D {"", "true", "false"}; + final String [] embeddedElementsForFieldSpec =3D {"", "embedded-elemen= t=3Dtrue", "embedded-element=3Dfalse"}; + for(int i=3D0; i < collectionTypes.length; i++) + { + // Map has a lot of combinations, generate it separately + if(collectionTypes[i].indexOf("Map") >=3D 0 || collectionTypes[i].eq= uals("Hashtable")) + { + generateMapCollection(collectionTypes[i]); + } + else // Array and the other collections + { + String classFile =3D collectionTypes[i] + "Collections"; + FileOutputStream fout =3D new FileOutputStream(classFile + ".java"= ); + PrintWriter pw =3D new PrintWriter(fout); + FileOutputStream xmlFout =3D new FileOutputStream(classFile + ".jd= o=2En"); + PrintWriter xmlPw =3D new PrintWriter(xmlFout); + FileOutputStream xmlFout1 =3D new FileOutputStream(classFile + ".j= do.a"); + PrintWriter xmlPw1 =3D new PrintWriter(xmlFout1); + FileOutputStream xmlFout2 =3D new FileOutputStream(classFile + ".j= do.d"); + PrintWriter xmlPw2 =3D new PrintWriter(xmlFout2); + + startClass(pw, classFile); + startXmlMetaData(xmlPw); + startXmlMetaData(xmlPw1); + startXmlMetaData(xmlPw2); + + startXmlClass(xmlPw, classFile, 0); + startXmlClass(xmlPw1, classFile, 1); + startXmlClass(xmlPw2, classFile, 2); + + int fieldCounter=3D0; + String fieldNames [] =3D new String [elementTypes.length * embedde= dElements.length]; + for(int j=3D0; j < elementTypes.length; j++) + { + if( elementTypes[j].equals("Locale") && collectionTypes[i].equ= als("TreeSet") ) + continue; + for(int k=3D0; k < embeddedElements.length; k++) + { + if(collectionTypes[i].equals("Array")) + { + if(!embeddedElements[k].equals("")) + { + fieldNames[fieldCounter] =3D collectionTypes[i] + "Of" + e= lementTypes[j] + fieldCounter; +// pw.println(" public " + "Object [] "+ fieldNames[fieldC= ounter] +";"); + pw.println(" public " + elementTypes[j] +" [] " + fieldNa= mes[fieldCounter] +";"); + printXmlArrayFieldWithEmbeddedElement(xmlPw, fieldNames[f= ieldCounter], embeddedElements[k]); + printXmlArrayFieldWithEmbeddedElement(xmlPw1, fieldNames[f= ieldCounter], embeddedElements[k]); + printXmlArrayFieldWithEmbeddedElement(xmlPw2, fieldNames[f= ieldCounter], embeddedElements[k]); + buildFieldSpecs(embeddedElementsForFieldSpec[k] + " " + + "public " + elementTypes[j] +" [] " + fiel= dNames[fieldCounter]); // add to the field specs array*/ + + fieldCounter++; + } + } + else // Collection + { + fieldNames[fieldCounter] =3D collectionTypes[i] + "Of" + ele= mentTypes[j] + fieldCounter; + pw.println(" public " + collectionTypes[i] +" "+ fieldNames= [fieldCounter] +";"); + printXmlCollectionFieldWithEmbeddedElement(xmlPw, fieldNames= [fieldCounter], elementsWithPackageInfo[j], + embeddedElements[= k]); + printXmlCollectionFieldWithEmbeddedElement(xmlPw1, fieldName= s[fieldCounter], elementsWithPackageInfo[j], + embeddedElements[= k]); + printXmlCollectionFieldWithEmbeddedElement(xmlPw2, fieldName= s[fieldCounter], elementsWithPackageInfo[j], + embeddedElements[= k]); + buildFieldSpecs(embeddedElementsForFieldSpec[k] + " " + + "public " + collectionTypes[i] +" "+ fieldNa= mes[fieldCounter]); // add to the field specs array*/ + fieldCounter++; + + } + } + } + writeFieldSpecs(pw); + writeMethodGetLength(pw); + writeMethodGet(pw, collectionTypes[i].equals("Array")? "Object [] = " : collectionTypes[i], fieldNames, fieldCounter); + if(collectionTypes[i].equals("Array")) + writeMethodSetForArray(pw, "Object [] ", fieldNames, fieldCounte= r); + else + writeMethodSet(pw, collectionTypes[i], fieldNames, fieldCounter); + + endClass(pw); + pw.close(); + fout.close(); + endXmlClass(xmlPw); + endXmlClass(xmlPw1); + endXmlClass(xmlPw2); + endXmlMetaDeta(xmlPw); + endXmlMetaDeta(xmlPw1); + endXmlMetaDeta(xmlPw2); + xmlPw.close(); + xmlFout.close(); + xmlPw1.close(); + xmlFout1.close(); + xmlPw2.close(); + xmlFout2.close(); + } + } + } + + private void generateMapCollection(String mapName) throws Exception + { + final String [] keyTypes1 =3D {"String"}; + final String [] valueTypes1 =3D {"Object", "SimpleClass", "SimpleInter= face", "String", + "Date", "Locale", "BigDecimal", "BigIntege= r", + "Byte", "Double", "Float", "Integer", "Lon= g", + "Short"}; + final String [] keyTypes2 =3D {"Object", "SimpleClass", "SimpleInterfa= ce", "String", + "Date", "BigDecimal", "BigInteger", + "Byte", "Double", "Float", "Integer", "Lon= g", + "Short"}; + final String [] valueTypes2 =3D {"String"}; + + final String [][] keyTypes =3D {keyTypes1, keyTypes2}; + final String [][] valueTypes =3D {valueTypes1, valueTypes2}; + + String [] classNameArray =3D {mapName + "StringKey" + "Collections", + mapName + "StringValue" + "Collections"}; + + for(int i=3D0; i < classNameArray.length; i++) + { + String classFile =3D classNameArray[i]; + FileOutputStream fout =3D new FileOutputStream(classFile + ".java"); + PrintWriter pw =3D new PrintWriter(fout); + FileOutputStream xmlFout =3D new FileOutputStream(classFile + ".jdo.= n"); + PrintWriter xmlPw =3D new PrintWriter(xmlFout); + FileOutputStream xmlFout1 =3D new FileOutputStream(classFile + ".jdo= .a"); + PrintWriter xmlPw1 =3D new PrintWriter(xmlFout1); + FileOutputStream xmlFout2 =3D new FileOutputStream(classFile + ".jdo= .d"); + PrintWriter xmlPw2 =3D new PrintWriter(xmlFout2); + + startClass(pw, classFile); + startXmlMetaData(xmlPw); + startXmlMetaData(xmlPw1); + startXmlMetaData(xmlPw2); + + startXmlClass(xmlPw, classFile, 0); + startXmlClass(xmlPw1, classFile, 1); + startXmlClass(xmlPw2, classFile, 2); + + fillMapCollection(keyTypes[i], valueTypes[i],mapName, pw, xmlPw, xml= Pw1, xmlPw2); + + endClass(pw); + pw.close(); + fout.close(); + endXmlClass(xmlPw); + endXmlClass(xmlPw1); + endXmlClass(xmlPw2); + endXmlMetaDeta(xmlPw); + endXmlMetaDeta(xmlPw1); + endXmlMetaDeta(xmlPw2); + xmlPw.close(); + xmlFout.close(); + xmlPw1.close(); + xmlFout1.close(); + xmlPw2.close(); + xmlFout2.close(); + } + } + + private void fillMapCollection(String [] keyTypes, String [] valueTypes, + String mapName, PrintWriter pw, PrintWrit= er xmlPw, + PrintWriter xmlPw1, PrintWriter xmlPw2) + { + final String [] embeddedKeys =3D {"", "true", "false"}; + final String [] embeddedValues =3D embeddedKeys; + final String [] embeddedKeyForFieldSpec =3D {"", "embedded-key=3Dtrue"= , "embedded-key=3Dfalse"}; + final String [] embeddedValueForFieldSpec =3D {"", "embedded-value=3Dt= rue", "embedded-value=3Dfalse"}; + + int fieldCounter=3D0; + String fieldNames [] =3D new String [keyTypes.length * embeddedKeys.le= ngth + * valueTypes.length * embeddedValue= s=2Elength]; + for(int i =3D 0; i < keyTypes.length; i++) + { + for(int j =3D 0; j < embeddedKeys.length; j++) + { + for(int k =3D 0; k < valueTypes.length; k++) + { + for(int l =3D 0; l < embeddedValues.length; l++) + { + if( keyTypes[i].equals("") && embeddedKeys[j].equals("") + && valueTypes[k].equals("") && embeddedValues[l].equals("")) + continue; + fieldNames[fieldCounter] =3D mapName+ "Of" + keyTypes[i] +"_"+= valueTypes[k] + fieldCounter; + pw.println(" public " + mapName +" " + fieldNames[fieldCounte= r] +";"); + printXmlMapField(xmlPw, fieldNames[fieldCounter], keyTypes[i],= embeddedKeys[j], + valueTypes[k], embeddedValues[l]); + printXmlMapField(xmlPw1, fieldNames[fieldCounter], keyTypes[i]= , embeddedKeys[j], + valueTypes[k], embeddedValues[l]); + printXmlMapField(xmlPw2, fieldNames[fieldCounter], keyTypes[i]= , embeddedKeys[j], + valueTypes[k], embeddedValues[l]); + buildFieldSpecs(embeddedKeyForFieldSpec[j] + " " + + embeddedValueForFieldSpec[l] + " " + + "public " + mapName +" "+ fieldNames[fieldCoun= ter]); // add to the field specs array*/ + fieldCounter++; + + } + } + } + } + writeFieldSpecs(pw); + writeMethodGetLength(pw); + writeMethodGet(pw, mapName, fieldNames, fieldCounter); + writeMethodSet(pw, mapName, fieldNames, fieldCounter); + } + + public static void main(String[] args) + { + ClassGenerator classGenerator =3D new ClassGenerator(); + try + { + classGenerator.generate(); + classGenerator.generateCollections(); + } + catch (Exception e) + { + System.out.println(e); + e.printStackTrace(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/DeepEqua= lity.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/= apache/jdo/tck/util/DeepEquality.java?view=3Dauto&rev=3D158179 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/DeepEqualit= y=2Ejava (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/util/DeepEqualit= y=2Ejava Fri Mar 18 17:07:39 2005 @@ -0,0 +1,67 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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=20 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * Unless required by applicable law or agreed to in writing, software=20 + * distributed under the License is distributed on an "AS IS" BASIS,=20 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied= .=20 + * See the License for the specific language governing permissions and=20 + * limitations under the License. + */ + +package org.apache.jdo.tck.util; + +/** + * This DeepEquality interface defines a method indicating + * whether some other object is "deep equal to" this object. + *

+ * Two objects are deep equal, if all the fields are deep equal. The + * sematics of deep equal on the fields depends of the field type: + *

    + *
  • fields of type boolean or an integral type are deep + * equal, if they compare true using =3D=3D
  • =20 + *
  • fields of type float and double are deep + * equal, if they are close enough as defined by methods closeEnough + * provided by class EqualityHelper
  • =20 + *
  • fields of Java wrapper classes are equal if their wrapped primitive + * values are deep equal
  • + *
  • fields of type BigDecimal are equal, if compareTo returns 0
  • + *
  • collection fields are deep equal, if they have the same size and + * their corresponding elements compare deep equal after sorting using the + * natural ordering.
  • =20 + *
  • map fields compare deep equal, if they have the same size and both + * keys and values compare deep equal after sorting the entries using the + * natural ordering of the keys.
  • =20 + *
  • fields of type DeepEquality are deep equal, if method=20 + * deepEquals returns true
  • + *
  • fields of other types are deep equal, if method equals + * returns true
  • =20 + *
+ * The EqualityHelper instance passed to the + * deepEquals method keeps track of instances that have + * already been processed to avoid endless recursion for cyclic data + * structures.=20 + * + * @author Michael Bouschen + * @since 1.1 + */ +public interface DeepEquality { + + /**=20 + * Returns true if all the fields of this instance are + * deep equal to the corresponding fields of the specified Employee. + * @param other the object with which to compare. + * @param helper EqualityHelper to keep track of instances that have + * already been processed.=20 + * @return true if all the fields are deep equal; + * false otherwise.=20 + * @throws ClassCastException if the specified instances' type prevents + * it from being compared to this instance.=20 + */ + public boolean deepCompareFields(DeepEquality other, EqualityHelper he= lper); +}