@Test public void shouldNotRedirectNonCruiseRequestsToGoPage() throws IOException, ServletException { Handler legacyRequestHandler = jetty6Server.legacyRequestHandler(); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getWriter()).thenReturn(new PrintWriter(new ByteArrayOutputStream())); HttpServletRequest req = mock(HttpServletRequest.class); when(req.getMethod()).thenReturn(HttpMethods.GET); legacyRequestHandler.handle("/cruise_but_not_quite", req, response, Handler.REQUEST); verifyNoMoreInteractions(response); legacyRequestHandler.handle("/something_totally_different", req, response, Handler.REQUEST); verifyNoMoreInteractions(response); }
@Test public void shouldGetLegacyRequestHandlerToHandleAllRequestSentToCruiseUrl() throws IOException, ServletException { Jetty6Server.LegacyUrlRequestHandler legacyUrlRequestHandler = (Jetty6Server.LegacyUrlRequestHandler) jetty6Server.legacyRequestHandler(); HttpServletResponse response = mock(HttpServletResponse.class); PrintWriter writer = mock(PrintWriter.class); when(response.getWriter()).thenReturn(writer); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn(HttpMethods.GET); legacyUrlRequestHandler.handle("/cruise/foo", request, response, 1); verify(response).setHeader("Location", "/go/foo"); verify(response).setStatus(HttpStatus.ORDINAL_301_Moved_Permanently); verify(response).setHeader("Content-Type", "text/plain"); verify(writer) .write( String.format( "Url(s) starting in '/cruise' have been permanently moved to '/go', please use the new path.")); verify(writer).close(); }