use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithValidationErrorAndConversionError.
@PathPatternsParameterizedTest
void dataClassBindingWithValidationErrorAndConversionError(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ValidatedDataClassController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bind");
request.addParameter("param2", "x");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("2:null-x-null");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method relativeMethodPathDispatchingController.
@PathPatternsParameterizedTest
void relativeMethodPathDispatchingController(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MyRelativeMethodPathDispatchingController.class, usePathPatterns, wac -> {
if (!usePathPatterns) {
RootBeanDefinition mappingDef = new RootBeanDefinition(RequestMappingHandlerMapping.class);
mappingDef.getPropertyValues().add("useSuffixPatternMatch", true);
wac.registerBeanDefinition("handlerMapping", mappingDef);
}
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myHandle");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myView");
request = new MockHttpServletRequest("GET", "/yourApp/myOther");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myOtherView");
request = new MockHttpServletRequest("GET", "/hisApp/myLang");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myLangView");
request = new MockHttpServletRequest("GET", "/herApp/surprise.do");
response = new MockHttpServletResponse();
getServlet().service(request, response);
if (!usePathPatterns) {
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContentAsString()).isEqualTo("mySurpriseView");
} else {
assertThat(response.getStatus()).as("Suffixes pattern matching should not work with PathPattern's").isEqualTo(404);
}
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method multipartFileAsSingleString.
@PathPatternsParameterizedTest
void multipartFileAsSingleString(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MultipartController.class, usePathPatterns);
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.setRequestURI("/singleString");
request.addFile(new MockMultipartFile("content", "Juergen".getBytes()));
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("Juergen");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method bridgeMethodsWithMultipleInterfaces.
@PathPatternsParameterizedTest
void bridgeMethodsWithMultipleInterfaces(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ArticleController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/method");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method requestParamMap.
@PathPatternsParameterizedTest
void requestParamMap(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestParamMapController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/map");
request.addParameter("key1", "value1");
request.addParameter("key2", "value21", "value22");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("key1=value1,key2=value21");
request.setRequestURI("/multiValueMap");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("key1=[value1],key2=[value21,value22]");
}
Aggregations