Search in sources :

Example 16 with UrlRenderer

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

the class UrlRendererTest method renderFullUrlAsRelativeToBaseUrlWithoutComposedContextPath.

@Test
public void renderFullUrlAsRelativeToBaseUrlWithoutComposedContextPath() {
    // base url without context path and filter path
    Url baseUrl = Url.parse("a/b/c/d");
    Url encodedFullUrl = Url.parse("http://host:8080/filter/path/a/b;jsessionid=123456");
    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setFilterPath("filter/path");
    UrlRenderer renderer = new UrlRenderer(request);
    String encodedRelativeUrl = renderer.renderRelativeUrl(encodedFullUrl);
    assertEquals("../../b;jsessionid=123456", 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 17 with UrlRenderer

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

the class UrlRendererTest method renderUrlWithManyDotsAtTheBeginning1.

/**
 * https://issues.apache.org/jira/browse/WICKET-6230
 */
@Test
public void renderUrlWithManyDotsAtTheBeginning1() {
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(Url.parse("a")));
    String renderedUrl = renderer.renderUrl(Url.parse("...abc"));
    assertEquals("./...abc", renderedUrl);
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 18 with UrlRenderer

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

the class UrlRendererTest method test16.

/**
 * prevent another double slash when common prefix is present
 */
@Test
public void test16() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("private/AdminPage")).setContextPath("context"));
    assertEquals("../signIn;jsessionid=16k3wqa9c4sgq1cnp7fisa20u", r1.renderRelativeUrl(Url.parse("/context/signIn;jsessionid=16k3wqa9c4sgq1cnp7fisa20u")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 19 with UrlRenderer

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

the class UrlRendererTest method renderAbsoluteWithoutSchemeWithPort.

/**
 * https://issues.apache.org/jira/browse/WICKET-5065
 */
@Test
public void renderAbsoluteWithoutSchemeWithPort() {
    Url baseUrl = Url.parse("a/b");
    MockWebRequest request = new MockWebRequest(baseUrl);
    UrlRenderer renderer = new UrlRenderer(request);
    Url absoluteUrl = Url.parse("//host:1234/c/d");
    String encodedRelativeUrl = renderer.renderUrl(absoluteUrl);
    assertEquals("//host:1234/c/d", 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 20 with UrlRenderer

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

the class UrlRendererTest method renderAbsoluteWithoutScheme.

/**
 * https://issues.apache.org/jira/browse/WICKET-5065
 */
@Test
public void renderAbsoluteWithoutScheme() {
    Url baseUrl = Url.parse("a/b");
    MockWebRequest request = new MockWebRequest(baseUrl);
    UrlRenderer renderer = new UrlRenderer(request);
    Url absoluteUrl = Url.parse("//host/c/d");
    String encodedRelativeUrl = renderer.renderUrl(absoluteUrl);
    assertEquals("//host/c/d", 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)

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