|
1 | 1 | /* |
2 | | - * Copyright 2012-2021 the original author or authors. |
| 2 | + * Copyright 2012-2022 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.health; |
18 | 18 |
|
19 | 19 | import java.util.Collections; |
| 20 | +import java.util.Map; |
20 | 21 |
|
21 | 22 | import org.junit.jupiter.api.Test; |
22 | 23 | import reactor.core.publisher.Flux; |
|
45 | 46 | import org.springframework.boot.actuate.health.ReactiveHealthIndicator; |
46 | 47 | import org.springframework.boot.actuate.health.Status; |
47 | 48 | import org.springframework.boot.actuate.health.StatusAggregator; |
| 49 | +import org.springframework.boot.actuate.health.SystemHealth; |
48 | 50 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
49 | 51 | import org.springframework.boot.test.context.FilteredClassLoader; |
| 52 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
50 | 53 | import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; |
51 | 54 | import org.springframework.boot.test.context.runner.WebApplicationContextRunner; |
52 | 55 | import org.springframework.context.annotation.Bean; |
@@ -264,6 +267,32 @@ void runWhenHasHealthEndpointGroupsPostProcessorPerformsProcessing() { |
264 | 267 | }); |
265 | 268 | } |
266 | 269 |
|
| 270 | + @Test |
| 271 | + void runWithIndicatorsInParentContextFindsIndicators() { |
| 272 | + new ApplicationContextRunner().withUserConfiguration(HealthIndicatorsConfiguration.class) |
| 273 | + .run((parent) -> new WebApplicationContextRunner().withConfiguration(AutoConfigurations |
| 274 | + .of(HealthContributorAutoConfiguration.class, HealthEndpointAutoConfiguration.class)) |
| 275 | + .withParent(parent).run((context) -> { |
| 276 | + HealthComponent health = context.getBean(HealthEndpoint.class).health(); |
| 277 | + Map<String, HealthComponent> components = ((SystemHealth) health).getComponents(); |
| 278 | + assertThat(components).containsKeys("additional", "ping", "simple"); |
| 279 | + })); |
| 280 | + } |
| 281 | + |
| 282 | + @Test |
| 283 | + void runWithReactiveContextAndIndicatorsInParentContextFindsIndicators() { |
| 284 | + new ApplicationContextRunner().withUserConfiguration(HealthIndicatorsConfiguration.class) |
| 285 | + .run((parent) -> new ReactiveWebApplicationContextRunner() |
| 286 | + .withConfiguration(AutoConfigurations.of(HealthContributorAutoConfiguration.class, |
| 287 | + HealthEndpointAutoConfiguration.class, WebEndpointAutoConfiguration.class, |
| 288 | + EndpointAutoConfiguration.class)) |
| 289 | + .withParent(parent).run((context) -> { |
| 290 | + HealthComponent health = context.getBean(HealthEndpoint.class).health(); |
| 291 | + Map<String, HealthComponent> components = ((SystemHealth) health).getComponents(); |
| 292 | + assertThat(components).containsKeys("additional", "ping", "simple"); |
| 293 | + })); |
| 294 | + } |
| 295 | + |
267 | 296 | @Configuration(proxyBeanMethods = false) |
268 | 297 | static class HealthIndicatorsConfiguration { |
269 | 298 |
|
|
0 commit comments