assertNull(p3.getToGallery());
}
public void testReplace() throws Exception {
Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("xa");
Gallery g1 = context.newObject(Gallery.class);
g1.setGalleryName("yTW");
p1.setToGallery(g1);
context.commitChanges();
ObjectContext context2 = runtime.getContext();
// test database data
Painting p2 = (Painting) Cayenne.objectForQuery(context2, new SelectQuery(
Painting.class));
Gallery g21 = p2.getToGallery();
assertNotNull(g21);
assertEquals("yTW", g21.getGalleryName());
assertEquals(1, g21.getPaintingArray().size());
assertSame(p2, g21.getPaintingArray().get(0));
Gallery g22 = context2.newObject(Gallery.class);
g22.setGalleryName("rE");
p2.setToGallery(g22);
// test before save
assertEquals(0, g21.getPaintingArray().size());
assertEquals(1, g22.getPaintingArray().size());
assertSame(p2, g22.getPaintingArray().get(0));
// do save II
context2.commitChanges();
ObjectContext context3 = runtime.getContext();
Painting p3 = (Painting) Cayenne.objectForQuery(context3, new SelectQuery(
Painting.class));
Gallery g3 = p3.getToGallery();
assertNotNull(g3);
assertEquals("rE", g3.getGalleryName());
assertEquals(1, g3.getPaintingArray().size());
assertSame(p3, g3.getPaintingArray().get(0));
}