@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);
  }
Example #2
0
  @Test
  public void shouldAddWelcomeRequestHandler() 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(0);
    assertThat(handler instanceof Jetty6Server.GoServerWelcomeFileHandler, is(true));

    Jetty6Server.GoServerWelcomeFileHandler welcomeFileHandler =
        (Jetty6Server.GoServerWelcomeFileHandler) handler;
    assertThat(welcomeFileHandler.getContextPath(), is("/"));
  }
  @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);
  }