Search in sources :

Example 1 with MockQuery

use of org.apache.cayenne.query.MockQuery in project cayenne by apache.

the class QualifierTranslatorIT method testNonQualifiedQuery.

// TODO: not an integration test; extract into *Test
@Test
public void testNonQualifiedQuery() throws Exception {
    TstQueryAssembler qa = new TstQueryAssembler(new MockQuery(), node.getAdapter(), node.getEntityResolver());
    try {
        new QualifierTranslator(qa).appendPart(new StringBuilder());
        fail();
    } catch (ClassCastException ccex) {
    // exception expected
    }
}
Also used : MockQuery(org.apache.cayenne.query.MockQuery) Test(org.junit.Test)

Example 2 with MockQuery

use of org.apache.cayenne.query.MockQuery in project cayenne by apache.

the class ClientServerChannelIT method testOnQuery.

@Test
public void testOnQuery() {
    final boolean[] genericDone = new boolean[1];
    MockDataChannel parent = new MockDataChannel(new EntityResolver()) {

        @Override
        public QueryResponse onQuery(ObjectContext context, Query query) {
            genericDone[0] = true;
            return super.onQuery(context, query);
        }
    };
    DataContext context = (DataContext) runtime.newContext(parent);
    QueryMessage message = new QueryMessage(new MockQuery());
    new ClientServerChannel(context).onQuery(null, message.getQuery());
    assertTrue(genericDone[0]);
}
Also used : QueryMessage(org.apache.cayenne.remote.QueryMessage) MockQuery(org.apache.cayenne.query.MockQuery) Query(org.apache.cayenne.query.Query) EntityResolver(org.apache.cayenne.map.EntityResolver) ObjectContext(org.apache.cayenne.ObjectContext) MockQuery(org.apache.cayenne.query.MockQuery) MockDataChannel(org.apache.cayenne.MockDataChannel) Test(org.junit.Test)

Example 3 with MockQuery

use of org.apache.cayenne.query.MockQuery in project cayenne by apache.

the class DataContextDelegateIT method testWillPerformGenericQuery.

@Test
public void testWillPerformGenericQuery() throws Exception {
    final List<Query> queriesPerformed = new ArrayList<Query>(1);
    DataContextDelegate delegate = new MockDataContextDelegate() {

        @Override
        public Query willPerformGenericQuery(DataContext context, Query query) {
            queriesPerformed.add(query);
            return query;
        }
    };
    context.setDelegate(delegate);
    // test that delegate is consulted before select
    MockQuery query = new MockQuery();
    context.performGenericQuery(query);
    assertTrue("Delegate is not notified of a query being run.", queriesPerformed.contains(query));
    assertEquals(1, queriesPerformed.size());
    assertTrue("Delegate unexpectedly blocked the query.", query.isRouteCalled());
}
Also used : Query(org.apache.cayenne.query.Query) MockQuery(org.apache.cayenne.query.MockQuery) ArrayList(java.util.ArrayList) MockQuery(org.apache.cayenne.query.MockQuery) Test(org.junit.Test)

Example 4 with MockQuery

use of org.apache.cayenne.query.MockQuery in project cayenne by apache.

the class DataContextDelegateIT method testWillPerformGenericQueryBlocked.

@Test
public void testWillPerformGenericQueryBlocked() throws Exception {
    final List<Query> queriesPerformed = new ArrayList<Query>(1);
    DataContextDelegate delegate = new MockDataContextDelegate() {

        @Override
        public Query willPerformGenericQuery(DataContext context, Query query) {
            queriesPerformed.add(query);
            return null;
        }
    };
    context.setDelegate(delegate);
    MockQuery query = new MockQuery();
    context.performGenericQuery(query);
    assertTrue("Delegate is not notified of a query being run.", queriesPerformed.contains(query));
    assertEquals(1, queriesPerformed.size());
    assertFalse("Delegate couldn't block the query.", query.isRouteCalled());
}
Also used : Query(org.apache.cayenne.query.Query) MockQuery(org.apache.cayenne.query.MockQuery) ArrayList(java.util.ArrayList) MockQuery(org.apache.cayenne.query.MockQuery) Test(org.junit.Test)

Aggregations

MockQuery (org.apache.cayenne.query.MockQuery)4 Test (org.junit.Test)4 Query (org.apache.cayenne.query.Query)3 ArrayList (java.util.ArrayList)2 MockDataChannel (org.apache.cayenne.MockDataChannel)1 ObjectContext (org.apache.cayenne.ObjectContext)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 QueryMessage (org.apache.cayenne.remote.QueryMessage)1