cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnth...@apache.org
Subject [cayenne] 01/02: Add failing test for transient insert and delete of a to-many relationship value
Date Mon, 13 May 2019 20:11:29 GMT
This is an automated email from the ASF dual-hosted git repository.

johnthuss pushed a commit to branch cayenne42testing3
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit ff91fa76ca04607c71440851894f19e2d3d7e97d
Author: John Huss <johnthuss@apache.org>
AuthorDate: Mon May 13 11:58:43 2019 -0500

    Add failing test for transient insert and delete of a to-many relationship value
---
 .../apache/cayenne/access/OptimisticLockingIT.java | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
b/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
index 14b623c..c24a4a3 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
@@ -26,6 +26,7 @@ import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.query.SortOrder;
 import org.apache.cayenne.test.jdbc.DBHelper;
 import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.locking.LockingHelper;
 import org.apache.cayenne.testdo.locking.RelLockingTestEntity;
 import org.apache.cayenne.testdo.locking.SimpleLockingTestEntity;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
@@ -454,10 +455,36 @@ public class OptimisticLockingIT extends ServerCase {
         SimpleLockingTestEntity object1 = object.getToSimpleLockingTest();
         object.setToSimpleLockingTest(null);
         context.commitChanges();
+        assertNull(object.getToSimpleLockingTest());
 
         // change to-one relationship to non-null and save... should lock on null value
         object.setToSimpleLockingTest(object1);
         context.commitChanges();
+        assertNotNull(object.getToSimpleLockingTest());
+    }
+    
+    @Test
+    public void testTransientInsertAndDeleteOfToManyRelationship() throws Exception {
+        createLockingOnToOneDataSet();
+
+        List<RelLockingTestEntity> allObjects = new SelectQuery<>(
+                RelLockingTestEntity.class).select(context);
+        assertEquals(1, allObjects.size());
+
+        RelLockingTestEntity object = allObjects.get(0);
+        
+        LockingHelper object1 = object.getLockingHelpers().get(0);
+        
+        // create and then immediately delete a to-many relationship value 
+        LockingHelper object2 = context.newObject(LockingHelper.class);
+        object.addToLockingHelpers(object2);
+        object.removeFromLockingHelpers(object2);
+        context.deleteObject(object2);
+        assertEquals(1, object.getLockingHelpers().size());
+
+        object1.setName("updated"); // this will force the commit to actually execute some
SQL
+
+        context.commitChanges();
     }
     
     @Test


Mime
View raw message