Search in sources :

Example 1 with MockDataChannelFilter

use of org.apache.cayenne.MockDataChannelFilter 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);
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) ListResponse(org.apache.cayenne.util.ListResponse) SelectQuery(org.apache.cayenne.query.SelectQuery) Query(org.apache.cayenne.query.Query) QueryResponse(org.apache.cayenne.QueryResponse) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilterChain(org.apache.cayenne.DataChannelFilterChain) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 2 with MockDataChannelFilter

use of org.apache.cayenne.MockDataChannelFilter 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));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) GraphDiff(org.apache.cayenne.graph.GraphDiff) ArrayList(java.util.ArrayList) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilterChain(org.apache.cayenne.DataChannelFilterChain) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 3 with MockDataChannelFilter

use of org.apache.cayenne.MockDataChannelFilter 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));
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) SelectQuery(org.apache.cayenne.query.SelectQuery) Query(org.apache.cayenne.query.Query) QueryResponse(org.apache.cayenne.QueryResponse) ArrayList(java.util.ArrayList) MockDataChannelFilter(org.apache.cayenne.MockDataChannelFilter) DataChannelFilterChain(org.apache.cayenne.DataChannelFilterChain) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Aggregations

DataChannelFilter (org.apache.cayenne.DataChannelFilter)3 DataChannelFilterChain (org.apache.cayenne.DataChannelFilterChain)3 MockDataChannelFilter (org.apache.cayenne.MockDataChannelFilter)3 ObjectContext (org.apache.cayenne.ObjectContext)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 QueryResponse (org.apache.cayenne.QueryResponse)2 Query (org.apache.cayenne.query.Query)2 SelectQuery (org.apache.cayenne.query.SelectQuery)2 GraphDiff (org.apache.cayenne.graph.GraphDiff)1 Artist (org.apache.cayenne.testdo.testmap.Artist)1 ListResponse (org.apache.cayenne.util.ListResponse)1