use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method defaultParameters.
@Test
public void defaultParameters() throws Exception {
initServletWithControllers(DefaultValueParamController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("foo--bar", response.getContentAsString());
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method requestBodyResponseBody.
@Test
public void requestBodyResponseBody() throws ServletException, IOException {
initServletWithControllers(RequestResponseBodyController.class);
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "Hello World";
request.setContent(requestBody.getBytes("UTF-8"));
request.addHeader("Content-Type", "text/plain; charset=utf-8");
request.addHeader("Accept", "text/*, */*");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals(200, response.getStatus());
assertEquals(requestBody, response.getContentAsString());
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method emptyValueMapping.
@Test
public void emptyValueMapping() throws Exception {
initServletWithControllers(ControllerWithEmptyValueMapping.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
request.setContextPath("/foo");
request.setServletPath("");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("test", response.getContentAsString());
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method relativePathDispatchingController.
@Test
public void relativePathDispatchingController() throws Exception {
initServletWithControllers(MyRelativePathDispatchingController.class);
getServlet().init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myHandle");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("myView", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/myApp/myOther");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("myOtherView", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/myApp/myLang");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("myLangView", response.getContentAsString());
request = new MockHttpServletRequest("GET", "/myApp/surprise.do");
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("mySurpriseView", response.getContentAsString());
}
use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method restController.
@Test
public void restController() throws Exception {
initServletWithControllers(ThisWillActuallyRun.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals("Hello World!", response.getContentAsString());
}
Aggregations