use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method correctlyRecordsMetricsForFailedDeferredResultResponse.
@Test
public void correctlyRecordsMetricsForFailedDeferredResultResponse() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
MetricsFilter filter = context.getBean(MetricsFilter.class);
CountDownLatch latch = new CountDownLatch(1);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController(latch)).addFilter(filter).build();
String attributeName = MetricsFilter.class.getName() + ".StopWatch";
MvcResult result = mvc.perform(post("/createFailure")).andExpect(status().isOk()).andExpect(request().asyncStarted()).andExpect(request().attribute(attributeName, is(notNullValue()))).andReturn();
latch.countDown();
try {
mvc.perform(asyncDispatch(result));
fail();
} catch (Exception ex) {
assertThat(result.getRequest().getAttribute(attributeName)).isNull();
verify(context.getBean(CounterService.class)).increment("status.500.createFailure");
} finally {
context.close();
}
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method recordsHttpInteractionsWithDoubleWildcardMapping.
@Test
public void recordsHttpInteractionsWithDoubleWildcardMapping() 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("/doubleWildcardMapping/foo/bar/baz")).andExpect(status().isOk());
verify(context.getBean(CounterService.class)).increment("status.200.doubleWildcardMapping.star-star.baz");
verify(context.getBean(GaugeService.class)).submit(eq("response.doubleWildcardMapping.star-star.baz"), anyDouble());
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method records5xxxHttpInteractionsAsSingleMetric.
@Test
public void records5xxxHttpInteractionsAsSingleMetric() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class, ServiceUnavailableFilter.class);
MetricsFilter filter = context.getBean(MetricsFilter.class);
MockMvc mvc = MockMvcBuilders.standaloneSetup(new MetricFilterTestController()).addFilter(filter).addFilter(context.getBean(ServiceUnavailableFilter.class)).build();
mvc.perform(get("/unknownPath/1")).andExpect(status().isServiceUnavailable());
mvc.perform(get("/unknownPath/2")).andExpect(status().isServiceUnavailable());
verify(context.getBean(CounterService.class), times(2)).increment("status.503.unmapped");
verify(context.getBean(GaugeService.class), times(2)).submit(eq("response.unmapped"), anyDouble());
context.close();
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class DeviceResolverAutoConfigurationTests method deviceHandlerMethodArgumentWorksWithSpringData.
@Test
public void deviceHandlerMethodArgumentWorksWithSpringData() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.register(Config.class);
this.context.setServletContext(new MockServletContext());
this.context.refresh();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
mockMvc.perform(get("/")).andExpect(status().isOk());
}
use of org.springframework.test.web.servlet.MockMvc in project spring-boot by spring-projects.
the class SpringBootWebSecurityConfigurationTests method defaultHeaderConfiguration.
@Test
public void defaultHeaderConfiguration() throws Exception {
this.context = SpringApplication.run(VanillaWebConfiguration.class, "--server.port=0");
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup((WebApplicationContext) this.context).addFilters((FilterChainProxy) this.context.getBean("springSecurityFilterChain", Filter.class)).build();
mockMvc.perform(MockMvcRequestBuilders.get("/")).andExpect(MockMvcResultMatchers.header().string("X-Content-Type-Options", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().string("X-XSS-Protection", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().string("Cache-Control", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().string("X-Frame-Options", is(notNullValue()))).andExpect(MockMvcResultMatchers.header().doesNotExist("Content-Security-Policy"));
}
Aggregations