Search in sources :

Example 31 with MockWebRequest

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

the class RequestCycleListenerTest method newRequestCycle.

private RequestCycle newRequestCycle(final RuntimeException exception) {
    final Response originalResponse = newResponse();
    Request request = new MockWebRequest(Url.parse("http://wicket.apache.org"));
    handler = new IRequestHandler() {

        @Override
        public void respond(IRequestCycle requestCycle) {
            if (exception != null) {
                throw exception;
            }
            responses++;
        }

        @Override
        public void detach(IRequestCycle requestCycle) {
            detaches++;
        }
    };
    IRequestMapper requestMapper = new IRequestMapper() {

        @Override
        public IRequestHandler mapRequest(Request request) {
            return handler;
        }

        @Override
        public Url mapHandler(IRequestHandler requestHandler) {
            throw new UnsupportedOperationException();
        }

        @Override
        public int getCompatibilityScore(Request request) {
            throw new UnsupportedOperationException();
        }
    };
    IExceptionMapper exceptionMapper = new IExceptionMapper() {

        @Override
        public IRequestHandler map(Exception e) {
            exceptionsMapped++;
            return null;
        }
    };
    RequestCycleContext context = new RequestCycleContext(request, originalResponse, requestMapper, exceptionMapper);
    RequestCycle cycle = new RequestCycle(context);
    if (Application.exists()) {
        cycle.getListeners().add(Application.get().getRequestCycleListeners());
    }
    return cycle;
}
Also used : Response(org.apache.wicket.request.Response) IRequestHandler(org.apache.wicket.request.IRequestHandler) IRequestCycle(org.apache.wicket.request.IRequestCycle) MockWebRequest(org.apache.wicket.mock.MockWebRequest) Request(org.apache.wicket.request.Request) MockWebRequest(org.apache.wicket.mock.MockWebRequest) IExceptionMapper(org.apache.wicket.request.IExceptionMapper) IRequestMapper(org.apache.wicket.request.IRequestMapper) IRequestCycle(org.apache.wicket.request.IRequestCycle) ReplaceHandlerException(org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)

Example 32 with MockWebRequest

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

the class UrlRendererTest method renderFullUrlAsRelativeToBaseUrlWithoutFilterPath.

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

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

the class UrlRendererTest method test14.

/**
 * WICKET-4920 prevent double slash
 */
@Test
public void test14() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(new Url()));
    assertEquals("./;jsessionid=1p87c5424zjuvd57kljcu2bwa?0-1.IBehaviorListener.1-component", r1.renderRelativeUrl(Url.parse("http://localhost:8080/;jsessionid=1p87c5424zjuvd57kljcu2bwa?0-1.IBehaviorListener.1-component")));
}
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 34 with MockWebRequest

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

the class UrlRendererTest method test13.

/**
 * https://issues.apache.org/jira/browse/WICKET-4401
 *
 * A Url should not ends with '..' because some web containers do not handle it properly. Using
 * '../' works better.
 */
@Test
public void test13() {
    UrlRenderer r1 = new UrlRenderer(new MockWebRequest(Url.parse("foo/bar")));
    assertEquals("../", r1.renderUrl(Url.parse("")));
}
Also used : MockWebRequest(org.apache.wicket.mock.MockWebRequest) UrlRenderer(org.apache.wicket.request.UrlRenderer) Test(org.junit.Test)

Example 35 with MockWebRequest

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

the class UrlRendererTest method renderFullUrlAsRelativeToBaseUrlWithFirstSegmentsEqualToTheFilterPath.

@Test
public void renderFullUrlAsRelativeToBaseUrlWithFirstSegmentsEqualToTheFilterPath() {
    // 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 'filterPath' is the actual filter path and should be ignored
    Url encodedFullUrl = Url.parse("http://host:8080/filterPath/a/b;jsessionid=123456");
    MockWebRequest request = new MockWebRequest(baseUrl);
    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)

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