Search in sources :

Example 21 with MockWebRequest

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

the class UrlRendererTest method test3.

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

Example 22 with MockWebRequest

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

the class UrlRendererTest method removeCommonPrefixesWicket5073.

/**
 * https://issues.apache.org/jira/browse/WICKET-5073
 */
@Test
public void removeCommonPrefixesWicket5073() {
    Url baseUrl = new Url(Arrays.asList(""), Arrays.<Url.QueryParameter>asList());
    MockWebRequest request = new MockWebRequest(baseUrl);
    request.setContextPath("/qs");
    request.setFilterPath("");
    UrlRenderer renderer = new UrlRenderer(request);
    renderer.setBaseUrl(baseUrl);
    String rendered = renderer.renderRelativeUrl(Url.parse("wicket/resource/org.apache.wicket.Application/x.css"));
    assertEquals("./wicket/resource/org.apache.wicket.Application/x.css", rendered);
}
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 23 with MockWebRequest

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

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

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

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