}
@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"));
}