use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.
the class Jetty9ServerTest method shouldAddResourceHandlerForAssets.
@Test
public void shouldAddResourceHandlerForAssets() throws Exception {
ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
jetty9Server.configure();
verify(server, times(1)).setHandler(captor.capture());
HandlerCollection handlerCollection = captor.getValue();
assertThat(handlerCollection.getHandlers().length, is(3));
Handler handler = handlerCollection.getHandlers()[1];
assertThat(handler instanceof AssetsContextHandler, is(true));
AssetsContextHandler assetsContextHandler = (AssetsContextHandler) handler;
assertThat(assetsContextHandler.getContextPath(), is("context/assets"));
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.
the class Jetty9ServerTest method shouldAddDefaultHeadersForRootContext.
@Test
public void shouldAddDefaultHeadersForRootContext() throws Exception {
ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
jetty9Server.configure();
verify(server, times(1)).setHandler(captor.capture());
HandlerCollection handlerCollection = captor.getValue();
Jetty9Server.GoServerWelcomeFileHandler handler = (Jetty9Server.GoServerWelcomeFileHandler) handlerCollection.getHandlers()[0];
Handler rootPathHandler = handler.getHandler();
HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(mock(PrintWriter.class));
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getPathInfo()).thenReturn("/");
rootPathHandler.handle("/", mock(Request.class), request, response);
verify(response).setHeader("X-XSS-Protection", "1; mode=block");
verify(response).setHeader("X-Content-Type-Options", "nosniff");
verify(response).setHeader("X-Frame-Options", "SAMEORIGIN");
verify(response).setHeader("X-UA-Compatible", "chrome=1");
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.
the class Jetty9ServerTest method shouldAddWelcomeRequestHandler.
@Test
public void shouldAddWelcomeRequestHandler() throws Exception {
ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
jetty9Server.configure();
verify(server, times(1)).setHandler(captor.capture());
HandlerCollection handlerCollection = captor.getValue();
assertThat(handlerCollection.getHandlers().length, is(3));
Handler handler = handlerCollection.getHandlers()[0];
assertThat(handler instanceof Jetty9Server.GoServerWelcomeFileHandler, is(true));
Jetty9Server.GoServerWelcomeFileHandler welcomeFileHandler = (Jetty9Server.GoServerWelcomeFileHandler) handler;
assertThat(welcomeFileHandler.getContextPath(), is("/"));
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.
the class Jetty9ServerTest method shouldAddWebAppContextHandler.
@Test
public void shouldAddWebAppContextHandler() throws Exception {
ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
jetty9Server.configure();
verify(server, times(1)).setHandler(captor.capture());
HandlerCollection handlerCollection = captor.getValue();
assertThat(handlerCollection.getHandlers().length, is(3));
Handler handler = handlerCollection.getHandlers()[2];
assertThat(handler, instanceOf(GzipHandler.class));
WebAppContext webAppContext = (WebAppContext) ((GzipHandler) handler).getHandler();
assertThat(webAppContext, instanceOf(WebAppContext.class));
List<String> configClasses = new ArrayList<>(Arrays.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(true));
assertThat(webAppContext.getDefaultsDescriptor(), is("jar:file:cruise.war!/WEB-INF/webdefault.xml"));
}
use of org.eclipse.jetty.server.handler.HandlerCollection in project gocd by gocd.
the class Jetty9ServerTest method shouldSetErrorHandlerForWebAppContext.
@Test
public void shouldSetErrorHandlerForWebAppContext() throws Exception {
ArgumentCaptor<HandlerCollection> captor = ArgumentCaptor.forClass(HandlerCollection.class);
jetty9Server.configure();
verify(server, times(1)).setHandler(captor.capture());
HandlerCollection handlerCollection = captor.getValue();
assertThat(handlerCollection.getHandlers().length, is(3));
Handler handler = handlerCollection.getHandlers()[2];
assertThat(handler, instanceOf(GzipHandler.class));
WebAppContext webAppContext = (WebAppContext) ((GzipHandler) handler).getHandler();
assertThat(webAppContext, instanceOf(WebAppContext.class));
assertThat(webAppContext.getErrorHandler() instanceof JettyCustomErrorPageHandler, is(true));
}
Aggregations