Jugen commented on code in PR #614:
URL: https://github.com/apache/cayenne/pull/614#discussion_r1595206887


##########
cayenne/src/test/java/org/apache/cayenne/access/DataContextFlattenedAttributesIT.java:
##########
@@ -457,28 +457,42 @@ public void testDelete() throws Exception {
         a.setArtistName("AX");
         context.commitChanges();
 
-        CompoundPainting o1 = context.newObject(CompoundPainting.class);
-        o1.setArtistName("A1");
-        o1.setEstimatedPrice(new BigDecimal(1.0d));
-        o1.setGalleryName("G1");
-        o1.setPaintingTitle("P1");
-        o1.setTextReview("T1");
+        createTestDataSet();
 
-        context.commitChanges();
+        List<CompoundPainting> objects = 
ObjectSelect.query(CompoundPainting.class)
+                .where(CompoundPainting.ARTIST_NAME.eq("artist2"))
+                .select(context);
 
-        context.deleteObjects(o1);
-        context.commitChanges();
+        // Should have two paintings by the same artist
+        assertEquals("Paintings", 2, objects.size());
 
-        Number artistCount = (Number) Cayenne.objectForQuery(context, new 
EJBQLQuery(
-                "select count(a) from Artist a"));
-        assertEquals(1, artistCount.intValue());
-        Number paintingCount = (Number) Cayenne.objectForQuery(context, new 
EJBQLQuery(
-                "select count(a) from Painting a"));
-        assertEquals(0, paintingCount.intValue());
+        CompoundPainting cp0 = objects.get(0);
+        CompoundPainting cp1 = objects.get(1);
 
-        Number galleryCount = (Number) Cayenne.objectForQuery(context, new 
EJBQLQuery(
-                "select count(a) from Gallery a"));
-        assertEquals(0, galleryCount.intValue());
+        // Both paintings are at the same gallery
+        assertEquals("Gallery", cp0.getGalleryName(), cp1.getGalleryName());
+
+        context.invalidateObjects(cp0);
+        context.deleteObjects(cp1);
+        context.commitChanges();
+
+        // Delete should only have deleted the painting and its info,
+        // the painting's artist and gallery should not be deleted.
+
+        objects = ObjectSelect.query(CompoundPainting.class)
+                .where(CompoundPainting.ARTIST_NAME.eq("artist2"))
+                .select(runtime.newContext());
+        
+        // Should now only have one painting by artist2
+        assertEquals("Painting", 1, objects.size());
+        // and that painting should have a valid gallery
+        assertNotNull("Gallery is null", objects.get(0).getToGallery());
+        assertNotNull("GalleryName is null", 
objects.get(0).getToGallery().getGalleryName());
+        
+        // There should be one less painting info now
+        Number infoCount = (Number) Cayenne.objectForQuery(context, new 
EJBQLQuery(

Review Comment:
   Good idea, will do.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cayenne.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to