use of org.apache.cayenne.DataChannelFilterChain in project cayenne by apache.
the class DataDomainFiltersIT method testOnQuery_Blocking.
@Test
public void testOnQuery_Blocking() {
DataDomain domain = runtime.getDataDomain();
final QueryResponse r1 = new ListResponse();
final QueryResponse r2 = new ListResponse();
DataChannelFilter f1 = new MockDataChannelFilter() {
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
return r1;
}
};
DataChannelFilter f2 = new MockDataChannelFilter() {
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
return r2;
}
};
domain.filters.add(f1);
domain.filters.add(f2);
SelectQuery query = new SelectQuery(Artist.class);
QueryResponse response = domain.onQuery(context, query);
assertSame(r2, response);
}
use of org.apache.cayenne.DataChannelFilterChain in project cayenne by apache.
the class DataDomainFiltersIT method testOnSync_FilterOrdering.
@Test
public void testOnSync_FilterOrdering() {
DataDomain domain = runtime.getDataDomain();
final List<String> results = new ArrayList<String>();
DataChannelFilter f1 = new MockDataChannelFilter() {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType, DataChannelFilterChain filterChain) {
results.add("f1start");
GraphDiff response = filterChain.onSync(originatingContext, changes, syncType);
results.add("f1end");
return response;
}
};
DataChannelFilter f2 = new MockDataChannelFilter() {
@Override
public GraphDiff onSync(ObjectContext originatingContext, GraphDiff changes, int syncType, DataChannelFilterChain filterChain) {
results.add("f2start");
GraphDiff response = filterChain.onSync(originatingContext, changes, syncType);
results.add("f2end");
return response;
}
};
domain.filters.add(f1);
domain.filters.add(f2);
Artist a = context.newObject(Artist.class);
a.setArtistName("AAA");
// testing domain.onSync indirectly
context.commitChanges();
assertEquals(4, results.size());
assertEquals("f2start", results.get(0));
assertEquals("f1start", results.get(1));
assertEquals("f1end", results.get(2));
assertEquals("f2end", results.get(3));
}
use of org.apache.cayenne.DataChannelFilterChain in project cayenne by apache.
the class DataDomainFiltersIT method testOnQuery_FilterOrdering.
@Test
public void testOnQuery_FilterOrdering() {
DataDomain domain = runtime.getDataDomain();
final List<String> results = new ArrayList<String>();
DataChannelFilter f1 = new MockDataChannelFilter() {
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
results.add("f1start");
QueryResponse response = filterChain.onQuery(originatingContext, query);
results.add("f1end");
return response;
}
};
DataChannelFilter f2 = new MockDataChannelFilter() {
@Override
public QueryResponse onQuery(ObjectContext originatingContext, Query query, DataChannelFilterChain filterChain) {
results.add("f2start");
QueryResponse response = filterChain.onQuery(originatingContext, query);
results.add("f2end");
return response;
}
};
domain.filters.add(f1);
domain.filters.add(f2);
SelectQuery query = new SelectQuery(Artist.class);
QueryResponse response = domain.onQuery(context, query);
assertNotNull(response);
assertEquals(4, results.size());
assertEquals("f2start", results.get(0));
assertEquals("f1start", results.get(1));
assertEquals("f1end", results.get(2));
assertEquals("f2end", results.get(3));
}
Aggregations