Search in sources :

Example 1 with Person

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

the class DiffSyncTest method patchEntity_moveProperty.

@Test
public void patchEntity_moveProperty() 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"));
    Patch patch = new Patch(ops);
    Person person = new Person("Edmund", "Blackadder");
    Person patched = sync.apply(person, patch);
    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) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 2 with Person

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

the class DiffSyncTest method patchEntity_moveProperty_lostReturnPacket.

@Test
public void patchEntity_moveProperty_lostReturnPacket() throws Exception {
    DiffSync<Person> sync = new DiffSync<Person>(new MapBasedShadowStore("x"), Person.class);
    Person person = new Person("Edmund", "Blackadder");
    List<PatchOperation> ops1 = new ArrayList<PatchOperation>();
    ops1.add(new MoveOperation("/firstName", "/lastName"));
    VersionedPatch vPatch1 = new VersionedPatch(ops1, 0, 0);
    Person patched = sync.apply(person, vPatch1);
    assertEquals("Blackadder", patched.getFirstName());
    assertNull(patched.getLastName());
    VersionedPatch lostDiff = sync.diff(patched);
    assertEquals(1, lostDiff.getClientVersion());
    assertEquals(0, lostDiff.getServerVersion());
    List<PatchOperation> ops2 = new ArrayList<PatchOperation>();
    ops2.add(new MoveOperation("/lastName", "/firstName"));
    VersionedPatch vPatch2 = new VersionedPatch(ops2, 0, 1);
    patched = sync.apply(patched, vPatch1, vPatch2);
    VersionedPatch diff = sync.diff(patched);
    assertEquals(2, diff.getClientVersion());
    assertEquals(0, diff.getServerVersion());
    assertNull(patched.getFirstName());
    assertEquals("Blackadder", 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 3 with Person

use of org.springframework.sync.Person 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 4 with Person

use of org.springframework.sync.Person 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

ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 MoveOperation (org.springframework.sync.MoveOperation)4 PatchOperation (org.springframework.sync.PatchOperation)4 Person (org.springframework.sync.Person)4 MapBasedShadowStore (org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore)4 Patch (org.springframework.sync.Patch)1