コード例 #1
0
  @Test
  public void contentTypeHeaderUTF8() {
    String contentType = "test/plain;charset=UTF-8";
    response.setHeader("Content-Type", contentType);
    assertEquals(contentType, response.getContentType());
    assertEquals(contentType, response.getHeader("Content-Type"));
    assertEquals("UTF-8", response.getCharacterEncoding());

    response = new MockHttpServletResponse();
    response.addHeader("Content-Type", contentType);
    assertEquals(contentType, response.getContentType());
    assertEquals(contentType, response.getHeader("Content-Type"));
    assertEquals("UTF-8", response.getCharacterEncoding());
  }
コード例 #2
0
  @Test
  public void contentTypeHeaderWithMoreComplexCharsetSyntax() {
    String contentType = "test/plain;charset=\"utf-8\";foo=\"charset=bar\";foocharset=bar;foo=bar";
    response.setHeader("Content-Type", contentType);
    assertEquals(contentType, response.getContentType());
    assertEquals(contentType, response.getHeader("Content-Type"));
    assertEquals("UTF-8", response.getCharacterEncoding());

    response = new MockHttpServletResponse();
    response.addHeader("Content-Type", contentType);
    assertEquals(contentType, response.getContentType());
    assertEquals(contentType, response.getHeader("Content-Type"));
    assertEquals("UTF-8", response.getCharacterEncoding());
  }
コード例 #3
0
  @Test
  public void contentTypeHeader() {
    String contentType = "test/plain";
    response.addHeader("Content-Type", contentType);
    assertEquals(contentType, response.getContentType());
    assertEquals(contentType, response.getHeader("Content-Type"));
    assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());

    response = new MockHttpServletResponse();
    response.setHeader("Content-Type", contentType);
    assertEquals(contentType, response.getContentType());
    assertEquals(contentType, response.getHeader("Content-Type"));
    assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
  }
コード例 #4
0
 @Test
 public void getDateHeader() {
   long time = 1437472800000L;
   response.setDateHeader("Last-Modified", time);
   assertEquals("Tue, 21 Jul 2015 10:00:00 GMT", response.getHeader("Last-Modified"));
   assertEquals(time, response.getDateHeader("Last-Modified"));
 }
コード例 #5
0
 @Test
 public void setContentTypeUTF8() {
   String contentType = "test/plain;charset=UTF-8";
   response.setContentType(contentType);
   assertEquals("UTF-8", response.getCharacterEncoding());
   assertEquals(contentType, response.getContentType());
   assertEquals(contentType, response.getHeader("Content-Type"));
 }
コード例 #6
0
 @Test
 public void setContentType() {
   String contentType = "test/plain";
   response.setContentType(contentType);
   assertEquals(contentType, response.getContentType());
   assertEquals(contentType, response.getHeader("Content-Type"));
   assertEquals(WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding());
 }
コード例 #7
0
 @Test
 public void setCharacterEncodingThenContentType() {
   response.setCharacterEncoding("UTF-8");
   response.setContentType("test/plain");
   assertEquals("test/plain", response.getContentType());
   assertEquals("test/plain;charset=UTF-8", response.getHeader("Content-Type"));
   assertEquals("UTF-8", response.getCharacterEncoding());
 }
コード例 #8
0
 @Test
 public void sendRedirect() throws IOException {
   String redirectUrl = "/redirect";
   response.sendRedirect(redirectUrl);
   assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
   assertEquals(redirectUrl, response.getHeader("Location"));
   assertEquals(redirectUrl, response.getRedirectedUrl());
   assertTrue(response.isCommitted());
 }
コード例 #9
0
 @Test(expected = IllegalArgumentException.class)
 public void getInvalidDateHeader() {
   response.setHeader("Last-Modified", "invalid");
   assertEquals("invalid", response.getHeader("Last-Modified"));
   response.getDateHeader("Last-Modified");
 }
コード例 #10
0
 @Test
 public void setDateHeader() {
   response.setDateHeader("Last-Modified", 1437472800000L);
   assertEquals("Tue, 21 Jul 2015 10:00:00 GMT", response.getHeader("Last-Modified"));
 }
コード例 #11
0
 @Test
 public void contentLengthHeader() {
   response.addHeader("Content-Length", "66");
   assertEquals(66, response.getContentLength());
   assertEquals("66", response.getHeader("Content-Length"));
 }