use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore 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());
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_addNewItem_duplicate.
//
// Guaranteed Delivery - Duplicate packet scenario
//
@Test
public void patchList_addNewItem_duplicate() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-add-new-item");
VersionedPatch versionedPatch = new VersionedPatch(patch.getOperations(), 0, 0);
VersionedPatch versionedPatch2 = new VersionedPatch(patch.getOperations(), 0, 0);
List<Todo> todos = getTodoList();
List<Todo> patched = sync.apply(todos, versionedPatch, versionedPatch2);
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());
// original should remain unchanged
assertEquals(todos, getTodoList());
assertNotEquals(patched, todos);
assertEquals(4, patched.size());
assertEquals(todos.get(0), patched.get(0));
assertEquals(todos.get(1), patched.get(1));
assertEquals(todos.get(2), patched.get(2));
assertEquals(new Todo(null, "D", false), patched.get(3));
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_emptyPatch.
//
// Apply patches - lists
//
@Test
public void patchList_emptyPatch() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-empty");
List<Todo> todos = getTodoList();
List<Todo> patched = sync.apply(todos, patch);
assertEquals(patched, getTodoList());
// original remains unchanged
assertEquals(todos, getTodoList());
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_addNewItem_normal.
//
// Guaranteed Delivery - Normal operations scenario
//
@Test
public void patchList_addNewItem_normal() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-add-new-item");
VersionedPatch versionedPatch = new VersionedPatch(patch.getOperations(), 0, 0);
List<Todo> todos = getTodoList();
List<Todo> patched = sync.apply(todos, versionedPatch);
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());
// original should remain unchanged
assertEquals(todos, getTodoList());
assertNotEquals(patched, todos);
assertEquals(4, patched.size());
assertEquals(todos.get(0), patched.get(0));
assertEquals(todos.get(1), patched.get(1));
assertEquals(todos.get(2), patched.get(2));
assertEquals(new Todo(null, "D", false), patched.get(3));
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchEntity_stringAndBooleanProperties.
@Test
public void patchEntity_stringAndBooleanProperties() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("single-change-status-and-desc");
Todo todo = new Todo(1L, "A", false);
Todo patched = sync.apply(todo, patch);
assertEquals(1L, patched.getId().longValue());
assertEquals("BBB", patched.getDescription());
assertTrue(patched.isComplete());
// original remains unchanged
assertEquals(1L, todo.getId().longValue());
assertEquals("A", todo.getDescription());
assertFalse(todo.isComplete());
}
Aggregations