Search in sources :

Example 1 with MockClientConnection

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

the class ClientModuleTest method testDataChannel.

@Test
public void testDataChannel() {
    Map<String, String> properties = new HashMap<>();
    ClientModule module = new ClientModule() {

        @Override
        public void configure(Binder binder) {
            super.configure(binder);
            // use a noop connection to prevent startup errors...
            binder.bind(ClientConnection.class).to(MockClientConnection.class);
            ServerModule.contributeProperties(binder).put(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, String.valueOf(true));
        }
    };
    Injector injector = DIBootstrap.createInjector(module);
    DataChannel channel = injector.getInstance(DataChannel.class);
    assertNotNull(channel);
    assertTrue(channel instanceof ClientChannel);
    assertSame("DataChannel must be a singleton", channel, injector.getInstance(DataChannel.class));
    ClientChannel clientChannel = (ClientChannel) channel;
    assertTrue(clientChannel.getConnection() instanceof MockClientConnection);
    assertTrue(clientChannel.getEventManager() instanceof DefaultEventManager);
    assertFalse(clientChannel.isChannelEventsEnabled());
}
Also used : Binder(org.apache.cayenne.di.Binder) DataChannel(org.apache.cayenne.DataChannel) HashMap(java.util.HashMap) Injector(org.apache.cayenne.di.Injector) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) ClientChannel(org.apache.cayenne.remote.ClientChannel) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 DataChannel (org.apache.cayenne.DataChannel)1 Binder (org.apache.cayenne.di.Binder)1 Injector (org.apache.cayenne.di.Injector)1 DefaultEventManager (org.apache.cayenne.event.DefaultEventManager)1 ClientChannel (org.apache.cayenne.remote.ClientChannel)1 ClientConnection (org.apache.cayenne.remote.ClientConnection)1 MockClientConnection (org.apache.cayenne.remote.MockClientConnection)1 Test (org.junit.Test)1