Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/SignInversion.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/SignInversion.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/SignInversion.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/SignInversion.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,127 @@ +/* + * 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.query.operators; + +import java.util.Collection; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Sign Inversion Query Operator + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-29. + *<BR> + *<B>Assertion Description: </B> +The numeric sign inversion operator (<code>-</code>) is supported for all types +as they are defined in the Java language. This includes the following types: +<UL> +<LI><code>byte, short, int, long, char, Byte, Short Integer, Long, Character</code></LI> +<LI><code>float, double, Float, Double</code></LI> +<LI><code>BigDecimal, BigInteger</code></LI></UL> +The operation on object-valued fields of wrapper types (<code>Boolean, Byte, +Short, Integer, Long, Float</code>, and <code>Double</code>), and numeric types +(<code>BigDecimal</code> and <code>BigInteger</code>) +use the wrapped values as operands. + + */ + +public class SignInversion extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-29 (SignInversion) 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(SignInversion.class); + } + + /** */ + public void test() { + pm = getPM(); + + try { + loadPrimitiveTypes(pm); + runTest(pm); + } + finally { + cleanupDatabase(pm, PrimitiveTypes.class); + pm.close(); + pm = null; + } + } + + /** */ + void runTest(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + tx.begin(); + + Collection instance9 = (Collection)pm.newQuery( + PrimitiveTypes.class, "id == 9").execute(); + Collection allOddInstances = (Collection)pm.newQuery( + PrimitiveTypes.class, "booleanNull").execute(); + + runSimplePrimitiveTypesQuery("-id == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-byteNotNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-shortNotNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-intNotNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-longNotNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-floatNotNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-doubleNotNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-byteNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-shortNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-intNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-longNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-floatNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-doubleNull == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-bigDecimal == -9", + pm, instance9, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-bigInteger == -9", + pm, instance9, ASSERTION_FAILED); + + runSimplePrimitiveTypesQuery("-charNull == -79", + pm, allOddInstances, ASSERTION_FAILED); + runSimplePrimitiveTypesQuery("-charNotNull == -79", + pm, allOddInstances, ASSERTION_FAILED); + + tx.commit(); + } +}
Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/StringConcatenation.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/StringConcatenation.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/StringConcatenation.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/StringConcatenation.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,104 @@ +/* + * 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.query.operators; + +import java.util.Collection; +import java.util.HashSet; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.pc.company.Employee; +import org.apache.jdo.tck.pc.company.CompanyModelReader; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> String Concatenation Query Operator + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-27. + *<BR> + *<B>Assertion Description: </B> +The <code>String</code> concatenation operator (<code>+</code>) is supported +for the <code>String</code> type only. + + */ + +public class StringConcatenation extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-27 (StringConcatenation) 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(StringConcatenation.class); + } + + /** */ + public void test() { + pm = getPM(); + + try { + // read test data + CompanyModelReader reader = + loadCompanyModel(pm, "org/apache/jdo/tck/query/company.xml"); + runTest(pm, reader); + } + finally { + cleanupCompanyModel(pm); + pm.close(); + pm = null; + } + } + + /** */ + void runTest(PersistenceManager pm, CompanyModelReader reader) { + Query q; + Object result; + Collection expected; + + Transaction tx = pm.currentTransaction(); + tx.begin(); + + // string literal + string literal + q = pm.newQuery(Employee.class); + q.setFilter("firstname == \"emp1\" + \"First\""); + result = q.execute(); + expected = new HashSet(); + expected.add(reader.getFullTimeEmployee("emp1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + // string field + string literal + q = pm.newQuery(Employee.class); + q.declareParameters("String param"); + q.setFilter("firstname + \"Ext\" == param"); + result = q.execute("emp1FirstExt"); + expected = new HashSet(); + expected.add(reader.getFullTimeEmployee("emp1")); + checkQueryResultWithoutOrder(ASSERTION_FAILED, result, expected); + + tx.commit(); + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/UnaryPlus.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/UnaryPlus.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/UnaryPlus.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/query/operators/UnaryPlus.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,93 @@ +/* + * 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.query.operators; + +import java.util.Collection; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.pc.mylib.PrimitiveTypes; +import org.apache.jdo.tck.query.QueryTest; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Unary Addition Query Operator + *<BR> + *<B>Keywords:</B> query + *<BR> + *<B>Assertion ID:</B> A14.6.2-25. + *<BR> + *<B>Assertion Description: </B> +The unary addition operator (<code>+</code>) is supported for all types as they +are defined in the Java language. This includes the following types: +<UL> +<LI><code>byte, short, int, long, char, Byte, Short Integer, Long, Character</code></LI> +<LI><code>float, double, Float, Double</code></LI> +<LI><code>BigDecimal, BigInteger</code></LI> +</UL> +The operation on object-valued fields of wrapper types <code>(Boolean, Byte, +Short, Integer, Long, Float</code>, and <code>Double</code>), and numeric types +(<code>BigDecimal and BigInteger</code>) use the wrapped values as operands. + + */ + +public class UnaryPlus extends QueryTest { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A14.6.2-25 (UnaryPlus) 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(UnaryPlus.class); + } + + /** */ + public void test() { + pm = getPM(); + + try { + loadPrimitiveTypes(pm); + runTestBinaryAddition(pm); + } + finally { + cleanupDatabase(pm, PrimitiveTypes.class); + pm.close(); + pm = null; + } + } + + /** */ + void runTestBinaryAddition(PersistenceManager pm) { + if (debug) logger.debug("\nExecuting test BinaryAddition() ..."); + + Transaction tx = pm.currentTransaction(); + tx.begin(); + + Collection instance9 = (Collection)pm.newQuery( + PrimitiveTypes.class, "id == 9").execute(); + + runSimplePrimitiveTypesQuery("+id == 9", + pm, instance9, ASSERTION_FAILED); + tx.commit(); + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenCommitted.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenCommitted.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenCommitted.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenCommitted.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,128 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import javax.transaction.Status; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> After Completion Method Called When Committed + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.3-6. + *<BR> + *<B>Assertion Description: </B> +The afterCompletionmethod of the Synchronization instance registered with a Transaction +will be called during the behavior specified for the transaction completion method commit with a value of +Status.STATUS_COMMITTE + */ + + + /* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/11/01 1.0 + */ +public class AfterCompletionMethodCalledWhenCommitted + extends JDO_Test + implements Synchronization { + + private boolean afterCompletionCalled; + private Transaction tx; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.3-6 (AfterCompletionMethodCalledWhenCommitted) 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(AfterCompletionMethodCalledWhenCommitted.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestAfterCompletionMethodCalledWhenCommitted(pm); + + pm.close(); + pm = null; + } + + /** */ + public void beforeCompletion() { + try { + if (debug) + logger.debug("before Complition isActive returns" + + tx.isActive()); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in beforeCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void afterCompletion(int status) { + if (status == javax.transaction.Status.STATUS_COMMITTED) { + afterCompletionCalled = true; + } + else { + fail(ASSERTION_FAILED, + "afterCompletion: incorrect status, expected " + + Status.STATUS_COMMITTED + ", got " + status); + } + } + + /** test transactions.setSynchronization() */ + void runTestAfterCompletionMethodCalledWhenCommitted(PersistenceManager pm) { + tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + + tx.setSynchronization(this); + afterCompletionCalled = false ; + tx.commit(); + tx = null; + + if (!afterCompletionCalled) { + fail(ASSERTION_FAILED, + "commit didn't invoke afterCompletion method"); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenRolledback.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenRolledback.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenRolledback.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/AfterCompletionMethodCalledWhenRolledback.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,128 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import javax.transaction.Status; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> After Completion Method Called When Rolledback + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.3-7. + *<BR> + *<B>Assertion Description: </B> + * The afterCompletion method of the Synchronization instance registered with a + * Transaction will be called after the behavior specified for the method + * rollback with a value of Status.STATUS_ROLLEDBACK. + */ + + + /* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/11/01 1.0 + */ +public class AfterCompletionMethodCalledWhenRolledback + extends JDO_Test + implements Synchronization { + + private boolean afterCompletionCalled; + private Transaction tx; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.3-7 (AfterCompletionMethodCalledWhenRolledback) 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(AfterCompletionMethodCalledWhenRolledback.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestAfterCompletionMethodCalledWhenRolledback(pm); + + pm.close(); + pm = null; + } + + /** */ + public void beforeCompletion() { + try { + if (debug) + logger.debug("before Complition isActive returns :" + + tx.isActive()); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in beforeCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void afterCompletion(int status) { + if (status == javax.transaction.Status.STATUS_ROLLEDBACK) { + afterCompletionCalled = true; + } + else { + fail(ASSERTION_FAILED, + "afterCompletion: incorrect status, expected " + + Status.STATUS_ROLLEDBACK + ", got " + status); + } + } + + /** test transactions.setSynchronization() */ + void runTestAfterCompletionMethodCalledWhenRolledback(PersistenceManager pm) { + tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + + tx.setSynchronization(this); + afterCompletionCalled = false ; + tx.rollback(); + tx = null; + + if (!afterCompletionCalled) { + fail(ASSERTION_FAILED, + "rollback didn't invoke afterCompletion method"); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodCalled.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodCalled.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodCalled.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodCalled.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,119 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import javax.transaction.Status; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Before Completion Method Called + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.3-4. + *<BR> + *<B>Assertion Description: </B> +The beforeCompletion method of the +Synchronization instance registered with a Transaction will be +called during the behavior specified for the transaction completion +method commit. + + */ + + + /* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/15/01 1.0 + */ +public class BeforeCompletionMethodCalled + extends JDO_Test + implements Synchronization { + + private boolean beforeCompletionCalled; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.3-4 (BeforeCompletionMethodCalled) 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(BeforeCompletionMethodCalled.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestBeforeCompletionMethodCalled(pm); + + pm.close(); + pm = null; + } + + /** */ + public void beforeCompletion(){ + beforeCompletionCalled = true; + if (debug) logger.debug ("beforeCompletion called "); + } + + /** */ + public void afterCompletion(int status) { + if (status != javax.transaction.Status.STATUS_COMMITTED) { + fail(ASSERTION_FAILED, + "afterCompletion: incorrect status, expected " + + Status.STATUS_COMMITTED + ", got " + status); + } + } + + /** test transactions.setSynchronization() */ + void runTestBeforeCompletionMethodCalled(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + + tx.setSynchronization(this); + beforeCompletionCalled = false ; + tx.commit(); + tx = null; + + if (!beforeCompletionCalled) { + fail(ASSERTION_FAILED, + "commit didn't invoke beforeCompletion method"); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodNotCalledBeforeRollback.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodNotCalledBeforeRollback.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodNotCalledBeforeRollback.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/BeforeCompletionMethodNotCalledBeforeRollback.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,114 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; +import javax.transaction.Status; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + +/** + *<B>Title:</B> Before Completion Method Not Called Before Rolledback + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.3-5. + *<BR> + *<B>Assertion Description: </B> + The beforeCompletion method of the Synchronization instance registered with a Transaction will not be +called before rollback. + + */ + + + /* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/15/01 1.0 + */ +public class BeforeCompletionMethodNotCalledBeforeRollback + extends JDO_Test + implements Synchronization { + + private boolean beforeCompletionCalled; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.3-5 (BeforeCompletionMethodNotCalledBeforeRollback) 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(BeforeCompletionMethodNotCalledBeforeRollback.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestBeforeCompletionMethodNotCalledBeforeRollback(pm); + + pm.close(); + pm = null; + } + + /** */ + public void beforeCompletion() { + beforeCompletionCalled = true ; + } + + /** */ + public void afterCompletion(int status) { + if (status != javax.transaction.Status.STATUS_ROLLEDBACK) { + fail(ASSERTION_FAILED, + "afterCompletion: incorrect status, expected " + + Status.STATUS_ROLLEDBACK + ", got " + status); + } + } + + /** test transactions.rollback() */ + void runTestBeforeCompletionMethodNotCalledBeforeRollback(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + + tx.setSynchronization(this); + beforeCompletionCalled = false ; + tx.rollback(); + tx = null; + + if (beforeCompletionCalled) { + fail(ASSERTION_FAILED, + "rollback invoked beforeCompletion, but it should not."); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Commit.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Commit.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Commit.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Commit.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,143 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.transactions; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; +import javax.transaction.Status; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Commit + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.4-1. + *<BR> + *<B>Assertion Description: </B> + The <code>commit</code> method performs the following operations: + <UL> + <LI>calls the <code>beforeCompletion</code> method of the + <code>Synchronization</code> instance registered with the + <code>Transaction</code>;</LI> + <LI>flushes dirty persistent instances;</LI> + <LI>notifies the underlying data store to commit the transaction + (this cannot be tested)</LI> + <LI>transitions persistent instances according to the life cycle specification;</LI> + <LI>calls the <code>afterCompletion</code> method of the <code>Synchronization</code> + instance registered with the <code>Transaction</code> with the results of the + data store commit operation.</LI> + </UL> + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/15/01 1.0 + */ +public class Commit extends JDO_Test implements Synchronization { + + private boolean beforeCompletionCalled; + private boolean afterCompletionCalled; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.4-1 (Commit) failed: "; + + /** + * The <code>main</code> is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(Commit.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestCommit(pm); + + pm.close(); + pm = null; + } + + /** */ + public void beforeCompletion(){ + beforeCompletionCalled = true; + if (debug) logger.debug("beforeCompletion called "); + } + + /** */ + public void afterCompletion(int status) { + if (status == Status.STATUS_COMMITTED) { + afterCompletionCalled = true; + if (debug) logger.debug("afterCompletion called\n "); + } + else { + fail(ASSERTION_FAILED, + "afterCompletion: incorrect status, expected " + + Status.STATUS_COMMITTED + ", got " + status); + } + } + + /** test transactions.setSynchronization() */ + void runTestCommit(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + if (!JDOHelper.isDirty(p1)) { + fail(ASSERTION_FAILED, + "P-NEW instance expected to be dirty, JDOHelper.isDirty returns false."); + } + + tx.setSynchronization(this); + beforeCompletionCalled = false; + afterCompletionCalled = false; + tx.commit(); + tx = null; + + if (JDOHelper.isDirty(p1)) { + fail(ASSERTION_FAILED, + "P-NEW instance should transition to HOLLOW or P-NONTX and then it should not be dirty, JDOHelper.isDirty returns true."); + } + if (!beforeCompletionCalled) { + fail(ASSERTION_FAILED, + "commit didn't invoke beforeCompletion method"); + } + if (!afterCompletionCalled) { + fail(ASSERTION_FAILED, + "commit didn't invoke afterCompletion method"); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetOptimistic.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetOptimistic.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetOptimistic.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetOptimistic.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,112 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.PersistenceManagerFactory; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.query.BoundParameterCheck; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Get Optimistic + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.1-2. + *<BR> + *<B>Assertion Description: </B> + The transactions.getOptimistic method + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/09/01 1.0 + */ +public class GetOptimistic extends JDO_Test { + private PersistenceManagerFactory pmf; + private PersistenceManager pm; + private PersistenceManager pm1; + private Transaction transaction; + private boolean flag; + private boolean flag2; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.1-2 (BoundParameterCheck) 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(BoundParameterCheck.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestGetOptimistic(pm); + + pm.close(); + pm = null; + } + + /** test transactions.getOptimistic() */ + public void runTestGetOptimistic(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + if (isOptimisticSupported()) { + tx.setOptimistic(true); + tx.begin(); + if (!tx.getOptimistic()) { + fail(ASSERTION_FAILED, + "tx.getOptimistic() returns false after setting the flag to true."); + } + tx.commit(); + if (!tx.getOptimistic()) { + fail(ASSERTION_FAILED, + "tx.getOptimistic() returns false after setting the flag to true."); + } + } + + tx.setOptimistic(false); + tx.begin(); + if (tx.getOptimistic()) { + fail(ASSERTION_FAILED, + "tx.getOptimistic() returns true after setting the flag to false."); + } + tx.commit(); + if (tx.getOptimistic()) { + fail(ASSERTION_FAILED, + "tx.getOptimistic() returns true after setting the flag to false."); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetPersistenceManager.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetPersistenceManager.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetPersistenceManager.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetPersistenceManager.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,92 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Get Persistence Manager + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.1-1. + *<BR> + *<B>Assertion Description: </B> + The transactions.getPersistenceManager method returns associated persistence manager + if the object parameter ia not null and implements persistenceCapable. + evaluating to true when == is used. + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 9/26/01 1.0 + */ +public class GetPersistenceManager extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.1-1 (GetPersistenceManager) 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(GetPersistenceManager.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestGetPersistenceManager(pm); + + pm.close(); + pm = null; + } + + /** test transactions.getPersistenceManager() */ + void runTestGetPersistenceManager(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + PersistenceManager pm1 = tx.getPersistenceManager(); + tx.commit(); + tx = null; + + if (pm1 != pm) + fail(ASSERTION_FAILED, + "tx.getPersistenceManager() returned unexpected pm, expected " + pm + ", got " + pm1); + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetRetainValues.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetRetainValues.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetRetainValues.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetRetainValues.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,103 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Get Retain Values + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.2-17. + *<BR> + *<B>Assertion Description: </B> + Transaction.getRetainValues returns the currently active setting for the + RetainValues flag. + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/09/01 1.0 + */ +public class GetRetainValues extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-17 (GetRetainValues) 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(GetRetainValues.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestGetRetainValues(pm); + + pm.close(); + pm = null; + } + + /** test transaction.getRetainValues()*/ + public void runTestGetRetainValues(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.setRetainValues(true); + tx.begin(); + if (!tx.getRetainValues()) { + fail(ASSERTION_FAILED, + "tx.getRetainValues returns false after setting the flag to true."); + } + tx.commit(); + if (!tx.getRetainValues()) { + fail(ASSERTION_FAILED, + "tx.getRetainValues returns false after setting the flag to true."); + } + + tx.setRetainValues(false); + tx.begin(); + if (tx.getRetainValues()) { + fail(ASSERTION_FAILED, + "tx.getRetainValues returns true after setting the flag to false."); + } + tx.commit(); + if (tx.getRetainValues()) { + fail(ASSERTION_FAILED, + "tx.getRetainValues returns true after setting the flag to false."); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetSynchronization.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetSynchronization.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetSynchronization.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/GetSynchronization.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,126 @@ +/* + * 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.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.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Get Synchronization + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.3-8. + *<BR> + *<B>Assertion Description: </B> + A call to Transaction.getSynchronization + retrieves the Synchronization instance that has been registered via + setSynchronization. + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/11/01 1.0 + */ +public class GetSynchronization + extends JDO_Test + implements Synchronization { + + private Transaction tx; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.3-8 (GetSynchronization) 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(GetSynchronization.class); + } + + /** */ + public void beforeCompletion(){ + try { + if (debug) + logger.debug("before Complition isActive returns :" + + tx.isActive()); + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in beforeCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void afterCompletion(int status) { + try { + if (debug) + 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 = getPM(); + + runTestGetSynchronization(pm); + + pm.close(); + pm = null; + } + + /** test transactions.getSynchronization() */ + void runTestGetSynchronization(PersistenceManager pm) { + tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + + tx.setSynchronization(this); + Synchronization s = tx.getSynchronization(); + if (s != this) { + fail(ASSERTION_FAILED, + "wrong synchronization instance, expected " + this + ", got " + s); + } + + tx.commit(); + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActive.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActive.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActive.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActive.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,101 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Is Active + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.1-2. + *<BR> + *<B>Assertion Description: </B> + The transactions.isActive method tells whether there is an active + transaction. There will be an active transaction if the begin method + has been executed but neither commit nor rollback has been executed. + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/09/01 1.0 + */ +public class IsActive extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.1-2 (IsActive) 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(IsActive.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestIsActive(pm); + + pm.close(); + pm = null; + } + + /** test transactions.isActive() */ + void runTestIsActive(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + if (!tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns false after tx.begin"); + } + tx.commit(); + + if (tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns true after tx.commit"); + } + + tx.begin(); + tx.rollback(); + if (tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns true after tx.rollback"); + } + + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActiveUntilAfterCompletionMethodCalled.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActiveUntilAfterCompletionMethodCalled.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActiveUntilAfterCompletionMethodCalled.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/IsActiveUntilAfterCompletionMethodCalled.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,128 @@ +/* + * 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.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.pc.mylib.PCPoint; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Is Active Until After Completion Method Called + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.1-3. + *<BR> + *<B>Assertion Description: </B> + Transaction.isActive returns true after the transaction has been started, until the afterCompletion + synchronization method is called + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/09/01 1.0 + */ +public class IsActiveUntilAfterCompletionMethodCalled + extends JDO_Test + implements Synchronization { + + private Transaction tx; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.1-3 (IsActiveUntilAfterCompletionMethodCalled) 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(IsActiveUntilAfterCompletionMethodCalled.class); + } + + /** */ + public void beforeCompletion() { + try { + if (!tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns false in beforeCompletion."); + } + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in beforeCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void afterCompletion(int status) { + try { + if (tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns true in afterCompletion."); + } + } + catch (Exception ex) { + fail(ASSERTION_FAILED, + "tx.isActive called in afterCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void test() { + pm = getPM(); + + runTestIsActiveUntilAfterCompletionMethodCalled(pm); + + pm.close(); + pm = null; + } + + /** test transactions.isActive() */ + void runTestIsActiveUntilAfterCompletionMethodCalled(PersistenceManager pm) { + tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + tx.setSynchronization(this); + if (!tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns false after tx.begin before tx.commit is completed."); + } + + tx.commit(); + if (tx.isActive()) { + fail(ASSERTION_FAILED, + "tx.isActive returns true after tx.commit."); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Rollback.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Rollback.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Rollback.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/Rollback.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,154 @@ +/* + * 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.transactions; + +import javax.jdo.JDOHelper; +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import javax.transaction.Status; +import javax.transaction.Synchronization; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.pc.mylib.PCPoint; +import org.apache.jdo.tck.query.BoundParameterCheck; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Rollback + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.4-2. + *<BR> + *<B>Assertion Description: </B> + The <code>commit</code> method performs the following operations: + <UL> + <LI>transitions persistent instances + according to the life cycle specification;</LI> + <LI>rolls back changes made in this transaction from the data store;</LI> + <LI>calls the <code>afterCompletion</code> method of the + <code>Synchronization</code> instance registered with the + <code>Transaction</code>.</LI> + </UL> + + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/17/01 1.0 + */ +public class Rollback + extends JDO_Test + implements Synchronization { + + private boolean beforeCompletionCalled; + private boolean afterCompletionCalled; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.4-2 (BoundParameterCheck) 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(BoundParameterCheck.class); + } + + /** */ + public void beforeCompletion(){ + beforeCompletionCalled = true; + if (debug) logger.debug ("beforeCompletion called "); + } + + /** */ + public void afterCompletion(int status) { + if (status == javax.transaction.Status.STATUS_ROLLEDBACK) { + afterCompletionCalled = true; + if (debug) logger.debug("afterCompletion called\n "); + } + else { + fail(ASSERTION_FAILED, + "afterCompletion: incorrect status, expected " + + Status.STATUS_ROLLEDBACK + ", got " + status); + } + } + + /** */ + public void test() { + pm = getPM(); + + runTestRollback(pm); + + pm.close(); + pm = null; + } + + /** test transactions.setSynchronization() */ + void runTestRollback(PersistenceManager pm) { + Transaction tx = pm.currentTransaction(); + try { + tx.begin(); + PCPoint p1 = new PCPoint(1,3); + pm.makePersistent(p1); + tx.commit(); + + tx.begin(); + p1.setX(55); + + if (!JDOHelper.isDirty(p1)) { + fail(ASSERTION_FAILED, + "JDOHelper.isDirty returns false when called for dirty instance."); + } + + tx.setSynchronization(this); + beforeCompletionCalled = false; + afterCompletionCalled = false ; + tx.rollback(); + + if (JDOHelper.isDirty(p1)) { + fail(ASSERTION_FAILED, + "P-NEW instance should transition to HOLLOW or P-NONTX and then it should not be dirty, JDOHelper.isDirty returns true."); + } + int x = p1.getX(); + if (x != 1) { + fail(ASSERTION_FAILED, + "tx.rollback should rollback change of ip1.x, expected 1, got " + x); + } + + if (beforeCompletionCalled) { + fail(ASSERTION_FAILED, + "rollback did invoke beforeCompletion method."); + } + if (!afterCompletionCalled) { + fail(ASSERTION_FAILED, + "commit didn't invoke afterCompletion method."); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalRead.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalRead.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalRead.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalRead.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,155 @@ +/* + * 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.transactions; + +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; + +import javax.jdo.PersistenceManager; +import javax.jdo.Query; +import javax.jdo.Transaction; + +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; + + +/** + *<B>Title:</B> Set Nontransactional Read + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.2-9. + *<BR> + *<B>Assertion Description: </B> + If an implementation supports nontransactional read, then a call to + <code>Transaction.setNontransactionalRead</code> with a parameter value of + <code>true</code> will set the flag to <code>true</code> and allows persistent + instances to be read outside of a transaction. + Queries and navigation will be allowed without an active transaction. + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/18/01 1.0 + */ +public class SetNontransactionalRead extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-9 (SetNontransactionalRead) 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(SetNontransactionalRead.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestSetNontransactionalRead(pm); + + pm.close(); + pm = null; + } + + /** test transactions.setNonteansactionalRead() */ + public void runTestSetNontransactionalRead(PersistenceManager pm) { + if (!isNontransactionalReadSupported()) { + if (debug) + logger.debug("Implementation does not support non transactional read"); + return; + } + + Transaction tx = pm.currentTransaction(); + try { + tx.setNontransactionalRead(true); + tx.begin(); + Company c = new Company(1L, "MyCompany", new Date(), null); + Department d = new Department(999, "MyDepartment", c); + pm.makePersistent(c); + pm.makePersistent(d); + Object oid = pm.getObjectId(d); + if (!tx.getNontransactionalRead()) { + fail(ASSERTION_FAILED, + "tx.getNontransactionalRead returns false after setting the flag to true."); + } + tx.commit(); + if (!tx.getNontransactionalRead()) { + fail(ASSERTION_FAILED, + "tx.getNontransactionalRead returns false after setting the flag to true."); + } + + // make sure transaction is not active + if (tx.isActive()) { + fail(ASSERTION_FAILED, + "transaction still active after tx.commit."); + } + tx = null; + + // read department + d = (Department)pm.getObjectById(oid, true); + long deptid = d.getDeptid(); + if (deptid != 999) { + fail("Reading department outside of a transaction returns unexpected value of d.deptid, expected 999, got " + deptid); + } + + // navigate from department to company + c = d.getCompany(); + if (c == null) { + fail("Navigating from department to company outside of a transaction returns null."); + } + String companyName = c.getName(); + if (!"MyCompany".equals(companyName)) { + fail("Navigated company returns unexpected value of c.name, expected MyCompany, got " + companyName); + } + + // run query + Query q = pm.newQuery(Department.class); + q.setFilter("name == \"MyDepartment\""); + Collection result = (Collection)q.execute(); + Iterator i = result.iterator(); + if (!i.hasNext()) { + fail(ASSERTION_FAILED, + "Query outside of a transaction returned empty collection."); + } + d = (Department)i.next(); + String deptName = d.getName(); + if (!"MyDepartment".equals(deptName)) { + fail("Department in query result returns unexpected value of d.name, expected MyDepartment, got " + deptName); + } + if (i.hasNext()) { + fail(ASSERTION_FAILED, + "Query outside of a transaction returns more than one instance."); + } + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadCalledDuringTxCompletion.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadCalledDuringTxCompletion.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadCalledDuringTxCompletion.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadCalledDuringTxCompletion.java Fri Mar 18 17:07:39 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.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; + + +/** + *<B>Title:</B> Set Nontransactional Read Called During TX Completion + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.2-1. + *<BR> + *<B>Assertion Description: </B> + If the setNontransactionalRead method of the Transaction interface is + called during commit or rollback processing (within the beforeCompletion and afterCompletion + synchronization methods), a JDOUserException is thrown. + + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/18/01 1.0 + */ +public class SetNontransactionalReadCalledDuringTxCompletion + extends JDO_Test + implements Synchronization { + + private Transaction tx; + + private boolean nonTransactionalReadFlag; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-1 (SetNontransactionalReadCalledDuringTxCompletion) 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(SetNontransactionalReadCalledDuringTxCompletion.class); + } + + /** */ + public void beforeCompletion() { + if (debug) logger.debug("beforeCompletion."); + try { + tx.setNontransactionalRead(nonTransactionalReadFlag); + fail(ASSERTION_FAILED, + "tx.setNontransactionalRead 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.setNontransactionalRead called in beforeCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void afterCompletion(int status) { + if (debug) logger.debug("afterCompletion."); + try { + tx.setNontransactionalRead(nonTransactionalReadFlag); + } + 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.setNontransactionalRead called in afterCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void test() { + pm = getPM(); + + runTestSetNontransactionalReadCalledDuringTxCompletion(pm); + + pm.close(); + pm = null; + } + + /** test transactions.setNonteansactionalRead() */ + public void runTestSetNontransactionalReadCalledDuringTxCompletion(PersistenceManager pm) { + /** + if (!isNontransactionalReadSupported()) { + if (verbose) println("Implementation does not support non transactional read"); + return; + } + */ + tx = pm.currentTransaction(); + try { + tx.setSynchronization(this); + + nonTransactionalReadFlag = false; + tx.begin(); + tx.commit(); + + if (isNontransactionalReadSupported()) { + nonTransactionalReadFlag = true; + tx.begin(); + tx.commit(); + } + + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadTrueWhenNotSupported.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadTrueWhenNotSupported.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadTrueWhenNotSupported.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalReadTrueWhenNotSupported.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,94 @@ +/* + * 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.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; + + +/** + *<B>Title:</B> Set Nontransactional Read True When Not Supported + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.2-5. + *<BR> + *<B>Assertion Description: </B> + If an implementation does not support nontransactional read, then a + call to Transaction.setNontransactionalRead with a parameter value of true will + * cause a JDOUnsupportedOptionException to be thrown. + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/18/01 1.0 + */ +public class SetNontransactionalReadTrueWhenNotSupported extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-5 (SetNontransactionalReadTrueWhenNotSupported) 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(SetNontransactionalReadTrueWhenNotSupported.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestSetNontransactionalReadTrueWhenNotSupported(pm); + + pm.close(); + pm = null; + } + + /* test transactions.setNonteansactionalRead() + * + */ + public void runTestSetNontransactionalReadTrueWhenNotSupported( + PersistenceManager pm) { + if (isNontransactionalReadSupported()) { + if (debug) + logger.debug("Implementation does support non transactional read."); + return; + } + + Transaction tx = pm.currentTransaction(); + try { + tx.setNontransactionalRead(true); + fail(ASSERTION_FAILED, + "tx.setNontransactionalRead(true) should throw JDOUnsupportedOptionException, if the implementation does not support non transactional read."); + } + 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/SetNontransactionalWriteCalledDuringTxCompletion.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalWriteCalledDuringTxCompletion.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalWriteCalledDuringTxCompletion.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetNontransactionalWriteCalledDuringTxCompletion.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,140 @@ +/* + * 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.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; + + +/** + *<B>Title:</B> Set Nontransactional Write Called During TX Completion + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.2-1. + *<BR> + *<B>Assertion Description: </B> + If the setNontransactionalWrite method of the Transaction interface is + called during commit or rollback processing (within the beforeCompletion + and afterCompletion synchronization methods), a JDOUserException is thrown. + + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/18/01 1.0 + */ +public class SetNontransactionalWriteCalledDuringTxCompletion + extends JDO_Test + implements Synchronization { + + private Transaction tx; + + private boolean nonTransactionalWriteFlag; + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-2 (SetNontransactionalWriteCalledDuringTxCompletion) 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(SetNontransactionalWriteCalledDuringTxCompletion.class); + } + + /** */ + public void beforeCompletion() { + if (debug) logger.debug("beforeCompletion."); + try { + tx.setNontransactionalWrite(nonTransactionalWriteFlag); + fail(ASSERTION_FAILED, + "tx.setNontransactionalWrite 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.setNontransactionalWrite called in beforeCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void afterCompletion(int status) { + if (debug) logger.debug("afterCompletion."); + try { + tx.setNontransactionalWrite(nonTransactionalWriteFlag); + } + 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.setNontransactionalWrite called in afterCompletion throws unexpected exception: " + ex); + } + } + + /** */ + public void test() { + pm = getPM(); + + runTestSetNontransactionalWriteCalledDuringTxCompletion(pm); + + pm.close(); + pm = null; + } + + /** test transactions.setNonteansactionalWrite() */ + public void runTestSetNontransactionalWriteCalledDuringTxCompletion(PersistenceManager pm) { + tx = pm.currentTransaction(); + try { + tx.setSynchronization(this); + + nonTransactionalWriteFlag = false; + tx.begin(); + tx.commit(); + + if (isNontransactionalWriteSupported()) { + nonTransactionalWriteFlag = true; + tx.begin(); + tx.commit(); + } + else if (debug) + logger.debug("Implementation does not support nontransactional write"); + + tx = null; + } + finally { + if ((tx != null) && tx.isActive()) + tx.rollback(); + } + } +} Added: incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetOptimistic.java URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetOptimistic.java?view=auto&rev=158179 ============================================================================== --- incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetOptimistic.java (added) +++ incubator/jdo/trunk/tck11/test/java/org/apache/jdo/tck/transactions/SetOptimistic.java Fri Mar 18 17:07:39 2005 @@ -0,0 +1,90 @@ +/* + * 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.transactions; + +import javax.jdo.PersistenceManager; +import javax.jdo.Transaction; + +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *<B>Title:</B> Set Optimistic + *<BR> + *<B>Keywords:</B> transactions + *<BR> + *<B>Assertion ID:</B> A13.4.2-14. + *<BR> + *<B>Assertion Description: </B> + A call to Transaction.setOptimistic causes the optimistic setting passed to replace the optimistic setting + currently active, if the Optimistic optional feature is supported. + + */ + + +/* + * Revision History + * ================ + * Author : Date : Version + * Azita Kamangar 10/09/01 1.0 + */ +public class SetOptimistic extends JDO_Test { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-14 (SetOptimistic) 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(SetOptimistic.class); + } + + /** */ + public void test() { + pm = getPM(); + + runTestSetOptimistic(pm); + + pm.close(); + pm = null; + } + + /** */ + void runTestSetOptimistic(PersistenceManager pm) { + if (!isOptimisticSupported()) { + if (debug) logger.debug("Optimistic not supported."); + return; + } + + Transaction tx = pm.currentTransaction(); + boolean orig = tx.getOptimistic(); + tx.setOptimistic(!orig); + if (tx.getOptimistic() == orig) { + fail(ASSERTION_FAILED, + "changing the optimistic flag by calling tx.setOptimistic does not have a effect."); + } + if ((tx != null) && tx.isActive()) { + tx.rollback(); + } + } +} +