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());
}
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));
}
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());
}
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());
}
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);
}
Aggregations