예제 #1
0
  @Test
  public void shouldSetInitParams() throws Exception {
    jetty6Server.configure();
    jetty6Server.setInitParameter("name", "value");

    assertThat(getWebAppContext(jetty6Server).getInitParameter("name"), CoreMatchers.is("value"));
  }
예제 #2
0
 @Test
 public void shouldAddExtraJarsIntoClassPath() throws Exception {
   jetty6Server.configure();
   jetty6Server.addExtraJarsToClasspath(
       "test-addons/some-addon-dir/addon-1.JAR,test-addons/some-addon-dir/addon-2.jar");
   assertThat(
       getWebAppContext(jetty6Server).getExtraClasspath(),
       is("test-addons/some-addon-dir/addon-1.JAR,test-addons/some-addon-dir/addon-2.jar"));
 }
예제 #3
0
  @Test
  public void shouldAddMBeanContainerAsEventListener() throws Exception {
    ArgumentCaptor<MBeanContainer> captor = ArgumentCaptor.forClass(MBeanContainer.class);
    jetty6Server.configure();

    verify(container).addEventListener(captor.capture());
    MBeanContainer mBeanContainer = captor.getValue();
    assertThat(mBeanContainer.getMBeanServer(), is(not(nullValue())));
  }
예제 #4
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);
  }
예제 #5
0
  @Test
  public void shouldAddResourceHandlerForAssets() 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(2);
    assertThat(handler instanceof Jetty6AssetsContextHandler, is(true));
    Jetty6AssetsContextHandler assetsContextHandler = (Jetty6AssetsContextHandler) handler;
    assertThat(assetsContextHandler.getContextPath(), is("context/assets"));
  }
예제 #6
0
  @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);
  }
예제 #7
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"));
  }
예제 #8
0
  @Test
  public void shouldAddHttpSocketConnector() throws Exception {
    ArgumentCaptor<Connector> captor = ArgumentCaptor.forClass(Connector.class);
    jetty6Server.configure();

    verify(server, times(2)).addConnector(captor.capture());

    List<Connector> connectors = captor.getAllValues();
    Connector plainConnector = connectors.get(0);

    assertThat(plainConnector instanceof SelectChannelConnector, is(true));
    SelectChannelConnector connector = (SelectChannelConnector) plainConnector;
    assertThat(connector.getPort(), is(1234));
    assertThat(connector.getHost(), is("localhost"));
  }
예제 #9
0
  @Test
  public void shouldAddSSLSocketConnector() throws Exception {
    ArgumentCaptor<Connector> captor = ArgumentCaptor.forClass(Connector.class);
    jetty6Server.configure();

    verify(server, times(2)).addConnector(captor.capture());
    List<Connector> connectors = captor.getAllValues();
    Connector sslConnector = connectors.get(1);

    assertThat(sslConnector instanceof SslSelectChannelConnector, is(true));
    SslSelectChannelConnector connector = (SslSelectChannelConnector) sslConnector;

    assertThat(connector.getPort(), is(4567));
    assertThat(connector.getHost(), is("localhost"));
    assertThat(connector.getMaxIdleTime(), is(30000));
    assertThat(connector.getWantClientAuth(), is(true));
    assertThat(connector.getExcludeCipherSuites(), is(new String[] {"CS1", "CS2"}));
  }
예제 #10
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);
  }
예제 #11
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();
  }
예제 #12
0
  @Test
  public void shouldAddWebAppContextHandler() 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(3);
    assertThat(handler instanceof WebAppContext, is(true));
    WebAppContext webAppContext = (WebAppContext) handler;
    List<String> configClasses = ArrayUtil.asList(webAppContext.getConfigurationClasses());
    assertThat(configClasses.contains(WebInfConfiguration.class.getCanonicalName()), is(true));
    assertThat(configClasses.contains(WebXmlConfiguration.class.getCanonicalName()), is(true));
    assertThat(configClasses.contains(JettyWebXmlConfiguration.class.getCanonicalName()), is(true));
    assertThat(webAppContext.getContextPath(), is("context"));
    assertThat(webAppContext.getWar(), is("cruise.war"));
    assertThat(webAppContext.isParentLoaderPriority(), is(false));
    assertThat(
        webAppContext.getDefaultsDescriptor(), is("org/mortbay/jetty/webapp/webdefault.xml"));
  }
예제 #13
0
 @Test
 public void shouldSetStopAtShutdown() throws Exception {
   jetty6Server.configure();
   verify(server).setStopAtShutdown(true);
 }