use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataContextSharedCacheIT method testSnapshotDeletePropagationToModified.
/**
* Test case to prove that deleting an object in one ObjectStore and committed to the
* database will be reflected in the peer ObjectStore using the same DataRowCache. By
* default MODIFIED objects will be changed to NEW.
*/
@Test
public void testSnapshotDeletePropagationToModified() throws Exception {
// make sure we have a fully resolved copy of an artist object
// in the second context
final Artist altArtist = context1.localObject(artist);
altArtist.getArtistName();
assertNotNull(altArtist);
assertFalse(altArtist == artist);
// modify peer
altArtist.setArtistName("version2");
assertEquals(PersistenceState.MODIFIED, altArtist.getPersistenceState());
// Update Artist
context.deleteObjects(artist);
context.commitChanges();
// check underlying cache
assertNull(context.getObjectStore().getDataRowCache().getCachedSnapshot(altArtist.getObjectId()));
// check peer artist
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
assertEquals(PersistenceState.NEW, altArtist.getPersistenceState());
}
};
helper.runTest(3000);
// check if now we can save this object again, and with the original
// ObjectId
ObjectId id = altArtist.getObjectId();
assertNotNull(id);
assertNotNull(id.getIdSnapshot().get(Artist.ARTIST_ID_PK_COLUMN));
assertFalse(id.isTemporary());
context1.commitChanges();
assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataContextSharedCacheIT method testSnapshotInsertPropagationToManyRefresh.
/**
* Test case to prove that inserting an object in one ObjectStore and committing to
* the database will be reflected in the peer ObjectStore using the same DataRowCache.
* This would mean refreshing to-many collections.
*/
@Test
public void testSnapshotInsertPropagationToManyRefresh() throws Exception {
Painting painting1 = (Painting) context.newObject("Painting");
painting1.setPaintingTitle("p1");
painting1.setToArtist(artist);
context.commitChanges();
// make sure we have a fully resolved copy of an artist and painting
// objects
// in the second context
final Artist altArtist = context1.localObject(artist);
final Painting altPainting1 = context1.localObject(painting1);
assertEquals(artist.getArtistName(), altArtist.getArtistName());
assertEquals(painting1.getPaintingTitle(), altPainting1.getPaintingTitle());
assertEquals(1, altArtist.getPaintingArray().size());
assertEquals(PersistenceState.COMMITTED, altArtist.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, altPainting1.getPersistenceState());
// insert new painting and add to artist
Painting painting2 = (Painting) context.newObject("Painting");
painting2.setPaintingTitle("p2");
painting2.setToArtist(artist);
context.commitChanges();
// check peer artist
// use threaded helper as a barrier, to avoid triggering faults earlier than
// needed
ParallelTestContainer helper = new ParallelTestContainer() {
@Override
protected void assertResult() throws Exception {
Object value = altArtist.readPropertyDirectly("paintingArray");
assertTrue("Unexpected: " + value, value instanceof ToManyList);
assertTrue(((ToManyList) value).isFault());
}
};
helper.runTest(2000);
List<Painting> list = altArtist.getPaintingArray();
assertEquals(2, list.size());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataContextValidationIT method testValidatingObjectsOnCommit.
@Test
public void testValidatingObjectsOnCommit() throws Exception {
// test that validation is called properly
context.setValidatingObjectsOnCommit(true);
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("a1");
context.commitChanges();
assertTrue(a1.isValidateForSaveCalled());
context.setValidatingObjectsOnCommit(false);
Artist a2 = context.newObject(Artist.class);
a2.setArtistName("a2");
context.commitChanges();
assertFalse(a2.isValidateForSaveCalled());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataDomainCallbacksIT method testPostLoad_Prefetch.
@Test
public void testPostLoad_Prefetch() throws Exception {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
registry.addCallback(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
MockCallingBackListener listener = new MockCallingBackListener();
registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, listener, "publicCallback");
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
Painting p1 = context.newObject(Painting.class);
p1.setToArtist(a1);
p1.setPaintingTitle("XXX");
context.commitChanges();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.disjoint());
p1 = (Painting) context1.performQuery(q).get(0);
// artist is prefetched here, and a callback must have been invoked
a1 = p1.getToArtist();
assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState());
assertEquals(1, a1.getPostLoaded());
assertSame(a1, listener.getPublicCalledbackEntity());
}
use of org.apache.cayenne.testdo.testmap.Artist in project cayenne by apache.
the class DataDomainCallbacksIT method testPostRemove.
@Test
public void testPostRemove() {
LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
Artist a1 = context.newObject(Artist.class);
a1.setArtistName("XX");
context.commitChanges();
registry.addCallback(LifecycleEvent.POST_REMOVE, Artist.class, "postRemoveCallback");
MockCallingBackListener listener2 = new MockCallingBackListener();
registry.addListener(LifecycleEvent.POST_REMOVE, Artist.class, listener2, "publicCallback");
context.deleteObjects(a1);
context.commitChanges();
assertTrue(a1.isPostRemoved());
assertSame(a1, listener2.getPublicCalledbackEntity());
}
Aggregations