Search in sources :

Example 6 with PatchOperation

use of org.springframework.sync.PatchOperation in project spring-sync by spring-projects.

the class DiffSyncTest method patchEntity_moveProperty_duplicate.

@Test
public void patchEntity_moveProperty_duplicate() throws Exception {
    DiffSync<Person> sync = new DiffSync<Person>(new MapBasedShadowStore("x"), Person.class);
    List<PatchOperation> ops = new ArrayList<PatchOperation>();
    ops.add(new MoveOperation("/firstName", "/lastName"));
    VersionedPatch vPatch1 = new VersionedPatch(ops, 0, 0);
    VersionedPatch vPatch2 = new VersionedPatch(ops, 0, 0);
    Person person = new Person("Edmund", "Blackadder");
    Person patched = sync.apply(person, vPatch1, vPatch2);
    VersionedPatch diff = sync.diff(patched);
    // the server is acknowledge client version 1 (the client should be at that version by this time)
    assertEquals(1, diff.getClientVersion());
    // the server created the patch against server version 0 (but it will be 1 after the patch is created)
    assertEquals(0, diff.getServerVersion());
    assertEquals("Blackadder", patched.getFirstName());
    assertNull(patched.getLastName());
}
Also used : MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) MoveOperation(org.springframework.sync.MoveOperation) ArrayList(java.util.ArrayList) PatchOperation(org.springframework.sync.PatchOperation) Person(org.springframework.sync.Person) Test(org.junit.Test)

Example 7 with PatchOperation

use of org.springframework.sync.PatchOperation in project spring-sync by spring-projects.

the class DiffSyncTest method patchEntity_moveProperty_normal.

@Test
public void patchEntity_moveProperty_normal() throws Exception {
    DiffSync<Person> sync = new DiffSync<Person>(new MapBasedShadowStore("x"), Person.class);
    List<PatchOperation> ops = new ArrayList<PatchOperation>();
    ops.add(new MoveOperation("/firstName", "/lastName"));
    VersionedPatch vPatch1 = new VersionedPatch(ops, 0, 0);
    Person person = new Person("Edmund", "Blackadder");
    Person patched = sync.apply(person, vPatch1);
    VersionedPatch diff = sync.diff(patched);
    // the server is acknowledge client version 1 (the client should be at that version by this time)
    assertEquals(1, diff.getClientVersion());
    // the server created the patch against server version 0 (but it will be 1 after the patch is created)
    assertEquals(0, diff.getServerVersion());
    assertEquals("Blackadder", patched.getFirstName());
    assertNull(patched.getLastName());
}
Also used : MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) MoveOperation(org.springframework.sync.MoveOperation) ArrayList(java.util.ArrayList) PatchOperation(org.springframework.sync.PatchOperation) Person(org.springframework.sync.Person) Test(org.junit.Test)

Aggregations

PatchOperation (org.springframework.sync.PatchOperation)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)5 MoveOperation (org.springframework.sync.MoveOperation)5 MapBasedShadowStore (org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore)5 Person (org.springframework.sync.Person)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 AddOperation (org.springframework.sync.AddOperation)2 Patch (org.springframework.sync.Patch)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CopyOperation (org.springframework.sync.CopyOperation)1 FromOperation (org.springframework.sync.FromOperation)1 PatchException (org.springframework.sync.PatchException)1 RemoveOperation (org.springframework.sync.RemoveOperation)1 ReplaceOperation (org.springframework.sync.ReplaceOperation)1 TestOperation (org.springframework.sync.TestOperation)1 Todo (org.springframework.sync.Todo)1