db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r384391 - in /db/jdo/trunk/tck20/src: conf/ java/org/apache/jdo/tck/api/persistencemanager/detach/ java/org/apache/jdo/tck/pc/shoppingcart/
Date Thu, 09 Mar 2006 00:56:45 GMT
Author: clr
Date: Wed Mar  8 16:56:41 2006
New Revision: 384391

URL: http://svn.apache.org/viewcvs?rev=384391&view=rev
Log:
JDO-272 Added tests for detach behavior

Added:
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAllOnCommit.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttach.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttachDirty.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachCopy.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachSerialize.java
Modified:
    db/jdo/trunk/tck20/src/conf/configurations.list
    db/jdo/trunk/tck20/src/conf/detach.conf
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java

Modified: db/jdo/trunk/tck20/src/conf/configurations.list
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/conf/configurations.list?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/conf/configurations.list (original)
+++ db/jdo/trunk/tck20/src/conf/configurations.list Wed Mar  8 16:56:41 2006
@@ -3,6 +3,7 @@
                  jdohelper.conf \
                  pm.conf \
                  pmf.conf \
+                 detach.conf \
                  enhancement.conf \
                  extents.conf \
                  fetchplan.conf \

Modified: db/jdo/trunk/tck20/src/conf/detach.conf
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/conf/detach.conf?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/conf/detach.conf (original)
+++ db/jdo/trunk/tck20/src/conf/detach.conf Wed Mar  8 16:56:41 2006
@@ -4,6 +4,10 @@
 jdo.tck.mapping = 8
 jdo.tck.classes = \
     org.apache.jdo.tck.api.jdohelper.IsDetached \
-    org.apache.jdo.tck.api.persistencemanager.detach.SetDetachAllOnCommit \
-    org.apache.jdo.tck.api.persistencemanager.detach.GetDetachAllOnCommit
+    org.apache.jdo.tck.api.persistencemanager.detach.DetachAllOnCommit \
+    org.apache.jdo.tck.api.persistencemanager.detach.DetachAttach \
+    org.apache.jdo.tck.api.persistencemanager.detach.DetachAttachDirty \
+    org.apache.jdo.tck.api.persistencemanager.detach.DetachCopy \
+    org.apache.jdo.tck.api.persistencemanager.detach.DetachSerialize \
+    org.apache.jdo.tck.api.persistencemanager.detach.SetDetachAllOnCommit
 jdo.tck.requiredOptions =

Added: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAllOnCommit.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAllOnCommit.java?rev=384391&view=auto
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAllOnCommit.java
(added)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAllOnCommit.java
Wed Mar  8 16:56:41 2006
@@ -0,0 +1,81 @@
+/*
+ * 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.api.persistencemanager.detach;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ * <B>Title:</B> Test DetachAllOnCommit
+ * <BR>
+ * <B>Keywords:</B> DetachAllOnCommit detach
+ * <BR>
+ * <B>Assertion IDs:</B> 
+ * <BR>
+ * <B>Assertion Description: </B>
+With this flag set to true, during beforeCompletion 
+all cached instances are prepared 
+for detachment according to the fetch plan 
+in effect at commit. Loading fields and unload- 
+ing fields required by the fetch plan 
+is done after calling the userÕs beforeCompletion 
+callback. During afterCompletion, before calling 
+the userÕs afterCompletion callback, all detachable 
+persistent instances in the cache transition 
+to detached; non-detachable persistent instances 
+transition to transient; and detachable instances can be serialized 
+as detached instances. Transient transactional instances 
+are unaffected by this flag.
+ */
+public class DetachAllOnCommit extends DetachTest {
+    
+    private static final String ASSERTION_FAILED = 
+            "Assertion A12.6.8 (DetachAllOnCommit) 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(DetachAllOnCommit.class);
+    }
+
+    /** */
+    public void testDetachAllOnCommit() {
+        getPM().currentTransaction().begin();
+        setCartFetchGroups();
+        pm.retrieveAll(cartClosure);
+        pm.setDetachAllOnCommit(true);
+        pm.currentTransaction().commit();
+        checkCartValues(ASSERTION_FAILED + 
+                "after commit with DetachAllOnCommit," + NL, cart1);
+        failOnError();
+    }
+
+}

Added: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttach.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttach.java?rev=384391&view=auto
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttach.java
(added)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttach.java
Wed Mar  8 16:56:41 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.api.persistencemanager.detach;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ * <B>Title:</B> Test DetachAttach
+ * <BR>
+ * <B>Keywords:</B> makePersistent detach
+ * <BR>
+ * <B>Assertion IDs:</B> 
+ * <BR>
+ * <B>Assertion Description: </B>
+For a detached instance, they locate or create a persistent 
+instance with the same JDO identity as the detached instance
+ */
+public class DetachAttach extends DetachTest {
+    
+    private static final String ASSERTION_FAILED = 
+            "Assertion A12.6.8 (DetachAttach) 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(DetachAttach.class);
+    }
+
+    /** */
+    public void testAttachClean() {
+        Cart detachedCart = createDetachedInstance(ASSERTION_FAILED);
+        pm.currentTransaction().begin();
+        Cart attachedCart = (Cart)pm.makePersistent(detachedCart);
+        checkCartValues(ASSERTION_FAILED +
+                "after attach," + NL, attachedCart);
+        pm.currentTransaction().commit();
+        failOnError();
+    }
+
+}

Added: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttachDirty.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttachDirty.java?rev=384391&view=auto
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttachDirty.java
(added)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachAttachDirty.java
Wed Mar  8 16:56:41 2006
@@ -0,0 +1,78 @@
+/*
+ * 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.api.persistencemanager.detach;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ * <B>Title:</B> Test DetachAttach
+ * <BR>
+ * <B>Keywords:</B> makePersistent detach dirty
+ * <BR>
+ * <B>Assertion IDs:</B> 
+ * <BR>
+ * <B>Assertion Description: </B>
+For a detached instance, they locate or create a persistent 
+instance with the same JDO identity as the detached instance, 
+and merge the persistent 
+state of the detached instance into the persistent instance. 
+ */
+public class DetachAttachDirty extends DetachTest {
+    
+    private static final String ASSERTION_FAILED = 
+            "Assertion A12.6.8 (DetachAttachDirty) 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(DetachAttach.class);
+    }
+
+    /** */
+    public void testAttachDirty() {
+        Cart detachedCart = createDetachedInstance(ASSERTION_FAILED);
+        pm.currentTransaction().begin();
+        cartEntry1.setQuantity(500);
+        goldenCartEntry.setQuantity(500);
+        Cart attachedCart = (Cart)pm.makePersistent(detachedCart);
+        checkCartValues(ASSERTION_FAILED +
+                "after attach," + NL, attachedCart, true);
+        pm.currentTransaction().commit();
+        pm.currentTransaction().begin();
+        Cart persistentCart = (Cart)pm.getObjectById(cart1oid);
+        checkCartValues(ASSERTION_FAILED +
+                "after attach, commit, begin, getObjectById," + NL, 
+                persistentCart, true);
+        pm.currentTransaction().commit();
+        failOnError();
+    }
+}

Added: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachCopy.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachCopy.java?rev=384391&view=auto
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachCopy.java
(added)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachCopy.java
Wed Mar  8 16:56:41 2006
@@ -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.api.persistencemanager.detach;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ * <B>Title:</B> Test DetachCopy
+ * <BR>
+ * <B>Keywords:</B> detachCopy detach
+ * <BR>
+ * <B>Assertion IDs:</B> 
+ * <BR>
+ * <B>Assertion Description: </B>
+For each instance in the parameter Collection, a 
+corresponding detached copy is returned. Each field in the 
+persistent instance is handled based on its type and whether the 
+field is contained in the fetch group for the persistence-capable 
+class. If there are duplicates in the parameter Collection, 
+the corresponding detached copy is used for each such duplicate.  
+ */
+public class DetachCopy extends DetachTest {
+    
+    private static final String ASSERTION_FAILED = 
+            "Assertion A12.6.8 (DetachCopy) 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(DetachCopy.class);
+    }
+
+    /** */
+    public void testDetachCopy() {
+        getPM().currentTransaction().begin();
+        setCartFetchGroups();
+        //pm.retrieveAll(cartClosure);
+        Cart cartDetached = (Cart)pm.detachCopy(cart1);
+        checkCartValues(ASSERTION_FAILED + 
+                "after detachCopy," + NL, cartDetached);
+        pm.currentTransaction().commit();
+        failOnError();
+    }
+
+    /** */
+    public void testDetachCopyAllCollection() {
+        getPM().currentTransaction().begin();
+        setCartFetchGroups();
+        //pm.retrieveAll(cartClosure);
+        Collection instances = new HashSet();
+        instances.add(cart1);
+        Collection detached = pm.detachCopyAll(instances);
+        Cart cartDetached = (Cart)detached.iterator().next();
+        checkCartValues(ASSERTION_FAILED + 
+                "after detachCopyAll(Collection)," + NL, cartDetached);
+        pm.currentTransaction().commit();
+        failOnError();
+    }
+
+    /** */
+    public void testDetachCopyAllArray() {
+        getPM().currentTransaction().begin();
+        setCartFetchGroups();
+        //pm.retrieveAll(cartClosure);
+        Object[] instances = new Object[]{cart1};
+        Object[] detached = pm.detachCopyAll(instances);
+        Cart cartDetached = (Cart)detached[0];
+        checkCartValues(ASSERTION_FAILED + 
+                "after detachCopyAll(Object[])," + NL, cartDetached);
+        pm.currentTransaction().commit();
+        failOnError();
+    }
+
+}

Added: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachSerialize.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachSerialize.java?rev=384391&view=auto
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachSerialize.java
(added)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachSerialize.java
Wed Mar  8 16:56:41 2006
@@ -0,0 +1,108 @@
+/*
+ * 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.api.persistencemanager.detach;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Transaction;
+
+import org.apache.jdo.tck.pc.shoppingcart.Cart;
+
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+/**
+ * <B>Title:</B> Test DetachSerialize
+ * <BR>
+ * <B>Keywords:</B> serialize detach
+ * <BR>
+ * <B>Assertion IDs:</B> 
+ * <BR>
+ * <B>Assertion Description: </B>
+The JDO 1.0 specification requires that serialized instances 
+be made ready for serialization 
+by instantiating all serializable persistent fields 
+before calling writeObject. For binary- 
+compatible implementations, this is done by the enhancer 
+adding a call to the StateManager prior to invoking the user's 
+writeObject method. 
+The behavior is the same in 
+JDO 2.0, with the additional requirement that restored 
+detachable serialized instances are 
+treated as detached instances.  
+ */
+public class DetachSerialize extends DetachTest {
+    
+    private static final String ASSERTION_FAILED = 
+            "Assertion A12.6.8 (DetachSerialize) 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(DetachSerialize.class);
+    }
+
+    /** */
+    public void testDetachSerialize() {
+        getPM().currentTransaction().begin();
+        setCartFetchGroups();
+        //pm.retrieveAll(cartClosure);
+        Cart cartDetached = (Cart)detachClosure(cart1);
+        checkCartValues(ASSERTION_FAILED + "after deserializing cart," + NL,
+                cartDetached);
+        pm.currentTransaction().commit();
+        failOnError();
+    }
+
+    /** Detach the parameter instance.
+     */
+    protected Object detachClosure(Object pc) {
+        byte[] cartStream = serialize(pc);
+        return deserialize(cartStream);
+    }
+    /** */
+
+    private byte[] serialize(Object root) {
+        try {
+            ByteArrayOutputStream baos = 
+                    new ByteArrayOutputStream();
+            ObjectOutputStream oos = new ObjectOutputStream(baos);
+            oos.writeObject(root);
+            return baos.toByteArray();
+        } catch (Exception ex) {
+            fail(ASSERTION_FAILED + "serializing cart:" + ex.toString());
+            return null; // will not be reached
+        }
+    }
+
+    private Object deserialize(byte[] stream) {
+        try {
+            ByteArrayInputStream bais = 
+                    new ByteArrayInputStream(stream);
+            ObjectInputStream ois = new ObjectInputStream(bais);
+            return ois.readObject();
+        } catch (Exception ex) {
+            fail(ASSERTION_FAILED + "deserializing cart:" + ex.toString());
+            return null; // will not be reached
+        }
+    }
+}

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
(original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/DetachTest.java
Wed Mar  8 16:56:41 2006
@@ -16,6 +16,11 @@
 
 package org.apache.jdo.tck.api.persistencemanager.detach;
 
+import java.util.Iterator;
+
+import javax.jdo.FetchPlan;
+import javax.jdo.JDOHelper;
+
 import org.apache.jdo.tck.JDO_Test;
 import org.apache.jdo.tck.pc.shoppingcart.CartEntry;
 import org.apache.jdo.tck.pc.shoppingcart.Cart;
@@ -27,16 +32,147 @@
 /**
  *
  */
-public class DetachTest extends JDO_Test {
+public abstract class DetachTest extends JDO_Test {
 
+    protected Cart cart1;
+    protected CartEntry cartEntry1;
+    protected Product product1;
+    
+    protected Object cart1oid;
+    
+    protected Cart goldenCart;
+    protected CartEntry goldenCartEntry;
+    
+    protected Object[] cartClosure;
+    
+    protected final static String CART_ENTRIES = "Cart.entries";
+    protected final static String CARTENTRY_CART = "CartEntry.cart";
+    protected final static String CARTENTRY_PRODUCT = "CartEntry.product";
+    protected final static String[] CART_FETCH_GROUPS = new String[]
+        {FetchPlan.DEFAULT, CART_ENTRIES, CARTENTRY_CART, CARTENTRY_PRODUCT};
+    
     /** Creates a new instance of DetachTest */
     public DetachTest() {
     }
 
+    /** */
     protected void localSetUp() {
         addTearDownClass(CartEntry.class);
         addTearDownClass(Cart.class);
         addTearDownClass(Product.class);
         addTearDownClass(Undetachable.class);
+        
+        Product goldenProduct = new Product("PRODUCT1", "Product 1");
+        goldenCart = new Cart("142857");
+        goldenCartEntry = 
+                goldenCart.newCartEntry(goldenProduct, 100);
+
+        product1 = new Product("PRODUCT1", "Product 1");
+        cart1 = new Cart("142857");
+        cartEntry1 = new CartEntry(
+                cart1, goldenCartEntry.getId(), product1, 100);
+        cartClosure = new Object[]
+            {cart1, cartEntry1, product1};
+        
+        getPM().currentTransaction().begin();
+        pm.makePersistent(cart1);
+        cart1oid = pm.getObjectId(cart1);
+        pm.currentTransaction().commit();
+    }
+
+    /** */
+    protected void setCartFetchGroups() {
+        FetchPlan fp = getPM().getFetchPlan();
+        fp.setGroups(CART_FETCH_GROUPS);
+        fp.setMaxFetchDepth(2);
+    }
+
+    /** */
+    protected void checkState(String location, Object obj, 
+            boolean persistent) {
+        if(persistent) {
+            if (JDOHelper.isPersistent(obj))
+                return;
+        } else if (JDOHelper.isDetached(obj))
+                return;
+        appendMessage(location +
+                " should be " + 
+                (persistent?"persistent":"detached") + 
+                " but is not. The object state is: " +
+                states[currentState(obj)] + " " + getStateOfInstance(obj));
+    }
+
+    /** */
+    protected void reportDifference(String location, 
+            long expected, long actual) {
+        appendMessage(location + NL +
+                "expected: " + expected + NL +
+                "actual: " + actual);
+    }
+
+    /** */
+    protected void reportDifference(String location, 
+            Object expected, Object actual) {
+        appendMessage(location + NL +
+                "expected: " + expected + NL +
+                "actual: " + actual);
+    }
+
+    /** */
+    protected void checkCartValues(String location, Cart cart) {
+        checkCartValues(location, cart, false);
+    }
+
+    /** */
+    protected void checkCartValues(String location, Cart cart,
+            boolean persistent) {
+        checkState(location + "Cart instance", cart, persistent);
+        if (!goldenCart.getCustomerId().equals(cart.getCustomerId()))
+            reportDifference(location + 
+                " differences in cart.customerId", 
+                goldenCart.getCustomerId(), cart.getCustomerId());
+        Iterator goldenCartEntries = goldenCart.getEntries();
+        Iterator cartEntries = cart.getEntries();
+        while (cartEntries.hasNext()) {
+            CartEntry goldenCartEntry = (CartEntry)goldenCartEntries.next();
+            CartEntry cartEntry = (CartEntry)cartEntries.next();
+            checkState(location + "CartEntry instance", cartEntry,
+                    persistent);
+            if (cartEntry.getCart() != cart) {
+                reportDifference(location +
+                        " incorrect value for cartEntry.cart",
+                        cart, cartEntry.getCart());
+            }
+            if (goldenCartEntry.getId() != cartEntry.getId()) 
+                reportDifference(location + 
+                    " differences in cartEntry.id", 
+                    goldenCartEntry.getId(), cartEntry.getId());
+            if (goldenCartEntry.getQuantity() != cartEntry.getQuantity()) 
+                reportDifference(location + 
+                    " differences in cartEntry.quantity", 
+                    goldenCartEntry.getQuantity(), cartEntry.getQuantity());
+            Product goldenProduct = goldenCartEntry.getProduct();
+            Product product = cartEntry.getProduct();
+            checkState(location + "Product instance", product,
+                    persistent);
+            if (!goldenProduct.getDescription()
+                    .equals(product.getDescription()))
+                reportDifference(location + 
+                    " differences in product.description", 
+                    goldenProduct.getDescription(), product.getDescription());
+        }
+    }
+
+    /** */
+    protected Cart createDetachedInstance(String ASSERTION_FAILED) {
+        getPM().currentTransaction().begin();
+        setCartFetchGroups();
+        pm.retrieveAll(cartClosure);
+        pm.setDetachAllOnCommit(true);
+        pm.currentTransaction().commit();
+        checkCartValues(ASSERTION_FAILED + 
+                "after commit with DetachAllOnCommit,", cart1);
+        failOnError();
+        return cart1;
     }
 }

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
(original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/api/persistencemanager/detach/SetDetachAllOnCommit.java
Wed Mar  8 16:56:41 2006
@@ -23,14 +23,16 @@
 /**
  * <B>Title:</B> Test SetDetachAllOnCommit
  * <BR>
- * <B>Keywords:</B> KEYWORDS
+ * <B>Keywords:</B> DetachAllOnCommit commit detach
  * <BR>
- * <B>Assertion IDs:</B> A12.6.8-1
+ * <B>Assertion IDs:</B> A12.6.8-1, A12.6.8-2
  * <BR>
  * <B>Assertion Description: </B>
  * We define a new property called DetachAllOnCommit
  * PersistenceManager.setDetachAllOnCommit(boolean detachAllOnCommit)
  * sets the DetachAllOnCommit property
+ * PersistenceManager.getDetachAllOnCommit()
+ * The value of the DetachAllOnCommit flag is returned. 
  */
 public class SetDetachAllOnCommit extends DetachTest {
     

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Cart.java Wed Mar  8 16:56:41
2006
@@ -72,6 +72,10 @@
         entries.add(ce);
     }
 
+    public Iterator getEntries() {
+        return entries.iterator();
+    }
+
     public String getCustomerId() {
         return customerId;
     }

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/CartEntry.java Wed Mar
 8 16:56:41 2006
@@ -44,10 +44,10 @@
         this(cart, id, product, 1);
     }
     public CartEntry(Cart cart, long id, Product product, int quantity) {
-        setCart(cart);
         setId(id);
         setProduct(product);
         setQuantity(quantity);
+        cart.addCartEntry(this);
     }
 
     public long getId() {

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java?rev=384391&r1=384390&r2=384391&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/shoppingcart/Product.java Wed Mar  8
16:56:41 2006
@@ -34,6 +34,13 @@
         setSku(sku);
     }
 
+    /** Constructor with sku and description
+     */
+    public Product(String sku, String description) {
+        this(sku);
+        setDescription(description);
+    }
+
     public String getDescription() {
         return description;
     }



Mime
View raw message