Search in sources :

Example 51 with MockWebRequest

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

the class UrlRendererTest method test7.

/**
 */
@Test
public void test7() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("MyTestPage/indexed1/indexed2/indexed3?10-27.ILinkListener-l2&p1=v1")));
    assertEquals("../../../MyTestPage?10", r1.renderUrl(Url.parse("MyTestPage?10")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 52 with MockWebRequest

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

the class UrlRendererTest method test8.

/**
 */
@Test
public void test8() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("en/first-test-page?16-1.ILinkListener-l1")));
    assertEquals("./first-test-page/indexed1/indexed2/indexed3?p1=v1", r1.renderUrl(Url.parse("en/first-test-page/indexed1/indexed2/indexed3?p1=v1")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 53 with MockWebRequest

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

the class UrlRendererTest method renderFullUrlWithRelativeArgument.

@Test
public void renderFullUrlWithRelativeArgument() {
    Url baseUrl = Url.parse("one/two/three");
    baseUrl.setProtocol("http");
    baseUrl.setHost("www.example.com");
    baseUrl.setPort(8888);
    UrlRenderer renderer = new UrlRenderer(new MockWebRequest(baseUrl));
    // this is needed because MockWebRequest cuts data
    renderer.setBaseUrl(baseUrl);
    String fullUrl = renderer.renderFullUrl(Url.parse("../four"));
    assertEquals("http://www.example.com:8888/one/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 54 with MockWebRequest

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

the class MetaInfStaticResourceReferenceTest method testWithServlet30.

/**
 * Test with Servlet 3.0 container
 *
 * @throws MalformedURLException
 *             should not happen
 */
@Test
public void testWithServlet30() throws MalformedURLException {
    MockApplication application = new MockApplication();
    MockServletContext servletContext = new MockServletContext(application, "/");
    BaseWicketTester tester = new BaseWicketTester(application, servletContext);
    MetaInfStaticResourceReference metaRes = new MetaInfStaticResourceReference(getClass(), STATIC_RESOURCE_NAME);
    PackageResourceReference packRes = new PackageResourceReference(getClass(), STATIC_RESOURCE_NAME);
    Url packUrl = tester.getRequestCycle().mapUrlFor(packRes, null);
    Url metaUrl = tester.getRequestCycle().mapUrlFor(metaRes, null);
    Assert.assertNotNull(metaUrl);
    Assert.assertNotNull(packUrl);
    Assert.assertFalse("Meta and pack resource should not map to the same url under servlet 3.0.", metaUrl.equals(packUrl));
    String metaUrlStr = metaUrl.toString();
    if (metaUrlStr.charAt(1) != '/') {
        metaUrlStr = "/" + metaUrlStr;
    }
    // meta resource is served by the servlet container under 3.0
    URL metaNetUrl = servletContext.getResource(metaUrlStr);
    Assert.assertNotNull("Meta resource is not found by the 3.0 servlet container.", metaNetUrl);
    MockWebRequest request = new MockWebRequest(packUrl);
    IRequestHandler requestHandler = tester.getApplication().getRootRequestMapper().mapRequest(request);
    // the pack resource is still served by wicket
    Assert.assertNotNull(requestHandler);
}
Also used : MockApplication(org.apache.wicket.mock.MockApplication) IRequestHandler(org.apache.wicket.request.IRequestHandler) MockWebRequest(org.apache.wicket.mock.MockWebRequest) BaseWicketTester(org.apache.wicket.util.tester.BaseWicketTester) MockServletContext(org.apache.wicket.protocol.http.mock.MockServletContext) Url(org.apache.wicket.request.Url) URL(java.net.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