Search in sources :

Example 66 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchRemovesAnItem.

@Test
public void patchRemovesAnItem() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-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 67 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchUpdatesStatusOnOneItemAndRemovesTwoOtherItems.

@Test
public void patchUpdatesStatusOnOneItemAndRemovesTwoOtherItems() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-change-status-and-delete-two-items")).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(1L, "A", 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 68 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchSendsEntityDescriptionChange.

@Test
public void patchSendsEntityDescriptionChange() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH + "/2").content(resource("patch-change-entity-description")).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, "BBB", false), 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 69 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-sync by spring-projects.

the class DiffSyncControllerTest method patchRemovesTwoItems.

@Test
public void patchRemovesTwoItems() throws Exception {
    TodoRepository todoRepository = todoRepository();
    MockMvc mvc = mockMvc(todoRepository);
    mvc.perform(patch(RESOURCE_PATH).content(resource("patch-remove-two-items")).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(1L, "A", 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 70 with MockMvc

use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.

the class MetricFilterAutoConfigurationTests method gaugeServiceThatThrows.

@Test
public void gaugeServiceThatThrows() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
    GaugeService gaugeService = context.getBean(GaugeService.class);
    willThrow(new IllegalStateException()).given(gaugeService).submit(anyString(), anyDouble());
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
    mvc.perform(get("/templateVarTest/foo")).andExpect(status().isOk());
    verify(context.getBean(CounterService.class)).increment("status.200.templateVarTest.someVariable");
    verify(context.getBean(GaugeService.class)).submit(eq("response.templateVarTest.someVariable"), anyDouble());
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) GaugeService(org.springframework.boot.actuate.metrics.GaugeService) Filter(javax.servlet.Filter) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Aggregations

MockMvc (org.springframework.test.web.servlet.MockMvc)97 Test (org.junit.Test)91 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)25 Todo (org.springframework.sync.Todo)16 List (java.util.List)15 TodoRepository (org.springframework.sync.TodoRepository)15 Filter (javax.servlet.Filter)13 MockServletContext (org.springframework.mock.web.MockServletContext)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 OncePerRequestFilter (org.springframework.web.filter.OncePerRequestFilter)9 MvcResult (org.springframework.test.web.servlet.MvcResult)6 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 Ignore (org.junit.Ignore)3 FilterChainProxy (org.springframework.security.web.FilterChainProxy)3 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 HttpSession (javax.servlet.http.HttpSession)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2