Пример #1
0
 @Test
 public void explicitStatusCodeHttp11() throws Exception {
   RedirectView rv = new RedirectView();
   rv.setUrl("http://url.somewhere.com");
   rv.setHttp10Compatible(false);
   rv.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
   MockHttpServletRequest request = createRequest();
   MockHttpServletResponse response = new MockHttpServletResponse();
   rv.render(new HashMap<String, Object>(), request, response);
   assertEquals(301, response.getStatus());
   assertEquals("http://url.somewhere.com", response.getHeader("Location"));
 }
Пример #2
0
 @Test
 public void attributeStatusCodeHttp11() throws Exception {
   RedirectView rv = new RedirectView();
   rv.setUrl("http://url.somewhere.com");
   rv.setHttp10Compatible(false);
   MockHttpServletRequest request = createRequest();
   request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.CREATED);
   MockHttpServletResponse response = new MockHttpServletResponse();
   rv.render(new HashMap<String, Object>(), request, response);
   assertEquals(201, response.getStatus());
   assertEquals("http://url.somewhere.com", response.getHeader("Location"));
 }
Пример #3
0
 @Test
 public void http11() throws Exception {
   RedirectView rv = new RedirectView();
   rv.setUrl("http://url.somewhere.com");
   rv.setHttp10Compatible(false);
   MockHttpServletRequest request = createRequest();
   MockHttpServletResponse response = new MockHttpServletResponse();
   request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
   request.setAttribute(
       DispatcherServlet.FLASH_MAP_MANAGER_ATTRIBUTE, new SessionFlashMapManager());
   rv.render(new HashMap<String, Object>(), request, response);
   assertEquals(303, response.getStatus());
   assertEquals("http://url.somewhere.com", response.getHeader("Location"));
 }
Пример #4
0
  @Test
  public void flashMap() throws Exception {
    RedirectView rv = new RedirectView();
    rv.setUrl("http://url.somewhere.com/path");
    rv.setHttp10Compatible(false);
    MockHttpServletRequest request = createRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    FlashMap flashMap = new FlashMap();
    flashMap.put("successMessage", "yay!");
    request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, flashMap);
    ModelMap model = new ModelMap("id", "1");
    rv.render(model, request, response);
    assertEquals(303, response.getStatus());
    assertEquals("http://url.somewhere.com/path?id=1", response.getHeader("Location"));

    assertEquals("/path", flashMap.getTargetRequestPath());
    assertEquals(model, flashMap.getTargetRequestParams().toSingleValueMap());
  }