Search in sources :

Example 36 with UrlRenderer

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

the class UrlRendererTest method test2.

/**
 */
@Test
public void test2() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("foo/bar/baz?a=b")));
    assertEquals("../../foo?x=y", r1.renderUrl(Url.parse("foo?x=y")));
    assertEquals("../../aaa?x=y", r1.renderUrl(Url.parse("aaa?x=y")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 37 with UrlRenderer

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

the class UrlRendererTest method renderRelativeUrlWithFragment.

/**
 * https://issues.apache.org/jira/browse/WICKET-5970
 */
@Test
public void renderRelativeUrlWithFragment() {
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(Url.parse("authorize")));
    Url urlWithFragment = Url.parse("http://localhost:8080/redirect#access_token=123456");
    assertEquals("access_token=123456", urlWithFragment.getFragment());
    String renderedUrl = renderer.renderRelativeUrl(urlWithFragment);
    assertEquals("./redirect#access_token=123456", renderedUrl);
}
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 38 with UrlRenderer

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

the class UrlRendererTest method renderContextAbsoluteUrlWithNoOpLeadingSegments.

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

Example 39 with UrlRenderer

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

the class UrlRendererTest method renderHomeUrl.

/**
 * https://issues.apache.org/jira/browse/WICKET-5123
 */
@Test
public void renderHomeUrl() {
    Url baseUrl = Url.parse("login");
    MockWebRequest request = new MockWebRequest(baseUrl);
    UrlRenderer renderer = new UrlRenderer(request);
    Url homeUrl = Url.parse("");
    String encodedRelativeUrl = renderer.renderUrl(homeUrl);
    assertEquals(".", encodedRelativeUrl);
}
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 40 with UrlRenderer

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

the class UrlRendererTest method test10.

/**
 */
@Test
public void test10() {
    MockWebRequest request = new MockWebRequest(Url.parse("a/b/q/d/e"), "/contextPath", "/filterPath", "../");
    UrlRenderer r = new UrlRenderer(request);
    assertEquals("../../../../../", r.renderContextRelativeUrl(""));
    assertEquals("../../../../../", r.renderContextRelativeUrl("/"));
    assertEquals("../../../../../f", r.renderContextRelativeUrl("/f"));
    assertEquals("../../../../../../f", r.renderContextRelativeUrl("../f"));
    try {
        r.renderContextRelativeUrl(null);
        fail("Null 'url' is not allowed!");
    } catch (IllegalArgumentException iax) {
        assertTrue(true);
    }
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) 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