Search in sources :

Example 6 with TodoRepository

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));
}
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 7 with TodoRepository

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));
}
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 8 with TodoRepository

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));
}
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 9 with TodoRepository

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));
}
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 10 with TodoRepository

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));
}
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