Example usage for org.springframework.mock.web MockHttpServletRequest getContextPath

List of usage examples for org.springframework.mock.web MockHttpServletRequest getContextPath

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest getContextPath.

Prototype

@Override
    public String getContextPath() 

Source Link

Usage

From source file:org.cateproject.test.functional.mockmvc.HtmlUnitRequestBuilder.java

private void servletPath(MockHttpServletRequest result, String requestPath) {
    String servletPath = requestPath.substring(result.getContextPath().length());
    /*if ("".equals(servletPath)) {
       servletPath = null;/*from w  w  w .  ja  va 2 s  .  c om*/
    }*/
    result.setServletPath(servletPath);
}

From source file:org.cateproject.test.functional.mockmvc.HtmlUnitRequestBuilder.java

private com.gargoylesoftware.htmlunit.util.Cookie createCookie(MockHttpServletRequest request,
        String sessionid) {//from   w  w w.j a v a2s.  c  o  m
    return new com.gargoylesoftware.htmlunit.util.Cookie(request.getServerName(), "JSESSIONID", sessionid,
            request.getContextPath() + "/", null, request.isSecure(), true);
}

From source file:fr.xebia.servlet.filter.XForwardedFilterTest.java

@Test
public void testToAbsoluteInResponse() {
    // PREPARE//from w w w  .  j  av a2 s  . c o  m
    XForwardedFilter xFilter = new XForwardedFilter();
    MockHttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse mockResponse = new MockHttpServletResponse();
    XForwardedResponse response = xFilter.new XForwardedResponse(mockResponse, request);
    request.setScheme("http");
    request.setServerName("localhost");
    request.setServerPort(80);
    request.setContextPath("/context");
    request.setRequestURI("/context/dir/test");

    // TEST and VERIFY
    assertEquals("relative uri", "http://localhost/context/dir/relativeURI",
            response.toAbsolute("relativeURI"));
    assertEquals("relative to host uri", "http://localhost/relativeURI", response.toAbsolute("/relativeURI"));
    assertEquals("relative to context root uri", "http://localhost/context/relativeURI",
            response.toAbsolute(request.getContextPath() + "/relativeURI"));
    assertEquals("absolute uri", "https://server/othercontext/uri",
            response.toAbsolute("https://server/othercontext/uri"));
}

From source file:org.osaf.cosmo.BaseMockServletTestCase.java

/** */
protected String toAbsoluteUrl(MockHttpServletRequest request, String path) {
    StringBuffer url = new StringBuffer(request.getScheme());
    url.append("://").append(request.getServerName());
    if ((request.isSecure() && request.getServerPort() != 443) || (request.getServerPort() != 80)) {
        url.append(":").append(request.getServerPort());
    }/*from  w w  w  .ja v  a2s  . com*/
    if (!request.getContextPath().equals("/")) {
        url.append(request.getContextPath());
    }
    url.append(path);
    return url.toString();
}