Пример #1
0
  @Test
  public void shouldAddLegacyUrlRequestHandler() throws Exception {
    ArgumentCaptor<ContextHandler> captor = ArgumentCaptor.forClass(ContextHandler.class);
    jetty6Server.configure();

    verify(server, times(4)).addHandler(captor.capture());
    List<ContextHandler> handlers = captor.getAllValues();
    assertThat(handlers.size(), is(4));
    ContextHandler handler = handlers.get(1);
    assertThat(handler instanceof Jetty6Server.LegacyUrlRequestHandler, is(true));
    Jetty6Server.LegacyUrlRequestHandler legacyUrlRequestHandler =
        (Jetty6Server.LegacyUrlRequestHandler) handler;
    assertThat(legacyUrlRequestHandler.getContextPath(), is("/cruise"));
  }
Пример #2
0
  @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();
  }