use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_changeSingleEntityStatusAndDescription.
@Test
public void patchList_changeSingleEntityStatusAndDescription() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-change-single-status-and-desc");
List<Todo> todos = getTodoList();
List<Todo> patched = sync.apply(todos, patch);
// original should remain unchanged
assertEquals(todos, getTodoList());
assertNotEquals(patched, todos);
assertEquals(3, patched.size());
assertEquals(todos.get(0), patched.get(0));
assertEquals(new Todo(2L, "BBB", true), patched.get(1));
assertEquals(todos.get(2), patched.get(2));
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore 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());
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_patchFailingOperationInMiddle.
@Test
public void patchList_patchFailingOperationInMiddle() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-failing-operation-in-middle");
List<Todo> todos = getTodoList();
List<Todo> patched = null;
try {
patched = sync.apply(todos, patch);
fail();
} catch (PatchException e) {
// original should remain unchanged
assertEquals(todos, getTodoList());
assertNull(patched);
}
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchEntity_stringProperty.
@Test
public void patchEntity_stringProperty() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("single-change-description");
Todo todo = new Todo(1L, "A", false);
Todo patched = sync.apply(todo, patch);
assertEquals(1L, patched.getId().longValue());
assertEquals("AAA", patched.getDescription());
assertFalse(patched.isComplete());
// original remains unchanged
assertEquals(1L, todo.getId().longValue());
assertEquals("A", todo.getDescription());
assertFalse(todo.isComplete());
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchEntity_emptyPatch.
//
// Apply patches - single entity
//
@Test
public void patchEntity_emptyPatch() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-empty");
Todo todo = new Todo(1L, "A", false);
Todo patched = sync.apply(todo, patch);
assertEquals(1L, patched.getId().longValue());
assertEquals("A", patched.getDescription());
assertFalse(patched.isComplete());
// original remains unchanged
assertEquals(1L, todo.getId().longValue());
assertEquals("A", todo.getDescription());
assertFalse(todo.isComplete());
}
Aggregations