use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class HttpsMapperTest method mapRequestWithCustomPorts.
@Test
public void mapRequestWithCustomPorts() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig(10, 20));
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", 10, "/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:20/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, "https", "localhost", 20, "/ctx", "foo=bar");
resolved = mapper.mapRequest(request);
assertThat(resolved, is(instanceOf(RedirectHandler.class)));
assertThat(((RedirectHandler) resolved).getUrl(), is("http://localhost:10/ctx?foo=bar"));
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class HttpsMapperTest method getDesiredSchemeOfHandler.
@Test
public void getDesiredSchemeOfHandler() {
IRequestMapper delegate = mock(IRequestMapper.class);
HttpsMapper mapper = new HttpsMapper(delegate, new HttpsConfig());
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.HTTPS));
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.HTTP));
handler = mock(IRequestHandler.class);
assertThat(mapper.getDesiredSchemeFor(handler), is(Scheme.ANY));
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class HttpsMapperTest method mapHandler.
@Test
public void mapHandler() {
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);
// rendering url to https page on http, set protocol
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(SecurePage.class));
Url url = new Url();
when(delegate.mapHandler(handler)).thenReturn(url);
when(req.getScheme()).thenReturn("http");
mapper.mapHandler(handler, request);
assertThat(url.getProtocol(), is("https"));
assertThat(url.getPort(), is(443));
// render url to http page on http, ignore protocol
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
url = new Url();
reset(delegate);
when(delegate.mapHandler(handler)).thenReturn(url);
when(req.getScheme()).thenReturn("http");
mapper.mapHandler(handler, request);
assertThat(url.getProtocol(), is(nullValue()));
// render url to http page on https, set protocol
handler = new RenderPageRequestHandler(new PageProvider(InsecurePage.class));
url = new Url();
reset(delegate);
when(delegate.mapHandler(handler)).thenReturn(url);
when(req.getScheme()).thenReturn("https");
mapper.mapHandler(handler, request);
assertThat(url.getProtocol(), is("http"));
assertThat(url.getPort(), is(80));
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class PageRequestHandlerTrackerTest method trackPagesWithMapperDelegate.
/**
* Uses PageRequestHandlerTracker to check last IRequestHandler encapsulated in IRequestHandlerDelegate
*/
@Test
public void trackPagesWithMapperDelegate() {
IRequestMapper mapper = tester.getApplication().getRootRequestMapper();
tester.getApplication().setRootRequestMapper(new MapperDelegate(mapper));
tester.startPage(new PageA());
tester.getApplication().setRootRequestMapper(mapper);
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class MountedMapperTest method construct2.
/**
* Overriding mounting on '/' (see HomePageMapper) should be possible
*/
@Test
public void construct2() {
IRequestMapper homePageMapper = new MountedMapper("/", MockPage.class);
assertNotNull(homePageMapper);
}
Aggregations