use of org.springframework.web.testfixture.servlet.MockHttpServletResponse 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.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method assertContentDisposition.
private void assertContentDisposition(RequestResponseBodyMethodProcessor processor, boolean expectContentDisposition, String requestURI, String comment) throws Exception {
this.servletRequest.setRequestURI(requestURI);
processor.handleReturnValue("body", this.returnTypeString, this.container, this.request);
String header = servletResponse.getHeader("Content-Disposition");
if (expectContentDisposition) {
assertThat(header).as("Expected 'Content-Disposition' header. Use case: '" + comment + "'").isEqualTo("inline;filename=f.txt");
} else {
assertThat(header).as("Did not expect 'Content-Disposition' header. Use case: '" + comment + "'").isNull();
}
this.servletRequest = new MockHttpServletRequest();
this.servletResponse = new MockHttpServletResponse();
this.request = new ServletWebRequest(servletRequest, servletResponse);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletCookieValueMethodArgumentResolverTests method setup.
@BeforeEach
public void setup() throws Exception {
resolver = new ServletCookieValueMethodArgumentResolver(null);
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request, new MockHttpServletResponse());
Method method = getClass().getMethod("params", Cookie.class, String.class);
cookieParameter = new SynthesizingMethodParameter(method, 0);
cookieStringParameter = new SynthesizingMethodParameter(method, 1);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method binderInitializingCommandProvidingFormController.
@PathPatternsParameterizedTest
void binderInitializingCommandProvidingFormController(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MyBinderInitializingCommandProvidingFormController.class, usePathPatterns, wac -> wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class)));
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
request.addParameter("defaultName", "myDefaultName");
request.addParameter("age", "value2");
request.addParameter("date", "2007-10-02");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method explicitAndEmptyPathsControllerMapping.
@PathPatternsParameterizedTest
void explicitAndEmptyPathsControllerMapping(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ExplicitAndEmptyPathsController.class, usePathPatterns);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("get");
request = new MockHttpServletRequest("GET", "");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getContentAsString()).isEqualTo("get");
}
Aggregations