Search in sources :

Example 1 with IExceptionMapper

use of org.apache.wicket.request.IExceptionMapper in project wicket by apache.

the class RequestCycleUrlForTest method before.

@Before
public void before() {
    Request request = mock(Request.class);
    Url baseUrl = Url.parse("");
    when(request.getClientUrl()).thenReturn(baseUrl);
    Response response = new StringResponse() {

        @Override
        public String encodeURL(CharSequence url) {
            return url + JSESSIONID;
        }
    };
    IRequestMapper mapper = mock(IRequestMapper.class);
    Url bookmarkablePageUrl = Url.parse(BOOKMARKABLE_PAGE_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<BookmarkablePageRequestHandler>(BookmarkablePageRequestHandler.class)))).thenReturn(bookmarkablePageUrl);
    Url resourceUrl = Url.parse(RESOURCE_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceRequestHandler>(ResourceRequestHandler.class)))).thenReturn(resourceUrl);
    Url resourceReferenceUrl = Url.parse(RES_REF_URL);
    when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceReferenceRequestHandler>(ResourceReferenceRequestHandler.class)))).thenReturn(resourceReferenceUrl);
    IExceptionMapper exceptionMapper = mock(IExceptionMapper.class);
    RequestCycleContext context = new RequestCycleContext(request, response, mapper, exceptionMapper);
    requestCycle = new RequestCycle(context);
    requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
}
Also used : StringResponse(org.apache.wicket.response.StringResponse) Response(org.apache.wicket.request.Response) Request(org.apache.wicket.request.Request) StringResponse(org.apache.wicket.response.StringResponse) IExceptionMapper(org.apache.wicket.request.IExceptionMapper) IRequestMapper(org.apache.wicket.request.IRequestMapper) Url(org.apache.wicket.request.Url) Before(org.junit.Before)

Example 2 with IExceptionMapper

use of org.apache.wicket.request.IExceptionMapper 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)

Aggregations

IExceptionMapper (org.apache.wicket.request.IExceptionMapper)2 IRequestMapper (org.apache.wicket.request.IRequestMapper)2 Request (org.apache.wicket.request.Request)2 Response (org.apache.wicket.request.Response)2 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 IRequestCycle (org.apache.wicket.request.IRequestCycle)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 ReplaceHandlerException (org.apache.wicket.request.RequestHandlerExecutor.ReplaceHandlerException)1 Url (org.apache.wicket.request.Url)1 StringResponse (org.apache.wicket.response.StringResponse)1 Before (org.junit.Before)1