Search in sources :

Example 41 with UrlRenderer

use of org.apache.wicket.request.UrlRenderer in project wicket by apache.

the class UrlRendererTest method test12.

/**
 * <a href="https://issues.apache.org/jira/browse/WICKET-3567">WICKET-3567</a>
 */
@Test
public void test12() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("?0")));
    assertEquals("./", r1.renderUrl(Url.parse("")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 42 with UrlRenderer

use of org.apache.wicket.request.UrlRenderer in project wicket by apache.

the class UrlRendererTest method renderFullUrlWithNoOpLeadingSegments.

/**
 * https://issues.apache.org/jira/browse/WICKET-5774
 */
@Test
public void renderFullUrlWithNoOpLeadingSegments() {
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(Url.parse("any/thing")));
    String fullUrl = renderer.renderFullUrl(Url.parse("http://www.example.com:8888/./../one/two/three"));
    assertEquals("http://www.example.com:8888/one/two/three", fullUrl);
    fullUrl = renderer.renderFullUrl(Url.parse("http://www.example.com:8888/.././one/two/three"));
    assertEquals("http://www.example.com:8888/one/two/three", fullUrl);
    fullUrl = renderer.renderFullUrl(Url.parse("http://www.example.com:8888/one/.././two/three"));
    assertEquals("http://www.example.com:8888/two/three", fullUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 43 with UrlRenderer

use of org.apache.wicket.request.UrlRenderer in project wicket by apache.

the class ServletWebResponseTest method encodeAbsoluteUrl.

/**
 * WICKET-5582 absolute URLs stay absolute after encoding
 */
@Test
public void encodeAbsoluteUrl() {
    final String url = "http://localhost:8080/path";
    ServletWebRequest webRequest = mock(ServletWebRequest.class);
    when(webRequest.isAjax()).thenReturn(Boolean.FALSE);
    Url baseUrl = Url.parse("./baseUrl");
    baseUrl.setProtocol("http");
    baseUrl.setHost("someHost");
    baseUrl.setPort(80);
    when(webRequest.getClientUrl()).thenReturn(baseUrl);
    UrlRenderer renderer = new UrlRenderer(webRequest);
    RequestCycle requestCycle = mock(RequestCycle.class);
    ThreadContext.setRequestCycle(requestCycle);
    when(requestCycle.getUrlRenderer()).thenReturn(renderer);
    HttpServletResponse httpServletResponse = mock(HttpServletResponse.class);
    when(httpServletResponse.encodeURL(Matchers.eq(url))).thenReturn(url + ";foo");
    ServletWebResponse webResponse = new ServletWebResponse(webRequest, httpServletResponse);
    assertEquals(url + ";foo", webResponse.encodeURL(url));
}
Also used : RequestCycle(org.apache.wicket.request.cycle.RequestCycle) MockHttpServletResponse(org.apache.wicket.protocol.http.mock.MockHttpServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 44 with UrlRenderer

use of org.apache.wicket.request.UrlRenderer in project wicket by apache.

the class UrlRendererTest method renderFullUrlWithAbsoluteArgument.

/**
 * https://issues.apache.org/jira/browse/WICKET-4514
 */
@Test
public void renderFullUrlWithAbsoluteArgument() {
    Url baseUrl = Url.parse("one/two/three");
    baseUrl.setProtocol("http");
    baseUrl.setHost("www.example.com");
    baseUrl.setPort(8888);
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    // this is needed because MockWebRequest cuts data
    renderer.setBaseUrl(baseUrl);
    // url starting with slash is
    String fullUrl = renderer.renderFullUrl(Url.parse("/four"));
    // considered absolute
    assertEquals("http://www.example.com:8888/four", fullUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 45 with UrlRenderer

use of org.apache.wicket.request.UrlRenderer in project wicket by apache.

the class UrlRendererTest method rendersRelativeUrl.

@Test
public void rendersRelativeUrl() {
    Url contextRelativeUrl = new Url();
    contextRelativeUrl.setProtocol("http");
    contextRelativeUrl.setHost("localshot");
    contextRelativeUrl.setPort(8080);
    contextRelativeUrl.setContextRelative(true);
    contextRelativeUrl.getSegments().addAll(asList("", ""));
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(contextRelativeUrl));
    assertThat(r1.renderRelativeUrl(Url.parse("foo")), is("../foo"));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

UrlRenderer (org.apache.wicket.request.UrlRenderer)53 Test (org.junit.Test)49 MockWebRequest (org.apache.wicket.mock.MockWebRequest)47 Url (org.apache.wicket.request.Url)30 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 MockHttpServletResponse (org.apache.wicket.protocol.http.mock.MockHttpServletResponse)2 Before (org.junit.Before)2 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 IHeaderResponse (org.apache.wicket.markup.head.IHeaderResponse)1 HeaderResponse (org.apache.wicket.markup.head.internal.HeaderResponse)1 BufferedWebResponse (org.apache.wicket.protocol.http.BufferedWebResponse)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 Request (org.apache.wicket.request.Request)1 Response (org.apache.wicket.request.Response)1 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)1 WebRequest (org.apache.wicket.request.http.WebRequest)1 WebResponse (org.apache.wicket.request.http.WebResponse)1 IResource (org.apache.wicket.request.resource.IResource)1