use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class ShallowMergeOperationIT method testMerge_NoOverride.
@Test
public void testMerge_NoOverride() throws Exception {
createArtistsDataSet();
ObjectContext childContext = runtime.newContext(context);
final ShallowMergeOperation op = new ShallowMergeOperation(childContext);
int modifiedId = 33003;
final Artist modified = (Artist) Cayenne.objectForQuery(context, new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, modifiedId)));
final Artist peerModified = (Artist) Cayenne.objectForQuery(childContext, new ObjectIdQuery(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, modifiedId)));
modified.setArtistName("M1");
peerModified.setArtistName("M2");
assertEquals(PersistenceState.MODIFIED, modified.getPersistenceState());
assertEquals(PersistenceState.MODIFIED, peerModified.getPersistenceState());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Persistent peerModified2 = op.merge(modified);
assertSame(peerModified, peerModified2);
assertEquals(PersistenceState.MODIFIED, peerModified2.getPersistenceState());
assertEquals("M2", peerModified.getArtistName());
assertEquals("M1", modified.getArtistName());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class SimpleIdIncrementalFaultListPrefetchIT method testPrefetch1.
/**
* Test that all queries specified in prefetch are executed with a single prefetch
* path.
*/
@Test
public void testPrefetch1() throws Exception {
createArtistsAndPaintingsDataSet();
Expression e = ExpressionFactory.likeExp("artistName", "artist1%");
SelectQuery q = new SelectQuery("Artist", e);
q.addPrefetch("paintingArray");
q.setPageSize(3);
final IncrementalFaultList<?> result = (IncrementalFaultList) context.performQuery(q);
assertEquals(6, result.size());
// currently queries with prefetch do not resolve their first page
assertEquals(result.size(), result.getUnfetchedObjects());
int count = queryInterceptor.runWithQueryCounter(new UnitTestClosure() {
public void execute() {
// go through the second page objects and count queries
for (int i = 3; i < 6; i++) {
result.get(i);
}
}
});
// within the same page only one query should've been executed
assertEquals(1, count);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class SingleTableInheritanceIT method testRelationshipAbstractToSuperPrefetchingDisjoint.
@Test
public void testRelationshipAbstractToSuperPrefetchingDisjoint() {
context.performGenericQuery(new SQLTemplate(AbstractPerson.class, "INSERT INTO PERSON (PERSON_ID, NAME, PERSON_TYPE) VALUES (2, 'AA', 'EE')"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (2, 'AA', 2)"));
context.performGenericQuery(new SQLTemplate(PersonNotes.class, "INSERT INTO PERSON_NOTES (ID, NOTES, PERSON_ID) VALUES (3, 'BB', 2)"));
SelectQuery query = new SelectQuery(PersonNotes.class);
query.addPrefetch(PersonNotes.PERSON.disjoint());
query.addOrdering(PersonNotes.NOTES.asc());
List<PersonNotes> notes = context.performQuery(query);
assertEquals(2, notes.size());
final PersonNotes note = notes.get(0);
queryBlocker.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals("AA", note.getPerson().getName());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class FlattenedPrefetchIT method testJointManyToMany.
@Test
public void testJointManyToMany() throws Exception {
createPrefetchDataSet1();
SelectQuery q = new SelectQuery(Artist.class);
q.addPrefetch(Artist.GROUP_ARRAY.joint());
final List<Artist> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Artist a : objects) {
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class FlattenedPrefetchIT method testJointMultiPrefetch.
@Test
public void testJointMultiPrefetch() throws Exception {
createPrefetchDataSet2();
SelectQuery q = new SelectQuery(Painting.class);
q.addPrefetch(Painting.TO_ARTIST.joint());
q.addPrefetch(Painting.TO_ARTIST.dot(Artist.GROUP_ARRAY).joint());
final List<Painting> objects = context.performQuery(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(3, objects.size());
for (Painting p : objects) {
Artist a = p.getToArtist();
assertEquals(PersistenceState.COMMITTED, a.getPersistenceState());
List<ArtGroup> list = a.getGroupArray();
assertNotNull(list);
assertFalse("artist's groups not resolved: " + a, ((ValueHolder) list).isFault());
assertTrue(list.size() > 0);
for (ArtGroup g : list) {
assertEquals(PersistenceState.COMMITTED, g.getPersistenceState());
}
// assert no duplicates
Set<ArtGroup> s = new HashSet<ArtGroup>(list);
assertEquals(s.size(), list.size());
}
}
});
}
Aggregations