Search in sources :

Example 11 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class ResourceHandlerRegistryTests method setUp.

@Before
public void setUp() {
    this.registry = new ResourceHandlerRegistry(new GenericWebApplicationContext(), new MockServletContext());
    this.registration = registry.addResourceHandler("/resources/**");
    this.registration.addResourceLocations("classpath:org/springframework/web/servlet/config/annotation/");
    this.response = new MockHttpServletResponse();
}
Also used : GenericWebApplicationContext(org.springframework.web.context.support.GenericWebApplicationContext) MockServletContext(org.springframework.mock.web.test.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 12 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class UrlFilenameViewControllerTests method withPrefix.

@Test
public void withPrefix() throws Exception {
    UrlFilenameViewController ctrl = new UrlFilenameViewController();
    ctrl.setPrefix("mypre_");
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index.html");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = ctrl.handleRequest(request, response);
    assertEquals("mypre_index", mv.getViewName());
    assertTrue(mv.getModel().isEmpty());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 13 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class UrlFilenameViewControllerTests method multiLevelMappingWithFallback.

@Test
public void multiLevelMappingWithFallback() throws Exception {
    UrlFilenameViewController ctrl = new UrlFilenameViewController();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/docs/cvs/commit.html");
    exposePathInMapping(request, "/docs/cvs/commit.html");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = ctrl.handleRequest(request, response);
    assertEquals("docs/cvs/commit", mv.getViewName());
    assertTrue(mv.getModel().isEmpty());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 14 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class UrlFilenameViewControllerTests method withContextMapping.

@Test
public void withContextMapping() throws Exception {
    UrlFilenameViewController ctrl = new UrlFilenameViewController();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myapp/docs/cvs/commit.html");
    request.setContextPath("/myapp");
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = ctrl.handleRequest(request, response);
    assertEquals("docs/cvs/commit", mv.getViewName());
    assertTrue(mv.getModel().isEmpty());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 15 with MockHttpServletResponse

use of org.springframework.mock.web.test.MockHttpServletResponse in project spring-framework by spring-projects.

the class UrlFilenameViewControllerTests method withFlashAttributes.

@Test
public void withFlashAttributes() throws Exception {
    UrlFilenameViewController ctrl = new UrlFilenameViewController();
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/index");
    request.setAttribute(DispatcherServlet.INPUT_FLASH_MAP_ATTRIBUTE, new ModelMap("name", "value"));
    MockHttpServletResponse response = new MockHttpServletResponse();
    ModelAndView mv = ctrl.handleRequest(request, response);
    assertEquals("index", mv.getViewName());
    assertEquals(1, mv.getModel().size());
    assertEquals("value", mv.getModel().get("name"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) ModelMap(org.springframework.ui.ModelMap) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)171 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)162 Test (org.junit.Test)140 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)33 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)28 Before (org.junit.Before)19 MockServletContext (org.springframework.mock.web.test.MockServletContext)14 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)10 TestBean (org.springframework.tests.sample.beans.TestBean)9 HashMap (java.util.HashMap)8 FilterChain (javax.servlet.FilterChain)8 ServletException (javax.servlet.ServletException)7 HttpSession (javax.servlet.http.HttpSession)7 IOException (java.io.IOException)6 Map (java.util.Map)6 ServletRequest (javax.servlet.ServletRequest)6 ServletResponse (javax.servlet.ServletResponse)6