use of org.apache.wicket.request.IRequestMapper 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;
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class HttpsMapperTest method getSchemeOfRequest.
@Test
public void getSchemeOfRequest() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
ServletWebRequest request = mock(ServletWebRequest.class);
HttpServletRequest req = mock(HttpServletRequest.class);
when(request.getContainerRequest()).thenReturn(req);
when(req.getScheme()).thenReturn("https");
assertThat(mapper.getSchemeOf(request), is(Scheme.HTTPS));
reset(req);
when(req.getScheme()).thenReturn("hTTps");
assertThat(mapper.getSchemeOf(request), is(Scheme.HTTPS));
reset(req);
when(req.getScheme()).thenReturn("http");
assertThat(mapper.getSchemeOf(request), is(Scheme.HTTP));
try {
reset(req);
when(req.getScheme()).thenReturn("ftp");
mapper.getSchemeOf(request);
assertThat("expected error", false);
} catch (IllegalStateException e) {
// expected
}
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class HttpsMapperTest method getDesiredSchemeOfPageClass.
@Test
public void getDesiredSchemeOfPageClass() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
assertThat(mapper.getDesiredSchemeFor(SecurePage.class), is(Scheme.HTTPS));
assertThat(mapper.getDesiredSchemeFor(SecureDecendantPage.class), is(Scheme.HTTPS));
assertThat(mapper.getDesiredSchemeFor(SecureMixinPage.class), is(Scheme.HTTPS));
assertThat(mapper.getDesiredSchemeFor(InsecurePage.class), is(Scheme.HTTP));
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class HttpsMapperTest method mapRequest.
@Test
public void mapRequest() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
ServletWebRequest request = mock(ServletWebRequest.class);
HttpServletRequest req = mock(HttpServletRequest.class);
when(request.getContainerRequest()).thenReturn(req);
// https handler on http request, redirect to https
setupRequest(req, "http", "localhost", 80, "/ctx", "foo=bar");
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
when(delegate.mapRequest(request)).thenReturn(handler);
IRequestHandler resolved = mapper.mapRequest(request);
assertThat(resolved, is(instanceOf(RedirectHandler.class)));
assertThat(((RedirectHandler) resolved).getUrl(), is("https://localhost/ctx?foo=bar"));
// http handler on http request, return the original handler
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
reset(delegate);
when(delegate.mapRequest(request)).thenReturn(handler);
setupRequest(req, "http", "localhost", 80, "/ctx", "foo=bar");
resolved = mapper.mapRequest(request);
assertThat(resolved, is(sameInstance(handler)));
}
Aggregations