use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextGraphDiffCompressorIT method testMultipleSimpleProperties.
@Test
public void testMultipleSimpleProperties() {
ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
o1.setGlobalAttribute1("v1");
o1.setGlobalAttribute1("v2");
DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {
public void execute() {
context.commitChanges();
}
});
assertEquals(1, stats.nodePropertiesChanged);
assertEquals(1, stats.nodesCreated);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextGraphDiffCompressorIT method testComplimentaryArcs.
@Test
public void testComplimentaryArcs() {
ClientMtTable1 o1 = context.newObject(ClientMtTable1.class);
ClientMtTable2 o2 = context.newObject(ClientMtTable2.class);
o2.setTable1(o1);
o2.setTable1(null);
DataChannelSyncStats stats = clientServerInterceptor.runWithSyncStatsCollection(new UnitTestClosure() {
public void execute() {
context.commitChanges();
}
});
assertEquals(0, stats.nodePropertiesChanged);
assertEquals(2, stats.nodesCreated);
assertEquals(0, stats.arcsCreated);
assertEquals(0, stats.arcsDeleted);
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextNamedQueryCachingIT method testLocalCacheParameterized.
@Test
public void testLocalCacheParameterized() throws Exception {
createThreeMtTable1sDataSet();
final MappedSelect q1 = MappedSelect.query("ParameterizedMtQueryWithLocalCache").param("g", "g1");
final MappedSelect q2 = MappedSelect.query("ParameterizedMtQueryWithLocalCache").param("g", "g2");
final List<?> result1 = context.performQuery(q1);
assertEquals(1, result1.size());
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> result2 = context.performQuery(q1);
assertSame(result1, result2);
}
});
final List<?> result3 = context.performQuery(q2);
assertNotSame(result1, result3);
assertEquals(1, result3.size());
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> result4 = context.performQuery(q2);
assertSame(result3, result4);
List<?> result5 = context.performQuery(q1);
assertSame(result1, result5);
}
});
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextNamedQueryCachingIT method testLocalCache.
@Test
public void testLocalCache() throws Exception {
createThreeMtTable1sDataSet();
final MappedSelect q1 = MappedSelect.query("MtQueryWithLocalCache");
final List<?> result1 = context.performQuery(q1);
assertEquals(3, result1.size());
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
List<?> result2 = context.performQuery(q1);
assertSame(result1, result2);
}
});
// refresh
q1.forceNoCache();
List<?> result3 = context.performQuery(q1);
assertNotSame(result1, result3);
assertEquals(3, result3.size());
}
use of org.apache.cayenne.unit.di.UnitTestClosure in project cayenne by apache.
the class CayenneContextWithDataContextIT method testPrefetchingToMany.
@Test
public void testPrefetchingToMany() throws Exception {
createTwoMtTable1sAnd2sDataSet();
SelectQuery q = new SelectQuery(ClientMtTable1.class);
q.addOrdering(ClientMtTable1.GLOBAL_ATTRIBUTE1_PROPERTY, SortOrder.ASCENDING);
q.addPrefetch(ClientMtTable1.TABLE2ARRAY_PROPERTY);
final List<ClientMtTable1> results = clientContext.performQuery(q);
clientServerInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
ClientMtTable1 o1 = results.get(0);
assertEquals(PersistenceState.COMMITTED, o1.getPersistenceState());
assertSame(clientContext, o1.getObjectContext());
List<?> children1 = o1.getTable2Array();
assertEquals(2, children1.size());
Iterator<?> it = children1.iterator();
while (it.hasNext()) {
ClientMtTable2 o = (ClientMtTable2) it.next();
assertEquals(PersistenceState.COMMITTED, o.getPersistenceState());
assertSame(clientContext, o.getObjectContext());
// TODO: fixme... reverse relationship is not connected and will
// cause a fetch
// assertEquals(o1, o.getTable1());
}
}
});
}
Aggregations