Example #1
0
  @Test
  public void body() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setContent("abcd".getBytes());

    final Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getBodyAsString(), is("abcd"));
  }
Example #2
0
  @Test
  public void uri() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setScheme("https");
    httpRequest.setServerName("example.com");
    httpRequest.setServerPort(1234);
    httpRequest.setRequestURI("/test/a/b?a=1");

    Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getURI(), is(URI.create("https://example.com:1234/test/a/b?a=1")));
  }
Example #3
0
  @Test
  public void parametersURLEncoded() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setQueryString("param1%20name=param1%20value");
    httpRequest.setContent("param2%20name=param2%20value".getBytes());
    httpRequest.addHeader("content-type", "application/x-www-form-urlencoded");

    final Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getParameterNames(), containsInAnyOrder("param1%20name", "param2%20name"));
    assertThat(req.getParameterValues("param1%20name"), contains("param1%20value"));
    assertThat(req.getParameterValues("param2%20name"), contains("param2%20value"));
  }
Example #4
0
  @Test
  public void headers() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.addHeader("header1", "value11");
    httpRequest.addHeader("header2", "value21");
    httpRequest.addHeader("header2", "value22");

    final Request req = RequestUtils.convert(httpRequest);

    assertThat(req.getHeaderNames(), containsInAnyOrder("header1", "header2"));
    assertThat(req.getHeaderValues("header1"), contains("value11"));
    assertThat(req.getHeaderValues("header2"), contains("value21", "value22"));
  }
Example #5
0
 @Test
 public void method() throws IOException {
   final MockHttpServletRequest httpRequest = prepareEmptyRequest();
   Request req = RequestUtils.convert(httpRequest);
   assertThat(req.getMethod(), is("POST"));
 }