use of io.dropwizard.jetty.setup.ServletEnvironment in project dropwizard by dropwizard.
the class DefaultHealthFactoryTest method configure.
@Test
void configure() throws Exception {
final DefaultHealthFactory healthFactory = configFactory.build(new ResourceConfigurationSourceProvider(), "/yml/health.yml");
LifecycleEnvironment lifecycleEnvironment = new LifecycleEnvironment(new MetricRegistry());
ServletRegistration.Dynamic mockServletRegistration = mock(ServletRegistration.Dynamic.class);
ServletEnvironment servletEnvironment = mock(ServletEnvironment.class);
ArgumentCaptor<Servlet> servletCaptor = ArgumentCaptor.forClass(Servlet.class);
when(servletEnvironment.addServlet(eq("health-check-test-servlet"), any(Servlet.class))).thenReturn(mockServletRegistration);
HealthEnvironment healthEnvironment = new HealthEnvironment(mock(HealthCheckRegistry.class));
healthFactory.configure(lifecycleEnvironment, servletEnvironment, mock(JerseyEnvironment.class), healthEnvironment, new ObjectMapper(), "test");
assertThat(lifecycleEnvironment.getManagedObjects()).hasSize(2).allSatisfy(obj -> assertThat(obj).isInstanceOf(JettyManaged.class)).map(managed -> ((JettyManaged) managed).getManaged()).satisfies(obj -> assertThat(obj).element(0).isInstanceOfSatisfying(ExecutorServiceManager.class, executorServiceManager -> assertThat(executorServiceManager.getPoolName()).isEqualTo("health-check-test-scheduled-executor"))).satisfies(obj -> assertThat(obj).element(1).isInstanceOf(HealthCheckConfigValidator.class));
assertThat(healthFactory.getHealthResponderFactory()).isInstanceOf(ServletHealthResponderFactory.class);
verify(servletEnvironment).addServlet(eq("health-check-test-servlet"), servletCaptor.capture());
assertThat(servletCaptor.getValue()).isInstanceOf(ServletHealthResponder.class);
verify(mockServletRegistration).addMapping("/health-check");
assertThat(healthEnvironment.healthStateAggregator()).isNotNull();
}
Aggregations