use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method typeNestedSetBinding.
@PathPatternsParameterizedTest
void typeNestedSetBinding(boolean usePathPatterns) throws Exception {
initDispatcherServlet(NestedSetController.class, usePathPatterns, wac -> {
RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
csDef.getPropertyValues().add("converters", new TestBeanConverter());
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("GET", "/myPath.do");
request.addParameter("testBeanSet", "1", "2");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("[1, 2]-org.springframework.beans.testfixture.beans.TestBean");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithFieldMarkerFallback.
@PathPatternsParameterizedTest
void dataClassBindingWithFieldMarkerFallback(boolean usePathPatterns) throws Exception {
initDispatcherServlet(DataClassController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bind");
request.addParameter("param1", "value1");
request.addParameter("_param2", "on");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("value1-false-0");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method optionalParamPresent.
@PathPatternsParameterizedTest
void optionalParamPresent(boolean usePathPatterns) throws Exception {
initDispatcherServlet(OptionalParamController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
request.addParameter("id", "val");
request.addParameter("flag", "true");
request.addHeader("header", "otherVal");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("val-true-otherVal");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithOptionalParameter.
@PathPatternsParameterizedTest
void dataClassBindingWithOptionalParameter(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ValidatedDataClassController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bind");
request.addParameter("param1", "value1");
request.addParameter("param2", "true");
request.addParameter("optionalParam", "8");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("value1-true-8");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method responseBodyNoAcceptableMediaType.
@PathPatternsParameterizedTest
void responseBodyNoAcceptableMediaType(boolean usePathPatterns) throws Exception {
initDispatcherServlet(RequestResponseBodyProducesController.class, usePathPatterns, wac -> {
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
StringHttpMessageConverter converter = new StringHttpMessageConverter();
adapterDef.getPropertyValues().add("messageConverters", converter);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "Hello World";
request.setContent(requestBody.getBytes(StandardCharsets.UTF_8));
request.addHeader("Content-Type", "text/plain; charset=utf-8");
request.addHeader("Accept", "application/pdf, application/msword");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(406);
}
Aggregations