use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class EnumTest method testSerializabilityWithHessianInTheMap.
@Test
public void testSerializabilityWithHessianInTheMap() throws Exception {
// test in the Map
Map<String, MockEnum> map = new HashMap<>();
map.put("a", MockEnum.b);
Map after = (Map) HessianUtil.cloneViaClientServerSerialization((Serializable) map, new EntityResolver());
assertNotNull(map);
assertSame(MockEnum.b, after.get("a"));
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class RefreshQueryTest method testSerializabilityWithHessian.
@Test
public void testSerializabilityWithHessian() throws Exception {
RefreshQuery o = new RefreshQuery();
Object clone = HessianUtil.cloneViaClientServerSerialization(o, new EntityResolver());
assertTrue(clone instanceof RefreshQuery);
RefreshQuery c1 = (RefreshQuery) clone;
assertNotSame(o, c1);
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class SelectByIdTest method testSerializabilityWithHessian.
@Test
public void testSerializabilityWithHessian() throws Exception {
SelectById<Artist> o = SelectById.query(Artist.class, 5);
Object clone = HessianUtil.cloneViaClientServerSerialization(o, new EntityResolver());
assertTrue(clone instanceof SelectById);
SelectById<?> c1 = (SelectById<?>) clone;
assertNotSame(o, c1);
assertEquals(o.entityType, c1.entityType);
assertEquals(o.singleId, c1.singleId);
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class ClientChannelTest method testOnQuerySelectOverrideModifiedCached.
@Test
public void testOnQuerySelectOverrideModifiedCached() {
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);
o1.setPersistenceState(PersistenceState.MODIFIED);
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);
assertEquals(1, response.size());
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.map.EntityResolver in project cayenne by apache.
the class ClientChannelTest method testOnQuerySelect.
@Test
public void testOnQuerySelect() {
final MockPersistentObject o1 = new MockPersistentObject();
ObjectId oid1 = new ObjectId("test_entity");
o1.setObjectId(oid1);
ClientConnection connection = mock(ClientConnection.class);
when(connection.sendMessage((ClientMessage) any())).thenAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
ClientMessage arg = (ClientMessage) invocation.getArguments()[0];
if (arg instanceof BootstrapMessage) {
return new EntityResolver();
} else {
return new GenericResponse(Arrays.asList(o1));
}
}
});
ClientChannel channel = new ClientChannel(connection, false, new MockEventManager(), false);
CayenneContext context = new CayenneContext(channel);
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);
context.setEntityResolver(new EntityResolver(entities));
QueryResponse response = channel.onQuery(context, new SelectQuery("test_entity"));
assertNotNull(response);
List<?> list = response.firstList();
assertNotNull(list);
assertEquals(1, list.size());
Persistent o1_1 = (Persistent) list.get(0);
assertEquals(o1.getObjectId(), o1_1.getObjectId());
// ObjectContext must be injected
assertEquals(context, o1_1.getObjectContext());
assertSame(o1_1, context.getGraphManager().getNode(oid1));
}
Aggregations