openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r562985 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple: TestEntityManagerClear.java TestEntityManagerMerge.java
Date Sun, 05 Aug 2007 23:20:11 GMT
Author: kwsutter
Date: Sun Aug  5 16:20:10 2007
New Revision: 562985

URL: http://svn.apache.org/viewvc?view=rev&rev=562985
Log:
Just a couple of new testcases that I used to debug some problems recently.  Turned out to
be non-issues, but I thought the testcases still might be worthwhile to have in our bucket.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMerge.java
Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java?view=diff&rev=562985&r1=562984&r2=562985
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerClear.java
Sun Aug  5 16:20:10 2007
@@ -18,8 +18,6 @@
  */
 package org.apache.openjpa.persistence.simple;
 
-import javax.persistence.EntityManager;
-
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.test.SingleEMTestCase;
 
@@ -35,6 +33,31 @@
         setUp(AllFieldTypes.class);
     }
 
+    public void testDetach() {
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object and flush
+        AllFieldTypes testObject1 = new AllFieldTypes();
+        testObject1.setStringField("my test object1");
+        persist(testObject1);
+        em.flush();
+        assertTrue("testObject1 not found in pc", em.contains(testObject1));
+
+        // Insert another object and persist
+        AllFieldTypes testObject2 = new AllFieldTypes();
+        testObject1.setStringField("my test object2");
+        persist(testObject2);
+        assertTrue("testObject2 not found in pc", em.contains(testObject2));
+        
+        // Rollback to clear the PC
+        rollback();
+        
+        assertFalse("testObject1 found in pc", em.contains(testObject1));
+        assertFalse("testObject2 found in pc", em.contains(testObject2));
+        
+    }
+    
     public void testClear() {
         // Create EntityManager and Start a transaction (1)
         begin();

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMerge.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMerge.java?view=auto&rev=562985
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMerge.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/TestEntityManagerMerge.java
Sun Aug  5 16:20:10 2007
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.openjpa.persistence.simple;
+
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+/**
+ * Test case to ensure that the proper JPA merge semantics are processed.
+ *
+ * @author Kevin Sutter
+ */
+public class TestEntityManagerMerge
+    extends SingleEMTestCase {
+
+    public void setUp() {
+        setUp(AllFieldTypes.class);
+    }
+
+    public void testMerge() {
+        // Create EntityManager and Start a transaction (1)
+        begin();
+
+        // Insert a new object into the PC
+        AllFieldTypes testObject = new AllFieldTypes();
+        testObject.setStringField("new test object");
+        persist(testObject);
+        assertTrue("testObject not found in pc", em.contains(testObject));
+        
+        // Modify this object...
+        testObject.setStringField("updated test object");
+
+        // Attempt to merge this updated object into the PC.  Should be ignored.
+        AllFieldTypes mergedObject = em.merge(testObject);
+        assertTrue("mergedObject and testObject are not equal", 
+                mergedObject.equals(testObject));
+        assertTrue("mergedObject and testObject are not ==", 
+                mergedObject == testObject);
+        assertTrue("testObject not found in pc", em.contains(testObject));
+        assertTrue("mergedObject not found in pc", em.contains(mergedObject));
+        
+        // And, once again...
+        testObject.setStringField("yet another update");
+        AllFieldTypes mergedObject2 = em.merge(testObject);
+        assertTrue("mergedObject2 and testObject are not equal", 
+                mergedObject2.equals(testObject));
+        assertTrue("mergedObject2 and testObject are not ==", 
+                mergedObject2 == testObject);
+        assertTrue("testObject not found in pc", em.contains(testObject));
+        assertTrue("mergedObject2 not found in pc", em.contains(mergedObject2));
+        
+        // Rollback
+        rollback();
+  
+    }
+    
+    public static void main(String[] args) {
+        TestRunner.run(TestEntityManagerMerge.class);
+    }
+}
+



Mime
View raw message