use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOMany2OneIT method testReplace.
@Test
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.newContext();
// 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.newContext();
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));
}
use of org.apache.cayenne.testdo.testmap.Gallery in project cayenne by apache.
the class CDOOneDep2OneIT method testNewAdd2.
/**
* Tests how primary key is propagated from one new object to another.
*/
@Test
public void testNewAdd2() throws Exception {
Artist a1 = this.newArtist();
Gallery g1 = context.newObject(Gallery.class);
g1.setGalleryName(galleryName);
Exhibit e1 = context.newObject(Exhibit.class);
e1.setOpeningDate(new Timestamp(System.currentTimeMillis()));
e1.setClosingDate(new Timestamp(System.currentTimeMillis()));
e1.setToGallery(g1);
ArtistExhibit ae1 = context.newObject(ArtistExhibit.class);
ae1.setToArtist(a1);
ae1.setToExhibit(e1);
// *** TESTING THIS ***
context.commitChanges();
}
Aggregations