Search in sources :

Example 11 with MockMvc

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

the class MetricFilterAutoConfigurationTests method records302HttpInteractionsAsSingleMetric.

@Test
public void records302HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class, RedirectFilter.class);
    MetricsFilter filter = context.getBean(MetricsFilter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).addFilter(context.getBean(RedirectFilter.class)).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().is3xxRedirection());
    mvc.perform(get("/unknownPath/2")).andExpect(status().is3xxRedirection());
    verify(context.getBean(CounterService.class), times(2)).increment("status.302.unmapped");
    verify(context.getBean(GaugeService.class), times(2)).submit(eq("response.unmapped"), anyDouble());
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 12 with MockMvc

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

the class MetricFilterAutoConfigurationTests method recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable.

@Test
public void recordsKnown404HttpInteractionsAsSingleMetricWithPathAndTemplateVariable() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
    mvc.perform(get("/knownPath/foo")).andExpect(status().isNotFound());
    verify(context.getBean(CounterService.class)).increment("status.404.knownPath.someVariable");
    verify(context.getBean(GaugeService.class)).submit(eq("response.knownPath.someVariable"), anyDouble());
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Filter(javax.servlet.Filter) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 13 with MockMvc

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

the class MetricFilterAutoConfigurationTests method recordsHttpInteractionsWithTemplateVariable.

@Test
public void recordsHttpInteractionsWithTemplateVariable() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
    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) Filter(javax.servlet.Filter) OncePerRequestFilter(org.springframework.web.filter.OncePerRequestFilter) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.Test)

Example 14 with MockMvc

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

the class MetricFilterAutoConfigurationTests method recordsHttpInteractionsWithWildcardMapping.

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

Example 15 with MockMvc

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

the class MetricFilterAutoConfigurationTests method records404HttpInteractionsAsSingleMetric.

@Test
public void records404HttpInteractionsAsSingleMetric() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
    Filter filter = context.getBean(Filter.class);
    MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).build();
    mvc.perform(get("/unknownPath/1")).andExpect(status().isNotFound());
    mvc.perform(get("/unknownPath/2")).andExpect(status().isNotFound());
    verify(context.getBean(CounterService.class), times(2)).increment("status.404.unmapped");
    verify(context.getBean(GaugeService.class), times(2)).submit(eq("response.unmapped"), anyDouble());
    context.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) 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)92 Test (org.junit.Test)87 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 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)5 MvcResult (org.springframework.test.web.servlet.MvcResult)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