Search in sources :

Example 36 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest 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 MockWebRequest

use of org.apache.wicket.mock.MockWebRequest 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 MockWebRequest

use of org.apache.wicket.mock.MockWebRequest 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 MockWebRequest

use of org.apache.wicket.mock.MockWebRequest 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 MockWebRequest

use of org.apache.wicket.mock.MockWebRequest 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

MockWebRequest (org.apache.wicket.mock.MockWebRequest)54 Test (org.junit.Test)52 UrlRenderer (org.apache.wicket.request.UrlRenderer)47 Url (org.apache.wicket.request.Url)29 Locale (java.util.Locale)2 MockServletContext (org.apache.wicket.protocol.http.mock.MockServletContext)2 IRequestHandler (org.apache.wicket.request.IRequestHandler)2 Binder (com.google.inject.Binder)1 Module (com.google.inject.Module)1 Provider (com.google.inject.Provider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Session (org.apache.wicket.Session)1 MockApplication (org.apache.wicket.mock.MockApplication)1 WebSession (org.apache.wicket.protocol.http.WebSession)1 IExceptionMapper (org.apache.wicket.request.IExceptionMapper)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1