use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithServletPart.
@PathPatternsParameterizedTest
void dataClassBindingWithServletPart(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ServletPartDataClassController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/bind");
request.setContentType("multipart/form-data");
request.addPart(new MockPart("param1", "value1".getBytes(StandardCharsets.UTF_8)));
request.addParameter("param2", "true");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("value1-true-0");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithMissingParameter.
@PathPatternsParameterizedTest
void dataClassBindingWithMissingParameter(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ValidatedDataClassController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bind");
request.addParameter("param1", "value1");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("1:value1-null-null");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method requiredParamMissing.
@PathPatternsParameterizedTest
void requiredParamMissing(boolean usePathPatterns) throws Exception {
WebApplicationContext webAppContext = initDispatcherServlet(RequiredParamController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).as("Invalid response status code").isEqualTo(HttpServletResponse.SC_BAD_REQUEST);
assertThat(webAppContext.isSingleton(RequiredParamController.class.getSimpleName())).isTrue();
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method mavResolver.
@PathPatternsParameterizedTest
void mavResolver(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ModelAndViewResolverController.class, usePathPatterns, wac -> {
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
ModelAndViewResolver[] mavResolvers = new ModelAndViewResolver[] { new MyModelAndViewResolver() };
adapterDef.getPropertyValues().add("modelAndViewResolvers", mavResolvers);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myValue");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method unsupportedPatchBody.
@PathPatternsParameterizedTest
void unsupportedPatchBody(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestResponseBodyController.class, usePathPatterns, wac -> {
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
StringHttpMessageConverter converter = new StringHttpMessageConverter();
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_PLAIN));
adapterDef.getPropertyValues().add("messageConverters", converter);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("PATCH", "/something");
String requestBody = "Hello World";
request.setContent(requestBody.getBytes(StandardCharsets.UTF_8));
request.addHeader("Content-Type", "application/pdf");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(415);
assertThat(response.getHeader("Accept-Patch")).isEqualTo("text/plain");
}
Aggregations