Search in sources :

Example 1 with ServletEnvironment

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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ServletHealthResponderFactory(io.dropwizard.health.response.ServletHealthResponderFactory) ServletHealthResponder(io.dropwizard.health.response.ServletHealthResponder) ServletRegistration(javax.servlet.ServletRegistration) Validators(io.dropwizard.jersey.validation.Validators) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JettyManaged(io.dropwizard.lifecycle.JettyManaged) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ServletEnvironment(io.dropwizard.jetty.setup.ServletEnvironment) Jackson(io.dropwizard.jackson.Jackson) YamlConfigurationFactory(io.dropwizard.configuration.YamlConfigurationFactory) JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) LifecycleEnvironment(io.dropwizard.lifecycle.setup.LifecycleEnvironment) MetricRegistry(com.codahale.metrics.MetricRegistry) ExecutorServiceManager(io.dropwizard.lifecycle.ExecutorServiceManager) Servlet(javax.servlet.Servlet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validator(javax.validation.Validator) ResourceConfigurationSourceProvider(io.dropwizard.configuration.ResourceConfigurationSourceProvider) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Mockito.mock(org.mockito.Mockito.mock) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) ServletRegistration(javax.servlet.ServletRegistration) JerseyEnvironment(io.dropwizard.jersey.setup.JerseyEnvironment) LifecycleEnvironment(io.dropwizard.lifecycle.setup.LifecycleEnvironment) ResourceConfigurationSourceProvider(io.dropwizard.configuration.ResourceConfigurationSourceProvider) Servlet(javax.servlet.Servlet) ServletEnvironment(io.dropwizard.jetty.setup.ServletEnvironment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

MetricRegistry (com.codahale.metrics.MetricRegistry)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ResourceConfigurationSourceProvider (io.dropwizard.configuration.ResourceConfigurationSourceProvider)1 YamlConfigurationFactory (io.dropwizard.configuration.YamlConfigurationFactory)1 ServletHealthResponder (io.dropwizard.health.response.ServletHealthResponder)1 ServletHealthResponderFactory (io.dropwizard.health.response.ServletHealthResponderFactory)1 Jackson (io.dropwizard.jackson.Jackson)1 JerseyEnvironment (io.dropwizard.jersey.setup.JerseyEnvironment)1 Validators (io.dropwizard.jersey.validation.Validators)1 ServletEnvironment (io.dropwizard.jetty.setup.ServletEnvironment)1 ExecutorServiceManager (io.dropwizard.lifecycle.ExecutorServiceManager)1 JettyManaged (io.dropwizard.lifecycle.JettyManaged)1 LifecycleEnvironment (io.dropwizard.lifecycle.setup.LifecycleEnvironment)1 Collections.singletonList (java.util.Collections.singletonList)1 Collectors (java.util.stream.Collectors)1 Servlet (javax.servlet.Servlet)1 ServletRegistration (javax.servlet.ServletRegistration)1 Validator (javax.validation.Validator)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1