@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());
  }
 @Test
 public void getRequestURLWithDefaultsAndHttps() {
   request.setScheme("https");
   request.setServerPort(443);
   StringBuffer requestURL = request.getRequestURL();
   assertEquals("https://localhost", requestURL.toString());
 }
Example #3
0
  @Test
  public void testIP() throws EndUserException {
    MockHttpServletRequest httpRequest =
        buildMock("http://10.20.3.5:9090/test/app/words/index/a", "/test");

    Request request = Request.get(httpRequest, null);
    request.setLocalContext(new String[] {"app", "words"});

    assertEquals("10.20.3.5", httpRequest.getLocalName());
    assertEquals(
        "http://10.20.3.5:9090/test/app/words/index/a", httpRequest.getRequestURL().toString());
    assertEquals(9090, httpRequest.getServerPort());

    assertEquals("10.20.3.5", request.getDomainName());
    assertEquals("10.20.3.5/test", request.getBaseDomainContext());
    assertTrue(request.isIP());

    assertEquals("/test", request.getBaseContext());
    assertEquals("/test/app/words", request.getLocalContext());

    String[] fullPath = request.getFullPath();
    assertArrayEquals(
        "Full path not as expected: " + StringUtils.join(fullPath, ","),
        new String[] {"app", "words", "index", "a"},
        fullPath);

    assertEquals("/index/a", request.getLocalPathAsString());
    assertArrayEquals(new String[] {"index", "a"}, request.getLocalPath());

    assertEquals("/test", request.getBaseContext());
  }
  @Test
  public void uri() throws Exception {
    String uri =
        "https://java.sun.com:8080/javase/6/docs/api/java/util/BitSet.html?foo=bar#and(java.util.BitSet)";
    this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, uri);
    MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);

    assertEquals("https", request.getScheme());
    assertEquals("foo=bar", request.getQueryString());
    assertEquals("java.sun.com", request.getServerName());
    assertEquals(8080, request.getServerPort());
    assertEquals("/javase/6/docs/api/java/util/BitSet.html", request.getRequestURI());
    assertEquals(
        "https://java.sun.com:8080/javase/6/docs/api/java/util/BitSet.html",
        request.getRequestURL().toString());
  }
 @Test
 public void getRequestURLWithNegativePort() {
   request.setServerPort(-99);
   StringBuffer requestURL = request.getRequestURL();
   assertEquals("http://localhost", requestURL.toString());
 }
 @Test
 public void getRequestURLWithNullRequestUri() {
   request.setRequestURI(null);
   StringBuffer requestURL = request.getRequestURL();
   assertEquals("http://localhost", requestURL.toString());
 }
 @Test
 public void getRequestURLWithDefaults() {
   StringBuffer requestURL = request.getRequestURL();
   assertEquals("http://localhost", requestURL.toString());
 }