use of org.apache.cayenne.map.EntityResolver 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 = ObjectId.of("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, ObjectSelect.query(MockPersistentObject.class));
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.map.EntityResolver in project cayenne by apache.
the class EnumTest method testSerializabilityWithHessianObjectPropertyInAList.
@Test
public void testSerializabilityWithHessianObjectPropertyInAList() throws Exception {
// test that Enum properties are serialized properly...
MockEnumHolder o1 = new MockEnumHolder();
o1.setMockEnum(MockEnum.b);
MockEnumHolder o2 = new MockEnumHolder();
o2.setMockEnum(MockEnum.c);
ArrayList<MockEnumHolder> l = new ArrayList<MockEnumHolder>();
l.add(o1);
l.add(o2);
ArrayList ld = (ArrayList) HessianUtil.cloneViaClientServerSerialization(l, new EntityResolver());
assertEquals(2, ld.size());
MockEnumHolder o1d = (MockEnumHolder) ld.get(0);
MockEnumHolder o2d = (MockEnumHolder) ld.get(1);
assertSame(MockEnum.b, o1d.getMockEnum());
assertSame(MockEnum.c, o2d.getMockEnum());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class EnumTest method testSerializabilityWithHessianStandalone.
@Test
public void testSerializabilityWithHessianStandalone() throws Exception {
MockEnum before = MockEnum.a;
// test standalone
Object after = HessianUtil.cloneViaClientServerSerialization(before, new EntityResolver());
assertNotNull(after);
assertSame(before, after);
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class RelationshipQueryTest method testSerializabilityWithHessian.
@Test
public void testSerializabilityWithHessian() throws Exception {
ObjectId oid = ObjectId.of("test", "a", "b");
RelationshipQuery query = new RelationshipQuery(oid, "relX");
RelationshipQuery q1 = (RelationshipQuery) HessianUtil.cloneViaClientServerSerialization(query, new EntityResolver());
assertNotNull(q1);
assertEquals(oid, q1.getObjectId());
assertEquals("relX", q1.getRelationshipName());
}
use of org.apache.cayenne.map.EntityResolver in project cayenne by apache.
the class SelectById_IT 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);
ObjEntity artistEntity = resolver.getObjEntity(Artist.class);
assertEquals(artistEntity, o.root.resolve(resolver));
assertEquals(o.root.resolve(resolver), c1.root.resolve(resolver));
assertEquals(o.idSpec.getQualifier(artistEntity), c1.idSpec.getQualifier(artistEntity));
}
Aggregations