use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_changeStatusAndDeleteTwoItems.
@Test
public void patchList_changeStatusAndDeleteTwoItems() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-change-status-and-delete-two-items");
List<Todo> todos = getTodoList();
List<Todo> patched = sync.apply(todos, patch);
// original should remain unchanged
assertEquals(todos, getTodoList());
assertNotEquals(patched, todos);
assertEquals(1, patched.size());
assertEquals(new Todo(1L, "A", true), patched.get(0));
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore 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());
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_manySuccessfulOperations.
@Test
public void patchList_manySuccessfulOperations() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-many-successful-operations");
List<Todo> todos = getBigTodoList();
List<Todo> patched = sync.apply(todos, patch);
// original should remain unchanged
assertEquals(todos, getBigTodoList());
assertNotEquals(patched, todos);
assertEquals(6, patched.size());
assertEquals(new Todo(1L, "A", true), patched.get(0));
assertEquals(new Todo(2L, "B", true), patched.get(1));
assertEquals(new Todo(3L, "C", false), patched.get(2));
assertEquals(new Todo(4L, "C", false), patched.get(3));
assertEquals(new Todo(1L, "A", true), patched.get(4));
assertEquals(new Todo(5L, "E", false), patched.get(5));
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_changeTwoStatusAndDescription.
@Test
public void patchList_changeTwoStatusAndDescription() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-change-two-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(new Todo(1L, "AAA", false), patched.get(0));
assertEquals(new Todo(2L, "B", true), patched.get(1));
assertEquals(new Todo(3L, "C", false), patched.get(2));
}
use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.
the class DiffSyncTest method patchList_patchFailingOperationFirst.
@Test
public void patchList_patchFailingOperationFirst() throws Exception {
DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
Patch patch = readJsonPatchFromResource("patch-failing-operation-first");
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);
}
}
Aggregations