Search in sources :

Example 56 with EntityResolver

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));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) GenericResponse(org.apache.cayenne.util.GenericResponse) EntityResolver(org.apache.cayenne.map.EntityResolver) CayenneContext(org.apache.cayenne.CayenneContext) DataMap(org.apache.cayenne.map.DataMap) ObjEntity(org.apache.cayenne.map.ObjEntity) MockPersistentObject(org.apache.cayenne.MockPersistentObject) QueryResponse(org.apache.cayenne.QueryResponse) MockEventManager(org.apache.cayenne.event.MockEventManager) Test(org.junit.Test)

Example 57 with EntityResolver

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());
}
Also used : ArrayList(java.util.ArrayList) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 58 with EntityResolver

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);
}
Also used : EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 59 with EntityResolver

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());
}
Also used : ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 60 with EntityResolver

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));
}
Also used : Artist(org.apache.cayenne.testdo.testmap.Artist) ObjEntity(org.apache.cayenne.map.ObjEntity) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

EntityResolver (org.apache.cayenne.map.EntityResolver)87 Test (org.junit.Test)57 ObjEntity (org.apache.cayenne.map.ObjEntity)17 ObjectId (org.apache.cayenne.ObjectId)14 DataMap (org.apache.cayenne.map.DataMap)14 DbEntity (org.apache.cayenne.map.DbEntity)10 ArrayList (java.util.ArrayList)7 ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)7 HashMap (java.util.HashMap)6 QueryResponse (org.apache.cayenne.QueryResponse)6 DataNode (org.apache.cayenne.access.DataNode)6 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 MockEventManager (org.apache.cayenne.event.MockEventManager)5 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)5 GenericResponse (org.apache.cayenne.util.GenericResponse)5 List (java.util.List)4 MappingNamespace (org.apache.cayenne.map.MappingNamespace)4 Artist (org.apache.cayenne.testdo.testmap.Artist)4 Map (java.util.Map)3