Search in sources :

Example 1 with QueryMessage

use of org.apache.cayenne.remote.QueryMessage 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) SelectQuery(org.apache.cayenne.query.SelectQuery) 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 2 with QueryMessage

use of org.apache.cayenne.remote.QueryMessage in project cayenne by apache.

the class BaseRemoteServiceTest method testProcessMessageExceptionSerializability.

@Test
public void testProcessMessageExceptionSerializability() throws Throwable {
    Map<String, String> map = new HashMap<>();
    ObjectContextFactory factory = new ObjectContextFactory() {

        public ObjectContext createContext(DataChannel parent) {
            return null;
        }

        public ObjectContext createContext() {
            return null;
        }
    };
    BaseRemoteService service = new BaseRemoteService(factory, map) {

        @Override
        protected ServerSession createServerSession() {
            return new ServerSession(new RemoteSession("a"), null);
        }

        @Override
        protected ServerSession createServerSession(String name) {
            return createServerSession();
        }

        @Override
        protected ServerSession getServerSession() {
            return createServerSession();
        }
    };
    try {
        service.processMessage(new QueryMessage(null) {

            @Override
            public Query getQuery() {
                // serializable exception thrown
                throw new CayenneRuntimeException();
            }
        });
        fail("Expected to throw");
    } catch (Exception ex) {
        Util.cloneViaSerialization(ex);
    }
    try {
        service.processMessage(new QueryMessage(null) {

            @Override
            public Query getQuery() {
                // non-serializable exception thrown
                throw new MockUnserializableException();
            }
        });
        fail("Expected to throw");
    } catch (Exception ex) {
        Util.cloneViaSerialization(ex);
    }
}
Also used : QueryMessage(org.apache.cayenne.remote.QueryMessage) Query(org.apache.cayenne.query.Query) HashMap(java.util.HashMap) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataChannel(org.apache.cayenne.DataChannel) RemoteSession(org.apache.cayenne.remote.RemoteSession) Test(org.junit.Test)

Aggregations

Query (org.apache.cayenne.query.Query)2 QueryMessage (org.apache.cayenne.remote.QueryMessage)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 DataChannel (org.apache.cayenne.DataChannel)1 MockDataChannel (org.apache.cayenne.MockDataChannel)1 ObjectContext (org.apache.cayenne.ObjectContext)1 ObjectContextFactory (org.apache.cayenne.configuration.ObjectContextFactory)1 EntityResolver (org.apache.cayenne.map.EntityResolver)1 MockQuery (org.apache.cayenne.query.MockQuery)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 RemoteSession (org.apache.cayenne.remote.RemoteSession)1