コード例 #1
0
  @Test
  public void header() throws Exception {
    this.builder.header("foo", "bar", "baz");

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    List<String> headers = Collections.list(request.getHeaders("foo"));

    assertEquals(2, headers.size());
    assertEquals("bar", headers.get(0));
    assertEquals("baz", headers.get(1));
  }
コード例 #2
0
  @Test
  public void contentType() throws Exception {
    this.builder.contentType(MediaType.TEXT_HTML);

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    String contentType = request.getContentType();
    List<String> contentTypes = Collections.list(request.getHeaders("Content-Type"));

    assertEquals("text/html", contentType);
    assertEquals(1, contentTypes.size());
    assertEquals("text/html", contentTypes.get(0));
  }
コード例 #3
0
  @Test
  public void acceptHeader() throws Exception {
    this.builder.accept(MediaType.TEXT_HTML, MediaType.APPLICATION_XML);

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    List<String> accept = Collections.list(request.getHeaders("Accept"));
    List<MediaType> result = MediaType.parseMediaTypes(accept.get(0));

    assertEquals(1, accept.size());
    assertEquals("text/html", result.get(0).toString());
    assertEquals("application/xml", result.get(1).toString());
  }
コード例 #4
0
  @Test
  public void headers() throws Exception {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.APPLICATION_JSON);
    httpHeaders.put("foo", Arrays.asList("bar", "baz"));
    this.builder.headers(httpHeaders);

    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
    List<String> headers = Collections.list(request.getHeaders("foo"));

    assertEquals(2, headers.size());
    assertEquals("bar", headers.get(0));
    assertEquals("baz", headers.get(1));
    assertEquals(MediaType.APPLICATION_JSON.toString(), request.getHeader("Content-Type"));
  }