use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method whenExceptionIsThrownResponseStatusIsUsedWhenResponseHasBeenCommitted.
@Test
public void whenExceptionIsThrownResponseStatusIsUsedWhenResponseHasBeenCommitted() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
response.setCommitted(true);
throw new IOException();
}
}).given(chain).doFilter(request, response);
try {
filter.doFilter(request, response, chain);
fail();
} catch (IOException ex) {
// Continue
}
verify(context.getBean(CounterService.class)).increment(eq("status.200.test.path"));
context.close();
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class MetricFilterAutoConfigurationTests method additionallyRecordsMetricsWithHttpMethodNameIfConfigured.
@Test
public void additionallyRecordsMetricsWithHttpMethodNameIfConfigured() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(Config.class, MetricFilterAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(context, "endpoints.metrics.filter.gauge-submissions=merged,per-http-method", "endpoints.metrics.filter.counter-submissions=merged,per-http-method");
context.refresh();
Filter filter = context.getBean(Filter.class);
final MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/test/path");
final MockHttpServletResponse response = new MockHttpServletResponse();
FilterChain chain = mock(FilterChain.class);
willAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
response.setStatus(200);
return null;
}
}).given(chain).doFilter(request, response);
filter.doFilter(request, response, chain);
verify(context.getBean(GaugeService.class)).submit(eq("response.test.path"), anyDouble());
verify(context.getBean(GaugeService.class)).submit(eq("response.PUT.test.path"), anyDouble());
verify(context.getBean(CounterService.class)).increment(eq("status.200.test.path"));
verify(context.getBean(CounterService.class)).increment(eq("status.PUT.200.test.path"));
context.close();
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class LinksEnhancerTests method setup.
@Before
public void setup() {
MockHttpServletRequest request = new MockHttpServletRequest();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class CloudFoundryEndpointHandlerMappingTests method registersCloudFoundryHealthEndpoint.
@Test
public void registersCloudFoundryHealthEndpoint() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
HealthEndpoint delegate = new HealthEndpoint(new OrderedHealthAggregator(), Collections.<String, HealthIndicator>emptyMap());
CloudFoundryEndpointHandlerMapping handlerMapping = new CloudFoundryEndpointHandlerMapping(Collections.singleton(new TestHealthMvcEndpoint(delegate)), null, null);
handlerMapping.setPrefix("/test");
handlerMapping.setApplicationContext(context);
handlerMapping.afterPropertiesSet();
HandlerExecutionChain handler = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/test/health"));
HandlerMethod handlerMethod = (HandlerMethod) handler.getHandler();
Object handlerMethodBean = handlerMethod.getBean();
assertThat(handlerMethodBean).isInstanceOf(CloudFoundryHealthMvcEndpoint.class);
}
use of org.springframework.mock.web.MockHttpServletRequest in project spring-boot by spring-projects.
the class CloudFoundrySecurityInterceptorTests method setup.
@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
this.interceptor = new CloudFoundrySecurityInterceptor(this.tokenValidator, this.securityService, "my-app-id");
this.endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
this.handlerMethod = new HandlerMethod(this.endpoint, "invoke");
this.request = new MockHttpServletRequest();
this.response = new MockHttpServletResponse();
}
Aggregations