StartedHealthIndicator implements HealthIndicator { @Override public Health health() { final Optional<Status> optStatus = gatewayStatusSupplier.get(); if (optStatus.isEmpty()) { return Health.unknown().build(); } else { final var status = optStatus.get(); switch (status) { case INITIAL: case STARTING: return Health.down().build(); case RUNNING: return Health.up().build(); case SHUTDOWN: return Health.outOfService().build(); default: LOG.warn("Encountered unexpected status " + status); return Health.unknown().build(); } } } StartedHealthIndicator(final Supplier<Optional<Status>> gatewayStatusSupplier); @Override Health health(); static final Logger LOG; }
@Test public void shouldReportUnknownWhenGatewayStateIsEmpty() { final StartedHealthIndicator sutHealthIndicator = new StartedHealthIndicator(() -> Optional.empty()); final Health actual = sutHealthIndicator.health(); assertThat(actual.getStatus()).isSameAs(org.springframework.boot.actuate.health.Status.UNKNOWN); }
@Test public void shouldReportDownWhenGatewayStateIsInitial() { final StartedHealthIndicator sutHealthIndicator = new StartedHealthIndicator(() -> Optional.of(Status.INITIAL)); final Health actual = sutHealthIndicator.health(); assertThat(actual.getStatus()).isSameAs(org.springframework.boot.actuate.health.Status.DOWN); }
@Test public void shouldReportDownWhenGatewayStateIsStarting() { final StartedHealthIndicator sutHealthIndicator = new StartedHealthIndicator(() -> Optional.of(Status.STARTING)); final Health actual = sutHealthIndicator.health(); assertThat(actual.getStatus()).isSameAs(org.springframework.boot.actuate.health.Status.DOWN); }
@Test public void shouldReportUpWhenGatewayStateIsRunning() { final StartedHealthIndicator sutHealthIndicator = new StartedHealthIndicator(() -> Optional.of(Status.RUNNING)); final Health actual = sutHealthIndicator.health(); assertThat(actual.getStatus()).isSameAs(org.springframework.boot.actuate.health.Status.UP); }
@Test public void shouldReportOutOfServiceWhenGatewayStateIsShutdown() { final StartedHealthIndicator sutHealthIndicator = new StartedHealthIndicator(() -> Optional.of(Status.SHUTDOWN)); final Health actual = sutHealthIndicator.health(); assertThat(actual.getStatus()) .isSameAs(org.springframework.boot.actuate.health.Status.OUT_OF_SERVICE); }