Search in sources :

Example 21 with MapBasedShadowStore

use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.

the class DiffSyncTest method patchEntity_numericProperty.

@Test
public void patchEntity_numericProperty() throws Exception {
    DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
    Patch patch = readJsonPatchFromResource("single-change-id");
    Todo todo = new Todo(1L, "A", false);
    Todo patched = sync.apply(todo, patch);
    assertEquals(123L, 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());
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 22 with MapBasedShadowStore

use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.

the class DiffSyncTest method patchList_changeSingleEntityStatus.

@Test
public void patchList_changeSingleEntityStatus() throws Exception {
    DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
    Patch patch = readJsonPatchFromResource("patch-change-single-status");
    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, "B", true), patched.get(1));
    assertEquals(todos.get(2), patched.get(2));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 23 with MapBasedShadowStore

use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.

the class DiffSyncTest method patchList_modifyThenRemoveItem.

@Test
public void patchList_modifyThenRemoveItem() throws Exception {
    DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
    Patch patch = readJsonPatchFromResource("patch-modify-then-remove-item");
    List<Todo> todos = getTodoList();
    List<Todo> patched = sync.apply(todos, patch);
    // original should remain unchanged
    assertEquals(todos, getTodoList());
    assertNotEquals(patched, todos);
    assertEquals(2, patched.size());
    assertEquals(new Todo(1L, "A", false), patched.get(0));
    assertEquals(new Todo(3L, "C", false), patched.get(1));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 24 with MapBasedShadowStore

use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.

the class DiffSyncTest method patchList_deleteTwoItemsAndChangeStatusOnAnother.

@Test
public void patchList_deleteTwoItemsAndChangeStatusOnAnother() throws Exception {
    DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
    Patch patch = readJsonPatchFromResource("patch-delete-twoitems-and-change-status-on-another");
    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(3L, "C", true), patched.get(0));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 25 with MapBasedShadowStore

use of org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore in project spring-sync by spring-projects.

the class DiffSyncTest method patchList_removeItem.

@Test
public void patchList_removeItem() throws Exception {
    DiffSync<Todo> sync = new DiffSync<Todo>(new MapBasedShadowStore("x"), Todo.class);
    Patch patch = readJsonPatchFromResource("patch-remove-item");
    List<Todo> todos = getTodoList();
    List<Todo> patched = sync.apply(todos, patch);
    // original should remain unchanged
    assertEquals(todos, getTodoList());
    assertNotEquals(patched, todos);
    assertEquals(2, patched.size());
    assertEquals(new Todo(1L, "A", false), patched.get(0));
    assertEquals(new Todo(3L, "C", false), patched.get(1));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Aggregations

MapBasedShadowStore (org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore)26 Test (org.junit.Test)25 Todo (org.springframework.sync.Todo)22 Patch (org.springframework.sync.Patch)21 ArrayList (java.util.ArrayList)5 PatchOperation (org.springframework.sync.PatchOperation)5 MoveOperation (org.springframework.sync.MoveOperation)4 Person (org.springframework.sync.Person)4 PatchException (org.springframework.sync.PatchException)2 AddOperation (org.springframework.sync.AddOperation)1 PersistenceCallbackRegistry (org.springframework.sync.diffsync.PersistenceCallbackRegistry)1 ShadowStore (org.springframework.sync.diffsync.ShadowStore)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1