Search in sources :

Example 26 with UrlRenderer

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

the class UrlRendererTest method renderUrlWithFragment.

/**
 * https://issues.apache.org/jira/browse/WICKET-5970
 */
@Test
public void renderUrlWithFragment() {
    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.renderUrl(urlWithFragment);
    assertEquals("http://localhost:8080/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 27 with UrlRenderer

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

the class UrlRendererTest method test1.

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

Example 28 with UrlRenderer

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

the class UrlRendererTest method renderUrlWithRelativeArgument.

/**
 * https://issues.apache.org/jira/browse/WICKET-4561
 * https://issues.apache.org/jira/browse/WICKET-4562
 */
@Test
public void renderUrlWithRelativeArgument() {
    Url baseUrl = Url.parse("one/two/three");
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    baseUrl.setProtocol("http");
    baseUrl.setHost("www.example.com");
    baseUrl.setPort(8888);
    renderer.setBaseUrl(baseUrl);
    Url newUrl = Url.parse("four");
    newUrl.setProtocol("https");
    String fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);
    newUrl = Url.parse("./four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);
    newUrl = Url.parse("./././four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);
    newUrl = Url.parse("../four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);
    newUrl = Url.parse(".././four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://www.example.com:8888/four", fullUrl);
    newUrl = Url.parse("../../../../four");
    newUrl.setProtocol("https");
    fullUrl = renderer.renderUrl(newUrl);
    assertEquals("https://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 29 with UrlRenderer

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

the class UrlRendererTest method test9.

/**
 */
@Test
public void test9() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("a/b/q/d/e")));
    assertEquals("../../../q/c/d/e", r1.renderUrl(Url.parse("a/q/c/d/e")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 30 with UrlRenderer

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

the class UrlRendererTest method renderFullUrlAsRelativeToAnAbsoluteBaseUrl.

@Test
public void renderFullUrlAsRelativeToAnAbsoluteBaseUrl() {
    Url baseUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b/c/d");
    Url encodedFullUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b;jsessionid=123456");
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    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)

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