use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class HessianServiceTest method testGetSession.
@Test
public void testGetSession() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(Constants.SERVER_ROP_EVENT_BRIDGE_FACTORY_PROPERTY, MockEventBridgeFactory.class.getName());
ObjectContextFactory factory = new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return null;
}
public ObjectContext createContext() {
return null;
}
};
HessianService service = new HessianService(factory, map);
MockHttpServletRequest request = new MockHttpServletRequest();
HttpSession session = new MockHttpSession();
request.setSession(session);
// for some reason need to call this to get session activated in the
// mock request
request.getSession();
try {
ServiceContext.begin(request, null, null, null);
assertSame(session, service.getSession(false));
} finally {
ServiceContext.end();
}
}
use of org.apache.cayenne.DataChannel 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);
}
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class BaseRemoteServiceTest method testConstructor.
@Test
public void testConstructor() throws Exception {
Map<String, String> map = new HashMap<>();
map.put(Constants.SERVER_ROP_EVENT_BRIDGE_FACTORY_PROPERTY, MockEventBridgeFactory.class.getName());
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 null;
}
@Override
protected ServerSession createServerSession(String name) {
return null;
}
@Override
protected ServerSession getServerSession() {
return null;
}
};
assertEquals(MockEventBridgeFactory.class.getName(), service.getEventBridgeFactoryName());
assertSame(factory, service.contextFactory);
}
use of org.apache.cayenne.DataChannel in project cayenne by apache.
the class ClientLocalRuntimeTest method testGetConnection.
@Test
public void testGetConnection() {
final DataContext serverContext = mock(DataContext.class);
Module serverModule = binder -> binder.bind(ObjectContextFactory.class).toInstance(new ObjectContextFactory() {
public ObjectContext createContext(DataChannel parent) {
return null;
}
public ObjectContext createContext() {
return serverContext;
}
});
ClientRuntime runtime = ClientRuntime.builder().local(DIBootstrap.createInjector(serverModule)).build();
ClientConnection connection = runtime.getConnection();
assertNotNull(connection);
assertTrue(connection instanceof LocalConnection);
LocalConnection localConnection = (LocalConnection) connection;
assertTrue(localConnection.getChannel() instanceof ClientServerChannel);
ClientServerChannel clientServerChannel = (ClientServerChannel) localConnection.getChannel();
assertSame(serverContext, clientServerChannel.getParentChannel());
}
use of org.apache.cayenne.DataChannel 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);
}
};
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());
}
Aggregations