Пример #1
0
  @Test
  public void shouldGetWelcomeFileHandlerToIgnoreRequestsToNonRootUrl()
      throws IOException, ServletException {
    Jetty6Server.GoServerWelcomeFileHandler welcomeFileHandler =
        (Jetty6Server.GoServerWelcomeFileHandler) jetty6Server.welcomeFileHandler();
    HttpServletResponse response = mock(HttpServletResponse.class);

    welcomeFileHandler.handle("/foo", mock(HttpServletRequest.class), response, 1);
    verifyNoMoreInteractions(response);
  }
Пример #2
0
  @Test
  public void shouldGetWelcomeFileHandlerToHandleRequestsToRootUrl()
      throws IOException, ServletException {
    Jetty6Server.GoServerWelcomeFileHandler welcomeFileHandler =
        (Jetty6Server.GoServerWelcomeFileHandler) jetty6Server.welcomeFileHandler();
    HttpServletResponse response = mock(HttpServletResponse.class);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    when(response.getWriter()).thenReturn(new PrintWriter(output));

    welcomeFileHandler.handle("/", mock(HttpServletRequest.class), response, 1);
    String responseBody = new String(output.toByteArray());
    assertThat(responseBody, is("redirecting.."));

    verify(response).setHeader("Location", "/go/home");
    verify(response).setStatus(HttpStatus.ORDINAL_301_Moved_Permanently);
    verify(response).setHeader(HttpHeaders.CONTENT_TYPE, "text/html");
    verify(response).getWriter();
    verifyNoMoreInteractions(response);
  }