Search in sources :

Example 6 with Binder

use of org.apache.cayenne.di.Binder 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)

Example 7 with Binder

use of org.apache.cayenne.di.Binder in project cayenne by apache.

the class ClientModuleTest method testObjectContextFactory.

@Test
public void testObjectContextFactory() {
    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);
        }
    };
    Injector injector = DIBootstrap.createInjector(module);
    ObjectContextFactory factory = injector.getInstance(ObjectContextFactory.class);
    assertNotNull(factory);
    assertSame("ObjectContextFactory must be a singleton", factory, injector.getInstance(ObjectContextFactory.class));
}
Also used : Binder(org.apache.cayenne.di.Binder) HashMap(java.util.HashMap) Injector(org.apache.cayenne.di.Injector) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) ObjectContextFactory(org.apache.cayenne.configuration.ObjectContextFactory) Test(org.junit.Test)

Example 8 with Binder

use of org.apache.cayenne.di.Binder in project cayenne by apache.

the class ClientRuntimeTest method testGetObjectContext.

@Test
public void testGetObjectContext() {
    Map<String, String> properties = new HashMap<>();
    ClientModule extraModule = 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);
        }
    };
    ClientRuntime runtime = ClientRuntime.builder().properties(properties).addModule(extraModule).build();
    ObjectContext context = runtime.newContext();
    assertNotNull(context);
    assertTrue(context instanceof CayenneContext);
    assertNotSame("ObjectContext must not be a singleton", context, runtime.newContext());
    CayenneContext clientContext = (CayenneContext) context;
    assertNotNull(clientContext.getChannel());
    assertSame(runtime.getChannel(), clientContext.getChannel());
}
Also used : Binder(org.apache.cayenne.di.Binder) HashMap(java.util.HashMap) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) ObjectContext(org.apache.cayenne.ObjectContext) CayenneContext(org.apache.cayenne.CayenneContext) Test(org.junit.Test)

Example 9 with Binder

use of org.apache.cayenne.di.Binder in project cayenne by apache.

the class ClientRuntimeTest method testShutdown.

@Test
public void testShutdown() throws Exception {
    Map<String, String> properties = new HashMap<>();
    ClientRuntime runtime = ClientRuntime.builder().properties(properties).addModule(binder -> ServerModule.contributeProperties(binder).put(Constants.SERVER_CONTEXTS_SYNC_PROPERTY, String.valueOf(true))).build();
    // make sure objects to be shut down are resolved
    EventManager em = runtime.getInjector().getInstance(EventManager.class);
    assertNotNull(em);
    assertTrue(em instanceof DefaultEventManager);
    assertFalse(((DefaultEventManager) em).isStopped());
    runtime.getInjector().shutdown();
    assertTrue(((DefaultEventManager) em).isStopped());
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) Binder(org.apache.cayenne.di.Binder) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertNotSame(org.junit.Assert.assertNotSame) Constants(org.apache.cayenne.configuration.Constants) Module(org.apache.cayenne.di.Module) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) DataChannel(org.apache.cayenne.DataChannel) Assert.assertSame(org.junit.Assert.assertSame) ClientChannel(org.apache.cayenne.remote.ClientChannel) ClientConnection(org.apache.cayenne.remote.ClientConnection) EventManager(org.apache.cayenne.event.EventManager) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) ServerModule(org.apache.cayenne.configuration.server.ServerModule) CayenneContext(org.apache.cayenne.CayenneContext) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EventManager(org.apache.cayenne.event.EventManager) HashMap(java.util.HashMap) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) Test(org.junit.Test)

Example 10 with Binder

use of org.apache.cayenne.di.Binder in project cayenne by apache.

the class ClientRuntimeTest method testGetDataChannel.

@Test
public void testGetDataChannel() {
    Map<String, String> properties = new HashMap<>();
    Module extraModule = binder -> binder.bind(ClientConnection.class).to(MockClientConnection.class);
    ClientRuntime runtime = ClientRuntime.builder().properties(properties).addModule(extraModule).build();
    DataChannel channel = runtime.getChannel();
    assertNotNull(channel);
    assertTrue(channel instanceof ClientChannel);
}
Also used : ObjectContext(org.apache.cayenne.ObjectContext) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) Binder(org.apache.cayenne.di.Binder) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertNotSame(org.junit.Assert.assertNotSame) Constants(org.apache.cayenne.configuration.Constants) Module(org.apache.cayenne.di.Module) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) DataChannel(org.apache.cayenne.DataChannel) Assert.assertSame(org.junit.Assert.assertSame) ClientChannel(org.apache.cayenne.remote.ClientChannel) ClientConnection(org.apache.cayenne.remote.ClientConnection) EventManager(org.apache.cayenne.event.EventManager) Assert.assertFalse(org.junit.Assert.assertFalse) Map(java.util.Map) ServerModule(org.apache.cayenne.configuration.server.ServerModule) CayenneContext(org.apache.cayenne.CayenneContext) DataChannel(org.apache.cayenne.DataChannel) HashMap(java.util.HashMap) MockClientConnection(org.apache.cayenne.remote.MockClientConnection) ClientConnection(org.apache.cayenne.remote.ClientConnection) Module(org.apache.cayenne.di.Module) ServerModule(org.apache.cayenne.configuration.server.ServerModule) ClientChannel(org.apache.cayenne.remote.ClientChannel) Test(org.junit.Test)

Aggregations

Binder (org.apache.cayenne.di.Binder)14 Test (org.junit.Test)14 Injector (org.apache.cayenne.di.Injector)11 Module (org.apache.cayenne.di.Module)8 HashMap (java.util.HashMap)7 ClientConnection (org.apache.cayenne.remote.ClientConnection)7 MockClientConnection (org.apache.cayenne.remote.MockClientConnection)7 ServerModule (org.apache.cayenne.configuration.server.ServerModule)6 Constants (org.apache.cayenne.configuration.Constants)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Assert.assertTrue (org.junit.Assert.assertTrue)5 DataChannel (org.apache.cayenne.DataChannel)4 DataDomain (org.apache.cayenne.access.DataDomain)4 ClientChannel (org.apache.cayenne.remote.ClientChannel)4 CayenneContext (org.apache.cayenne.CayenneContext)3 ObjectContext (org.apache.cayenne.ObjectContext)3 DataDomainFlushActionFactory (org.apache.cayenne.access.flush.DataDomainFlushActionFactory)3 DefaultDataDomainFlushActionFactory (org.apache.cayenne.access.flush.DefaultDataDomainFlushActionFactory)3 DbRowOpSorter (org.apache.cayenne.access.flush.operation.DbRowOpSorter)3 DefaultDbRowOpSorter (org.apache.cayenne.access.flush.operation.DefaultDbRowOpSorter)3