use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class NestedCayenneContextIT method testPrefetchingToMany.
@Test
public void testPrefetchingToMany() throws Exception {
ClientMtTable1 mt11 = clientContext.newObject(ClientMtTable1.class);
mt11.setGlobalAttribute1("1");
ClientMtTable1 mt12 = clientContext.newObject(ClientMtTable1.class);
mt12.setGlobalAttribute1("2");
ClientMtTable2 mt21 = clientContext.newObject(ClientMtTable2.class);
ClientMtTable2 mt22 = clientContext.newObject(ClientMtTable2.class);
mt21.setTable1(mt11);
mt22.setTable1(mt11);
clientContext.commitChanges();
final ObjectContext child = runtime.newContext(clientContext);
SelectQuery<ClientMtTable1> q = new SelectQuery<ClientMtTable1>(ClientMtTable1.class);
q.addOrdering("globalAttribute1", SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<ClientMtTable1> results = child.select(q);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o1 = results.get(0);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(child, o1.getObjectContext());
List<ClientMtTable2> children1 = o1.getTable2Array();
assertEquals(2, children1.size());
Iterator<ClientMtTable2> it = children1.iterator();
while (it.hasNext()) {
ClientMtTable2 o = it.next();
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(child, o.getObjectContext());
assertEquals(o1, o.getTable1());
}
ClientMtTable1 o2 = results.get(1);
assertEquals(PersistenceState.COMMITTED, o2.getPersistenceState());
assertSame(child, o2.getObjectContext());
List<?> children2 = o2.getTable2Array();
assertEquals(0, children2.size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class ClientServerChannelIT method testOnQueryPrefetchingToManyEmpty.
@Test
public void testOnQueryPrefetchingToManyEmpty() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<?> results = clientServerChannel.onQuery(null, q).firstList();
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o2 = (ClientMtTable1) results.get(1);
assertNull(o2.getObjectContext());
List<?> children2 = o2.getTable2Array();
assertNotNull(children2);
assertFalse(((ValueHolder) children2).isFault());
assertEquals(0, children2.size());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class ClientObjectSelectIT method testPageSelect.
@Test
public void testPageSelect() throws Exception {
final ObjectSelect<ClientMtTable1> objectSelect = ObjectSelect.query(ClientMtTable1.class).pageSize(5);
final List<ClientMtTable1> list = objectSelect.select(context);
assertNotNull(list);
assertEquals(RemoteIncrementalFaultList.class, list.getClass());
int count = serverCaseDataChannelInterceptor.runWithQueryCounter(new UnitTestClosure() {
@Override
public void execute() {
assertNotNull(list.get(0));
assertNotNull(list.get(4));
assertNotNull(list.get(5));
assertNotNull(list.get(6));
}
});
assertEquals(1, count);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DeepMergeOperationIT method testDeepMergeModified.
@Test
public void testDeepMergeModified() {
final Artist a = context.newObject(Artist.class);
a.setArtistName("AAA");
context.commitChanges();
final Artist a1 = (Artist) Cayenne.objectForPK(context1, a.getObjectId());
a1.setArtistName("BBB");
final DeepMergeOperation op = new DeepMergeOperation(context1);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a2 = (Artist) op.merge(a);
assertNotNull(a2);
assertEquals(PersistenceState.MODIFIED, a2.getPersistenceState());
assertSame(a1, a2);
assertEquals("BBB", a2.getArtistName());
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class DeepMergeOperationIT method testDeepMergeNonExistent.
@Test
public void testDeepMergeNonExistent() {
final Artist a = context.newObject(Artist.class);
a.setArtistName("AAA");
context.commitChanges();
final DeepMergeOperation op = new DeepMergeOperation(context1);
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
Artist a2 = (Artist) op.merge(a);
assertNotNull(a2);
assertEquals(PersistenceState.COMMITTED, a2.getPersistenceState());
assertEquals(a.getArtistName(), a2.getArtistName());
}
});
}
Aggregations