use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class SelectById_RunIT method testLocalCache.
@Test
public void testLocalCache() throws Exception {
createTwoArtists();
final Artist[] a3 = new Artist[1];
assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {
@Override
public void execute() {
a3[0] = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
assertNotNull(a3[0]);
assertEquals("artist3", a3[0].getArtistName());
}
}));
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
@Override
public void execute() {
Artist a3cached = SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
assertSame(a3[0], a3cached);
}
});
context.performGenericQuery(new RefreshQuery("g1"));
assertEquals(1, interceptor.runWithQueryCounter(new UnitTestClosure() {
@Override
public void execute() {
SelectById.query(Artist.class, 3).localCache("g1").selectOne(context);
}
}));
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextIT method testPerformPaginatedQueryBigPage.
@Test
public void testPerformPaginatedQueryBigPage() throws Exception {
createArtistsDataSet();
SelectQuery query = new SelectQuery(Artist.class);
query.setPageSize(5);
final List<?> objects = context.performQuery(query);
assertNotNull(objects);
assertTrue(objects instanceof IncrementalFaultList<?>);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
assertEquals(7, objects.size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextLocalObjectIT method testLocalObject_TempId_NestedContext.
@Test
public void testLocalObject_TempId_NestedContext() throws Exception {
final Artist a1 = context1.newObject(Artist.class);
final ObjectContext nestedContext = runtime.newContext(context1);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a3 = nestedContext.localObject(a1);
assertNotSame(a3, a1);
assertEquals(a3.getObjectId(), a1.getObjectId());
assertSame(nestedContext, a3.getObjectContext());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextLocalObjectIT method testLocalObject_SameContext.
@Test
public void testLocalObject_SameContext() throws Exception {
tArtist.insert(456, "Bla");
final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a2 = context1.localObject(a1);
assertSame(a2, a1);
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DataContextLocalObjectIT method testLocalObject_NotInCache.
@Test
public void testLocalObject_NotInCache() throws Exception {
tArtist.insert(456, "Bla");
final Artist a1 = Cayenne.objectForPK(context1, Artist.class, 456);
interceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a3 = context2.localObject(a1);
assertNotSame(a3, a1);
assertEquals(a3.getObjectId(), a1.getObjectId());
assertSame(context2, a3.getObjectContext());
}
});
}
Aggregations