Search in sources :

Example 51 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class RemoteRollbackIT method testRollbackNewObject.

@Test
public void testRollbackNewObject() {
    String o1Name = "revertTestClientMtTable1";
    ClientMtTable1 o1 = clientContext.newObject(ClientMtTable1.class);
    o1.setGlobalAttribute1(o1Name);
    clientContext.rollbackChanges();
    assertEquals(PersistenceState.TRANSIENT, o1.getPersistenceState());
    clientContext.commitChanges();
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) Test(org.junit.Test)

Example 52 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class HessianROPSerializationServiceIT method testByteArraySerialization.

@Test
public void testByteArraySerialization() throws Exception {
    ClientMtTable1 table1 = context.newObject(ClientMtTable1.class);
    table1.setGlobalAttribute1("Test table1");
    ClientMtTable2 table2 = context.newObject(ClientMtTable2.class);
    table2.setGlobalAttribute("Test table2");
    table2.setTable1(table1);
    ROPSerializationService clientService = createClientSerializationService();
    ROPSerializationService serverService = createServerSerializationService();
    // test client to server serialization
    byte[] data = clientService.serialize(table2);
    ClientMtTable2 serverTable2 = serverService.deserialize(data, ClientMtTable2.class);
    assertEquals("Test table2", serverTable2.getGlobalAttribute());
    assertEquals("Test table1", serverTable2.getTable1().getGlobalAttribute1());
    // test server to client serialization
    data = serverService.serialize(table2);
    ClientMtTable2 clientTable2 = clientService.deserialize(data, ClientMtTable2.class);
    assertEquals("Test table2", clientTable2.getGlobalAttribute());
    assertEquals("Test table1", clientTable2.getTable1().getGlobalAttribute1());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ClientMtTable2(org.apache.cayenne.testdo.mt.ClientMtTable2) ROPSerializationService(org.apache.cayenne.rop.ROPSerializationService) Test(org.junit.Test)

Example 53 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class ObjectDetachOperationIT method testDetachCommitted.

@Test
public void testDetachCommitted() {
    EntityResolver serverResover = serverContext.getEntityResolver();
    EntityResolver clientResolver = serverResover.getClientEntityResolver();
    ObjectDetachOperation op = new ObjectDetachOperation(clientResolver);
    ObjectId oid = new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 456);
    MtTable1 so = new MtTable1();
    so.setObjectId(oid);
    so.setGlobalAttribute1("gx");
    so.setPersistenceState(PersistenceState.COMMITTED);
    so.setObjectContext(serverContext);
    serverContext.getGraphManager().registerNode(oid, so);
    Object detached = op.detach(so, serverResover.getClassDescriptor("MtTable1"), null);
    assertNotNull(detached);
    assertNotSame(so, detached);
    assertTrue(detached instanceof ClientMtTable1);
    ClientMtTable1 co = (ClientMtTable1) detached;
    assertEquals(oid, co.getObjectId());
    assertEquals("gx", co.getGlobalAttribute1());
    assertEquals(PersistenceState.TRANSIENT, co.getPersistenceState());
    assertNull(co.getObjectContext());
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) MtTable1(org.apache.cayenne.testdo.mt.MtTable1) ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ObjectId(org.apache.cayenne.ObjectId) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 54 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class PersistentObjectListTest method testResolvedHessianSerialization.

@Test
public void testResolvedHessianSerialization() throws Exception {
    ClientMtTable1 owner = new ClientMtTable1();
    owner.setPersistenceState(PersistenceState.COMMITTED);
    owner.setGlobalAttribute1("a");
    PersistentObjectList list = new PersistentObjectList(owner, "x");
    List<Object> objects = new ArrayList<>();
    objects.add("a");
    objects.add("b");
    list.setObjectList(objects);
    assertFalse(list.isFault());
    Object deserialized = HessianUtil.cloneViaServerClientSerialization(list, new EntityResolver());
    assertNotNull(deserialized);
    assertTrue("Invalid deserialized: " + deserialized.getClass().getName(), deserialized instanceof PersistentObjectList);
    PersistentObjectList dlist = (PersistentObjectList) deserialized;
    assertFalse(dlist.isFault());
    assertNotNull(dlist.getRelationshipOwner());
    assertEquals("x", dlist.getRelationshipName());
    assertEquals(objects, dlist.objectList);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) ArrayList(java.util.ArrayList) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 55 with ClientMtTable1

use of org.apache.cayenne.testdo.mt.ClientMtTable1 in project cayenne by apache.

the class PersistentObjectListTest method testFaultHessianSerialization.

@Test
public void testFaultHessianSerialization() throws Exception {
    ClientMtTable1 owner = new ClientMtTable1();
    owner.setPersistenceState(PersistenceState.COMMITTED);
    owner.setGlobalAttribute1("a");
    PersistentObjectList list = new PersistentObjectList(owner, "x");
    assertTrue(list.isFault());
    Object deserialized = HessianUtil.cloneViaServerClientSerialization(list, new EntityResolver());
    // faults are writtens as nulls
    assertNull(deserialized);
}
Also used : ClientMtTable1(org.apache.cayenne.testdo.mt.ClientMtTable1) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

ClientMtTable1 (org.apache.cayenne.testdo.mt.ClientMtTable1)112 Test (org.junit.Test)112 ClientMtTable2 (org.apache.cayenne.testdo.mt.ClientMtTable2)46 SelectQuery (org.apache.cayenne.query.SelectQuery)26 UnitTestClosure (org.apache.cayenne.unit.di.UnitTestClosure)19 ObjectContext (org.apache.cayenne.ObjectContext)12 Expression (org.apache.cayenne.exp.Expression)12 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)11 List (java.util.List)8 ObjectId (org.apache.cayenne.ObjectId)7 EntityResolver (org.apache.cayenne.map.EntityResolver)7 LifecycleCallbackRegistry (org.apache.cayenne.reflect.LifecycleCallbackRegistry)7 RemoteIncrementalFaultList (org.apache.cayenne.remote.RemoteIncrementalFaultList)6 GraphDiff (org.apache.cayenne.graph.GraphDiff)5 MockEventManager (org.apache.cayenne.event.MockEventManager)4 ClientChannelServerDiffsListener1 (org.apache.cayenne.remote.ClientChannelServerDiffsListener1)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 GraphChangeHandler (org.apache.cayenne.graph.GraphChangeHandler)3 MtTable1 (org.apache.cayenne.testdo.mt.MtTable1)3