Search in sources :

Example 1 with TodoRepository

use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.

the class DiffSyncControllerTest method statusChangedOnClient_itemDeletedFromServer.

@Test
@Ignore
public void statusChangedOnClient_itemDeletedFromServer() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    performNoOpRequestToSetupShadow(mvc);
    repository.delete(2L);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-change-single-status")).accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(content().string(resource("patch-remove-completed-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));
}
Also used : Todo(org.springframework.sync.Todo) List(java.util.List) TodoRepository(org.springframework.sync.TodoRepository) MockMvc(org.springframework.test.web.servlet.MockMvc) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with TodoRepository

use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchChangesItemStatusAndThenRemovesThatSameItem.

@Test
public void patchChangesItemStatusAndThenRemovesThatSameItem() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-modify-then-remove-item")).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(2, all.size());
    assertEquals(all.get(0), new Todo(1L, "A", false));
    assertEquals(all.get(1), new Todo(3L, "C", false));
}
Also used : Todo(org.springframework.sync.Todo) List(java.util.List) TodoRepository(org.springframework.sync.TodoRepository) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 3 with TodoRepository

use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchSendsSingleStatusChange.

@Test
public void patchSendsSingleStatusChange() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-change-single-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(all.get(0), new Todo(1L, "A", false));
    assertEquals(all.get(1), new Todo(2L, "B", true));
    assertEquals(all.get(2), new Todo(3L, "C", false));
}
Also used : Todo(org.springframework.sync.Todo) List(java.util.List) TodoRepository(org.springframework.sync.TodoRepository) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 4 with TodoRepository

use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchRemovesTwoOtherItemsAndUpdatesStatusOnAnother.

@Test
public void patchRemovesTwoOtherItemsAndUpdatesStatusOnAnother() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-delete-twoitems-and-change-status-on-another")).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(1, all.size());
    assertEquals(all.get(0), new Todo(3L, "C", true));
}
Also used : Todo(org.springframework.sync.Todo) List(java.util.List) TodoRepository(org.springframework.sync.TodoRepository) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 5 with TodoRepository

use of org.springframework.sync.TodoRepository in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchAddsAnItem.

@Test
@Ignore
public void patchAddsAnItem() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-add-new-item")).accept(JSON_PATCH).contentType(JSON_PATCH)).andExpect(status().isOk()).andExpect(content().string("[{\"op\":\"test\",\"path\":\"/3/id\"},{\"op\":\"add\",\"path\":\"/3/id\",\"value\":4}]")).andExpect(content().contentType(JSON_PATCH));
    List<Todo> all = (List<Todo>) repository.findAll();
    assertEquals(4, 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));
    assertEquals(all.get(2), new Todo(4L, "D", false));
}
Also used : Todo(org.springframework.sync.Todo) List(java.util.List) TodoRepository(org.springframework.sync.TodoRepository) MockMvc(org.springframework.test.web.servlet.MockMvc) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

List (java.util.List)15 Test (org.junit.Test)15 Todo (org.springframework.sync.Todo)15 TodoRepository (org.springframework.sync.TodoRepository)15 MockMvc (org.springframework.test.web.servlet.MockMvc)15 Ignore (org.junit.Ignore)3