use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.
the class DiffSyncControllerTest method patchSendsEntityStatusChange.
//
// entity patching
//
@Test
public void patchSendsEntityStatusChange() throws Exception {
TodoRepository todoRepository = todoRepository();
MockMvc mvc = mockMvc(todoRepository);
mvc.perform(patch(RESOURCE_PATH + "/2").content(resource("patch-change-entity-status")).accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(status().isOk()).andExpect(content().string("[]")).andExpect(content().contentType(JSON_PATCH));
List<Todo> all = (List<Todo>) repository.findAll();
assertEquals(3, all.size());
assertEquals(new Todo(1L, "A", false), all.get(0));
assertEquals(new Todo(2L, "B", true), all.get(1));
assertEquals(new Todo(3L, "C", false), all.get(2));
}
use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.
the class DiffSyncControllerTest method patchSendsAStatusChangeAndADescriptionChangeForDifferentItems.
@Test
public void patchSendsAStatusChangeAndADescriptionChangeForDifferentItems() throws Exception {
TodoRepository todoRepository = todoRepository();
MockMvc mvc = mockMvc(todoRepository);
mvc.perform(patch(RESOURCE_PATH).content(resource("patch-change-two-status-and-desc")).accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(status().isOk()).andExpect(content().string("[]")).andExpect(content().contentType(JSON_PATCH));
List<Todo> all = (List<Todo>) repository.findAll();
assertEquals(3, all.size());
assertEquals(all.get(0), new Todo(1L, "AAA", false));
assertEquals(all.get(1), new Todo(2L, "B", true));
assertEquals(all.get(2), new Todo(3L, "C", false));
}
use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.
the class DiffSyncControllerTest method patchSendsEntityIdChange.
@Test
public void patchSendsEntityIdChange() throws Exception {
TodoRepository todoRepository = todoRepository();
MockMvc mvc = mockMvc(todoRepository);
mvc.perform(patch(RESOURCE_PATH + "/2").content(resource("patch-change-entity-id")).accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(status().isOk()).andExpect(content().string("[]")).andExpect(content().contentType(JSON_PATCH));
List<Todo> all = (List<Todo>) repository.findAll();
assertEquals(4, all.size());
assertEquals(new Todo(1L, "A", false), all.get(0));
assertEquals(new Todo(2L, "B", false), all.get(1));
assertEquals(new Todo(3L, "C", false), all.get(2));
// This is odd behavior, but correct in the context of the backing database.
assertEquals(new Todo(4L, "B", false), all.get(3));
}
use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.
the class DiffSyncControllerTest method noChangesFromEitherSide.
//
// list patching
//
@Test
public void noChangesFromEitherSide() throws Exception {
TodoRepository todoRepository = todoRepository();
MockMvc mvc = mockMvc(todoRepository);
mvc.perform(patch(RESOURCE_PATH).content("[]").accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(content().string("[]")).andExpect(content().contentType(JSON_PATCH)).andExpect(status().isOk());
List<Todo> all = (List<Todo>) repository.findAll();
assertEquals(3, all.size());
assertEquals(all.get(0), new Todo(1L, "A", false));
assertEquals(all.get(1), new Todo(2L, "B", false));
assertEquals(all.get(2), new Todo(3L, "C", false));
}
use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.
the class DiffSyncControllerTest method noChangesFromClientSide_itemDeletedFromServer.
//
// server-side changes
//
@Test
@Ignore
public void noChangesFromClientSide_itemDeletedFromServer() throws Exception {
TodoRepository todoRepository = todoRepository();
MockMvc mvc = mockMvc(todoRepository);
performNoOpRequestToSetupShadow(mvc);
repository.delete(2L);
mvc.perform(patch(RESOURCE_PATH).content("[]").accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(content().string(resource("patch-remove-item"))).andExpect(content().contentType(JSON_PATCH)).andExpect(status().isOk());
List<Todo> all = (List<Todo>) repository.findAll();
assertEquals(2, all.size());
assertEquals(new Todo(1L, "A", false), all.get(0));
assertEquals(new Todo(3L, "C", false), all.get(1));
}