use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class ClientRuntimeBuilderTest method testDataChannel_NoChannelEvents.
@Test
public void testDataChannel_NoChannelEvents() {
Map<String, String> properties1 = new HashMap<>();
properties1.put(ClientConstants.ROP_CHANNEL_EVENTS_PROPERTY, "true");
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).putAll(properties1);
}
};
Injector injector = DIBootstrap.createInjector(module);
DataChannel channel = injector.getInstance(DataChannel.class);
ClientChannel clientChannel = (ClientChannel) channel;
assertTrue(clientChannel.isChannelEventsEnabled());
}
use of org.apache.cayenne.DataChannel 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);
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class LocalConnectionTest method testConstructors.
@Test
public void testConstructors() {
DataChannel handler1 = new MockDataChannel();
LocalConnection connector1 = new LocalConnection(handler1);
assertFalse(connector1.isSerializingMessages());
assertSame(handler1, connector1.getChannel());
DataChannel handler2 = new MockDataChannel();
LocalConnection connector2 = new LocalConnection(handler2, LocalConnection.JAVA_SERIALIZATION);
assertTrue(connector2.isSerializingMessages());
assertSame(handler2, connector2.getChannel());
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class ServletContextHandlerTest method testRequestStart_bindContext.
@Test
public void testRequestStart_bindContext() {
Module module = binder -> {
binder.bind(DataChannel.class).to(MockDataChannel.class);
binder.bind(ObjectContextFactory.class).toInstance(new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return mock(ObjectContext.class);
}
public ObjectContext createContext() {
return mock(ObjectContext.class);
}
});
};
Injector injector = DIBootstrap.createInjector(module);
SessionContextRequestHandler handler = new SessionContextRequestHandler();
injector.injectMembers(handler);
MockHttpSession session = new MockHttpSession();
BaseContext.bindThreadObjectContext(null);
try {
MockHttpServletRequest request1 = new MockHttpServletRequest();
MockHttpServletResponse response1 = new MockHttpServletResponse();
request1.setSession(session);
handler.requestStart(request1, response1);
ObjectContext c1 = BaseContext.getThreadObjectContext();
assertNotNull(c1);
handler.requestEnd(request1, response1);
try {
BaseContext.getThreadObjectContext();
fail("thread context not null");
} catch (IllegalStateException e) {
// expected
}
MockHttpServletRequest request2 = new MockHttpServletRequest();
MockHttpServletResponse response2 = new MockHttpServletResponse();
request2.setSession(session);
handler.requestStart(request2, response2);
ObjectContext c2 = BaseContext.getThreadObjectContext();
assertSame(c1, c2);
handler.requestEnd(request2, response2);
try {
BaseContext.getThreadObjectContext();
fail("thread context not null");
} catch (IllegalStateException e) {
// expected
}
MockHttpServletRequest request3 = new MockHttpServletRequest();
MockHttpServletResponse response3 = new MockHttpServletResponse();
request3.setSession(new MockHttpSession());
handler.requestStart(request3, response3);
ObjectContext c3 = BaseContext.getThreadObjectContext();
assertNotNull(c3);
assertNotSame(c1, c3);
handler.requestEnd(request3, response3);
try {
BaseContext.getThreadObjectContext();
fail("thread context not null");
} catch (IllegalStateException e) {
// expected
}
} finally {
BaseContext.bindThreadObjectContext(null);
}
}
Aggregations