Maintain same structure in /health output

JSON output of /health now has the same structure for 1 or more HealthIndicators. This makes it easier to consume the response from scripts or apps

fixes #1291
This commit is contained in:
Christian Dupuis 2014-07-31 16:13:23 +02:00
parent 6b083d7e0b
commit 063f67da5f
2 changed files with 8 additions and 13 deletions

View File

@ -46,10 +46,6 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
Assert.notNull(healthAggregator, "HealthAggregator must not be null"); Assert.notNull(healthAggregator, "HealthAggregator must not be null");
Assert.notNull(healthIndicators, "HealthIndicators must not be null"); Assert.notNull(healthIndicators, "HealthIndicators must not be null");
if (healthIndicators.size() == 1) {
this.healthIndicator = healthIndicators.values().iterator().next();
}
else {
CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator( CompositeHealthIndicator healthIndicator = new CompositeHealthIndicator(
healthAggregator); healthAggregator);
for (Map.Entry<String, HealthIndicator> h : healthIndicators.entrySet()) { for (Map.Entry<String, HealthIndicator> h : healthIndicators.entrySet()) {
@ -57,7 +53,6 @@ public class HealthEndpoint extends AbstractEndpoint<Health> {
} }
this.healthIndicator = healthIndicator; this.healthIndicator = healthIndicator;
} }
}
/** /**
* Invoke all {@link HealthIndicator} delegates and collect their health information. * Invoke all {@link HealthIndicator} delegates and collect their health information.

View File

@ -89,7 +89,7 @@ public class EndpointAutoConfigurationTests {
assertNotNull(bean); assertNotNull(bean);
Health result = bean.invoke(); Health result = bean.invoke();
assertNotNull(result); assertNotNull(result);
assertTrue("Wrong result: " + result, result.getDetails().containsKey("database")); assertTrue("Wrong result: " + result, result.getDetails().containsKey("db"));
} }
@Test @Test