Search in sources :

Example 1 with MapBasedShadowStore

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));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 2 with MapBasedShadowStore

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());
}
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 3 with MapBasedShadowStore

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));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 4 with MapBasedShadowStore

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));
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) Patch(org.springframework.sync.Patch) Test(org.junit.Test)

Example 5 with MapBasedShadowStore

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);
    }
}
Also used : Todo(org.springframework.sync.Todo) MapBasedShadowStore(org.springframework.sync.diffsync.shadowstore.MapBasedShadowStore) PatchException(org.springframework.sync.PatchException) 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