@Test
 public void getURI() throws Exception {
   URI uri = new URI("http://example.com/path?query");
   mockRequest.setServerName(uri.getHost());
   mockRequest.setServerPort(uri.getPort());
   mockRequest.setRequestURI(uri.getPath());
   mockRequest.setQueryString(uri.getQuery());
   assertEquals("Invalid uri", uri, request.getURI());
 }
  private MockHttpServletRequest createMockAuthenticationRequest() {
    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setServletPath("/j_mock_post");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setRequestURI("/mycontext/j_mock_post");
    request.setContextPath("/mycontext");

    return request;
  }
  @Test
  public void getRequestWithCustomServerName() throws IOException {
    this.snippet
        .expectHttpRequest("get-request-custom-server-name")
        .withContents(httpRequest(GET, "/foo").header(HttpHeaders.HOST, "api.example.com"));

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
    request.setServerName("api.example.com");

    documentHttpRequest("get-request-custom-server-name").handle(result(request));
  }
  @Test
  public void getRequestURL() {
    request.setServerPort(8080);
    request.setRequestURI("/path");
    assertEquals("http://localhost:8080/path", request.getRequestURL().toString());

    request.setScheme("https");
    request.setServerName("example.com");
    request.setServerPort(8443);
    assertEquals("https://example.com:8443/path", request.getRequestURL().toString());
  }
Exemplo n.º 5
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")));
  }
Exemplo n.º 6
0
 private MockHttpServletRequest buildMock(String completeUrl, String contextPath) {
   try {
     URI uri = new URI(completeUrl);
     MockServletContext context = new MockServletContext();
     context.setContextPath(contextPath);
     MockHttpServletRequest httpRequest =
         new MockHttpServletRequest(context, "get", uri.getPath());
     httpRequest.setLocalName(uri.getHost());
     httpRequest.setServerName(uri.getHost());
     httpRequest.setServletPath(
         completeUrl.substring(completeUrl.indexOf(contextPath) + contextPath.length()));
     httpRequest.setContextPath(contextPath);
     httpRequest.setServerPort(uri.getPort());
     return httpRequest;
   } catch (URISyntaxException e) {
     return null;
   }
 }
 @Test
 public void getServerNameWithCustomName() {
   request.setServerName("example.com");
   assertEquals("example.com", request.getServerName());
 }