Search in sources :

Example 6 with NodeCreateOperation

use of org.apache.cayenne.graph.NodeCreateOperation in project cayenne by apache.

the class ObjectContextChangeLogSubListMessageFactoryTest method testGetDiffsSerializable.

@Test
public void testGetDiffsSerializable() throws Exception {
    ObjectContextChangeLog recorder = new ObjectContextChangeLog();
    recorder.addOperation(new NodeCreateOperation(new ObjectId("test")));
    CompoundDiff diff = (CompoundDiff) recorder.getDiffs();
    byte[] data = serializationService.serialize(diff);
    CompoundDiff diff0 = serializationService.deserialize(data, CompoundDiff.class);
    assertNotNull(diff0);
    assertEquals(1, diff0.getDiffs().size());
}
Also used : NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) CompoundDiff(org.apache.cayenne.graph.CompoundDiff) Test(org.junit.Test)

Example 7 with NodeCreateOperation

use of org.apache.cayenne.graph.NodeCreateOperation in project cayenne by apache.

the class ObjectContextChangeLogTest method testGetDiffsSerializableWithHessian.

@Test
public void testGetDiffsSerializableWithHessian() throws Exception {
    ObjectContextChangeLog recorder = new ObjectContextChangeLog();
    // id must be a serializable object
    recorder.addOperation(new NodeCreateOperation("id-string"));
    CompoundDiff diff = (CompoundDiff) recorder.getDiffs();
    Object clone = HessianUtil.cloneViaClientServerSerialization(diff, new EntityResolver());
    assertNotNull(clone);
    assertTrue(clone instanceof CompoundDiff);
    CompoundDiff d1 = (CompoundDiff) clone;
    assertEquals(1, d1.getDiffs().size());
}
Also used : NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) EntityResolver(org.apache.cayenne.map.EntityResolver) CompoundDiff(org.apache.cayenne.graph.CompoundDiff) Test(org.junit.Test)

Example 8 with NodeCreateOperation

use of org.apache.cayenne.graph.NodeCreateOperation in project cayenne by apache.

the class ClientServerChannelIT method testSynchronizeCommit.

@Test
public void testSynchronizeCommit() throws Exception {
    SelectQuery query = new SelectQuery(MtTable1.class);
    // no changes...
    clientServerChannel.onSync(serverContext, mock(GraphDiff.class), DataChannel.FLUSH_CASCADE_SYNC);
    assertEquals(0, serverContext.performQuery(query).size());
    // introduce changes
    clientServerChannel.onSync(serverContext, new NodeCreateOperation(new ObjectId("MtTable1")), DataChannel.FLUSH_CASCADE_SYNC);
    assertEquals(1, serverContext.performQuery(query).size());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 9 with NodeCreateOperation

use of org.apache.cayenne.graph.NodeCreateOperation in project cayenne by apache.

the class SyncMessageTest method testHessianSerialization.

@Test
public void testHessianSerialization() throws Exception {
    // id must be a serializable object; source doesn't have to be
    ObjectContext source = mock(ObjectContext.class);
    GraphDiff diff = new NodeCreateOperation("id-string");
    SyncMessage message = new SyncMessage(source, DataChannel.FLUSH_NOCASCADE_SYNC, diff);
    Object d = HessianUtil.cloneViaClientServerSerialization(message, new EntityResolver());
    assertNotNull(d);
    assertTrue(d instanceof SyncMessage);
    SyncMessage ds = (SyncMessage) d;
    assertNull(ds.getSource());
    assertEquals(message.getType(), ds.getType());
    assertNotNull(ds.getSenderChanges());
}
Also used : NodeCreateOperation(org.apache.cayenne.graph.NodeCreateOperation) GraphDiff(org.apache.cayenne.graph.GraphDiff) ObjectContext(org.apache.cayenne.ObjectContext) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Aggregations

NodeCreateOperation (org.apache.cayenne.graph.NodeCreateOperation)9 Test (org.junit.Test)7 CompoundDiff (org.apache.cayenne.graph.CompoundDiff)4 GraphDiff (org.apache.cayenne.graph.GraphDiff)3 EntityResolver (org.apache.cayenne.map.EntityResolver)2 ObjectContext (org.apache.cayenne.ObjectContext)1 ObjectId (org.apache.cayenne.ObjectId)1 NodeDiff (org.apache.cayenne.graph.NodeDiff)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1