assertTrue(getValue(list).contains(p2));
assertTrue(getValue(list).contains(p1));
}
public void testThrowOutDeleted() throws Exception {
ToManyList list = createForExistingArtist();
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("p1");
Painting p2 = context.newObject(Painting.class);
p2.setPaintingTitle("p2");
// list being tested is a separate copy from
// the relationship list that Artist has, so adding a painting
// here will not add the painting to the array being tested
((Artist) list.getRelationshipOwner()).addToPaintingArray(p1);
((Artist) list.getRelationshipOwner()).addToPaintingArray(p2);
context.commitChanges();
// immediately tag Artist as MODIFIED, since we are messing up with relationship
// bypassing normal CayenneDataObject methods
list.getRelationshipOwner().setPersistenceState(PersistenceState.MODIFIED);
assertTrue("List must be unresolved...", list.isFault());
list.add(p1);
list.add(p2);
assertTrue("List must be unresolved when adding an object...", list.isFault());
assertTrue(list.addedToUnresolved.contains(p2));
assertTrue(list.addedToUnresolved.contains(p1));
// now delete p2 and resolve list
((Artist) list.getRelationshipOwner()).removeFromPaintingArray(p2);
context.deleteObject(p2);
context.commitChanges();
assertTrue("List must be unresolved...", list.isFault());
assertTrue(
"List must be unresolved when an object was deleted externally...",
list.isFault());
assertTrue(list.addedToUnresolved.contains(p2));
assertTrue(list.addedToUnresolved.contains(p1));
// now resolve the list and see how merge worked
int size = list.size();
assertFalse("List must be resolved after checking a size...", list.isFault());
assertEquals("Deleted object must have been purged...", 1, size);
assertTrue(getValue(list).contains(p1));
assertFalse("Deleted object must have been purged...", getValue(list)
.contains(p2));
}