use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method testMatchWithoutMethodLevelPath.
@PathPatternsParameterizedTest
void testMatchWithoutMethodLevelPath(boolean usePathPatterns) throws Exception {
initDispatcherServlet(NoPathGetAndM2PostController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/t1/m2");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(405);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method parameterCsvAsStringArray.
@PathPatternsParameterizedTest
void parameterCsvAsStringArray(boolean usePathPatterns) throws Exception {
initDispatcherServlet(CsvController.class, usePathPatterns, wac -> {
RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
wbiDef.getPropertyValues().add("conversionService", csDef);
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/integerArray");
request.setMethod("POST");
request.addParameter("content", "1,2");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("1-2");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method responseStatus.
@PathPatternsParameterizedTest
void responseStatus(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ResponseStatusController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/something");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("something");
assertThat(response.getStatus()).isEqualTo(201);
assertThat(response.getErrorMessage()).isEqualTo("It's alive!");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method httpHeadExplicit.
@PathPatternsParameterizedTest
void httpHeadExplicit(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ResponseEntityController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("HEAD", "/stores");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeader("h1")).isEqualTo("v1");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataRecordBinding.
@PathPatternsParameterizedTest
void dataRecordBinding(boolean usePathPatterns) throws Exception {
initDispatcherServlet(DataRecordController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bind");
request.addParameter("param1", "value1");
request.addParameter("param2", "true");
request.addParameter("param3", "3");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("value1-true-3");
}
Aggregations