Search in sources :

Example 11 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method renderFullUrlAsRelativeToBaseUrlWithFirstSegmentsEqualToTheContextAndFilterPaths.

@Test
public void renderFullUrlAsRelativeToBaseUrlWithFirstSegmentsEqualToTheContextAndFilterPaths() {
    // base url without context path and filter path
    // 'filterPath' here is a normal segment with the same value
    Url baseUrl = Url.parse("filterPath/a/b/c/d");
    // here 'contextPath' is the actual context path and should be ignored
    Url encodedFullUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b;jsessionid=123456");
    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setContextPath("contextPath");
    request.setFilterPath("filterPath");
    UrlRenderer renderer = new UrlRenderer(request);
    String encodedRelativeUrl = renderer.renderRelativeUrl(encodedFullUrl);
    assertEquals("../../../../a/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 12 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method test5.

/**
 */
@Test
public void test5() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("url")));
    assertEquals("./url?1", r1.renderUrl(Url.parse("url?1")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 13 with MockWebRequest

use of org.apache.wicket.mock.MockWebRequest in project wicket by apache.

the class UrlRendererTest method renderFullUrlAsRelativeToBaseUrlWithoutContextAndFilterPaths.

@Test
public void renderFullUrlAsRelativeToBaseUrlWithoutContextAndFilterPaths() {
    // base url without context path and filter path
    Url baseUrl = Url.parse("a/b/c/d");
    Url encodedFullUrl = Url.parse("http://host:8080/contextPath/filterPath/a/b;jsessionid=123456");
    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setContextPath("contextPath");
    request.setFilterPath("filterPath");
    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 14 with MockWebRequest

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

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

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