use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method dataClassBindingWithLocalDate.
@PathPatternsParameterizedTest
void dataClassBindingWithLocalDate(boolean usePathPatterns) throws Exception {
initDispatcherServlet(DateClassController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/bind");
request.addParameter("date", "2010-01-01");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("2010-01-01");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method httpHead.
@PathPatternsParameterizedTest
void httpHead(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ResponseEntityController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("HEAD", "/baz");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeader("MyResponseHeader")).isEqualTo("MyValue");
assertThat(response.getContentLength()).isEqualTo(4);
assertThat(response.getContentAsByteArray().length == 0).isTrue();
// Now repeat with GET
request = new MockHttpServletRequest("GET", "/baz");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeader("MyResponseHeader")).isEqualTo("MyValue");
assertThat(response.getContentLength()).isEqualTo(4);
assertThat(response.getContentAsString()).isEqualTo("body");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method contentTypeHeaders.
@PathPatternsParameterizedTest
void contentTypeHeaders(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ContentTypeHeadersController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/something");
request.setContentType("application/pdf");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("pdf");
request = new MockHttpServletRequest("POST", "/something");
request.setContentType("text/html");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("text");
request = new MockHttpServletRequest("POST", "/something");
request.setContentType("application/xml");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(415);
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method restController.
@PathPatternsParameterizedTest
void restController(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ThisWillActuallyRun.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("Hello World!");
}
use of org.springframework.web.servlet.handler.PathPatternsParameterizedTest 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");
}
Aggregations