Search in sources :

Example 41 with MockHttpServletRequest

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

the class SimpleMappingExceptionResolverTests method setUp.

@Before
public void setUp() throws Exception {
    exceptionResolver = new SimpleMappingExceptionResolver();
    handler1 = new String();
    handler2 = new Object();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    request.setMethod("GET");
    genericException = new Exception();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Before(org.junit.Before)

Example 42 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest 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 43 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest 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 44 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest 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 45 with MockHttpServletRequest

use of org.springframework.mock.web.test.MockHttpServletRequest 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

MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)646 Test (org.junit.Test)540 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)330 Before (org.junit.Before)78 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)77 MockServletContext (org.springframework.mock.web.test.MockServletContext)56 TestBean (org.springframework.tests.sample.beans.TestBean)43 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)41 HttpServletResponse (javax.servlet.http.HttpServletResponse)40 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)37 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)30 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)29 ITestBean (org.springframework.tests.sample.beans.ITestBean)28 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)28 ServletException (javax.servlet.ServletException)27 HashMap (java.util.HashMap)26 FilterChain (javax.servlet.FilterChain)26 ModelAndViewContainer (org.springframework.web.method.support.ModelAndViewContainer)23 Cookie (javax.servlet.http.Cookie)22