use of org.apache.cayenne.event.MockEventManager in project cayenne by apache.
the class ClientChannelTest method testOnQuerySelectOverrideCached.
@Test
public void testOnQuerySelectOverrideCached() {
ObjEntity entity = new ObjEntity("test_entity");
entity.setClassName(MockPersistentObject.class.getName());
DataMap dataMap = new DataMap("test");
dataMap.addObjEntity(entity);
Collection<DataMap> entities = Collections.singleton(dataMap);
EntityResolver resolver = new EntityResolver(entities);
CayenneContext context = new CayenneContext();
context.setEntityResolver(resolver);
ObjectId oid = new ObjectId("test_entity", "x", "y");
MockPersistentObject o1 = new MockPersistentObject(oid);
context.getGraphManager().registerNode(oid, o1);
assertSame(o1, context.getGraphManager().getNode(oid));
// another object with the same GID ... we must merge it with cached and return
// cached object instead of the one fetched
MockPersistentObject o2 = new MockPersistentObject(oid);
MockClientConnection connection = new MockClientConnection(new GenericResponse(Arrays.asList(o2)));
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
context.setChannel(channel);
QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
assertNotNull(response);
List<?> list = response.firstList();
assertNotNull(list);
assertEquals(1, list.size());
assertTrue("Expected cached object, got: " + list, list.contains(o1));
assertSame(o1, context.getGraphManager().getNode(oid));
}
use of org.apache.cayenne.event.MockEventManager in project cayenne by apache.
the class ClientChannelTest method testEventBridgeFailure.
@Test
public void testEventBridgeFailure() throws Exception {
MockClientConnection connection = new MockClientConnection() {
@Override
public EventBridge getServerEventBridge() throws CayenneRuntimeException {
return new EventBridge(Collections.EMPTY_LIST, "ext") {
@Override
protected void sendExternalEvent(CayenneEvent localEvent) throws Exception {
}
@Override
protected void shutdownExternal() throws Exception {
}
@Override
protected void startupExternal() throws Exception {
// intentionally throw an exception
throw new CayenneRuntimeException("Test failure");
}
};
}
};
// default constructor must fail
try {
new ClientChannel(connection, false, new MockEventManager(), false);
fail("Channel didn't throw on broken EventBridge");
} catch (CayenneRuntimeException e) {
// expected
}
try {
DefaultEventManager manager = new DefaultEventManager(2);
managers.add(manager);
new ClientChannel(connection, false, manager, false);
fail("Channel didn't throw on broken EventBridge");
} catch (CayenneRuntimeException e) {
// expected
}
try {
DefaultEventManager manager = new DefaultEventManager(2);
managers.add(manager);
new ClientChannel(connection, false, manager, true);
} catch (CayenneRuntimeException e) {
fail("Channel threw on broken EventBridge");
}
}
Aggregations