use of org.springframework.test.web.servlet.MockMvc 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.test.web.servlet.MockMvc 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.test.web.servlet.MockMvc 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));
}
use of org.springframework.test.web.servlet.MockMvc in project spring-sync by spring-projects.
the class DiffSyncControllerTest method mockMvc.
private MockMvc mockMvc(TodoRepository todoRepository) {
ShadowStore shadowStore = new MapBasedShadowStore("x");
PersistenceCallbackRegistry callbackRegistry = new PersistenceCallbackRegistry();
callbackRegistry.addPersistenceCallback(new JpaPersistenceCallback<Todo>(todoRepository, Todo.class));
DiffSyncController controller = new DiffSyncController(callbackRegistry, shadowStore);
MockMvc mvc = standaloneSetup(controller).setMessageConverters(new JsonPatchHttpMessageConverter()).build();
return mvc;
}
use of org.springframework.test.web.servlet.MockMvc in project spring-sync by spring-projects.
the class DiffSyncControllerTest method patchSendsAStatusChangeAndADescriptionChangeForSameItem.
@Test
public void patchSendsAStatusChangeAndADescriptionChangeForSameItem() throws Exception {
TodoRepository todoRepository = todoRepository();
MockMvc mvc = mockMvc(todoRepository);
mvc.perform(patch(RESOURCE_PATH).content(resource("patch-change-single-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, "A", false));
assertEquals(all.get(1), new Todo(2L, "BBB", true));
assertEquals(all.get(2), new Todo(3L, "C", false));
}
Aggregations