|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2017 the original author or authors. |
|
|
|
|
* Copyright 2012-2018 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -17,17 +17,22 @@
@@ -17,17 +17,22 @@
|
|
|
|
|
package org.springframework.boot.actuate.health; |
|
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.junit.Rule; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static org.assertj.core.api.Assertions.entry; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Tests for {@link Health}. |
|
|
|
|
* |
|
|
|
|
* @author Phillip Webb |
|
|
|
|
* @author Michael Pratt |
|
|
|
|
* @author Stephane Nicoll |
|
|
|
|
*/ |
|
|
|
|
public class HealthTests { |
|
|
|
|
|
|
|
|
|
@ -53,7 +58,7 @@ public class HealthTests {
@@ -53,7 +58,7 @@ public class HealthTests {
|
|
|
|
|
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) |
|
|
|
|
.build(); |
|
|
|
|
assertThat(health.getStatus()).isEqualTo(Status.UP); |
|
|
|
|
assertThat(health.getDetails().get("a")).isEqualTo("b"); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "b")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -76,24 +81,53 @@ public class HealthTests {
@@ -76,24 +81,53 @@ public class HealthTests {
|
|
|
|
|
RuntimeException ex = new RuntimeException("bang"); |
|
|
|
|
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) |
|
|
|
|
.withException(ex).build(); |
|
|
|
|
assertThat(health.getDetails().get("a")).isEqualTo("b"); |
|
|
|
|
assertThat(health.getDetails().get("error")) |
|
|
|
|
.isEqualTo("java.lang.RuntimeException: bang"); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "b"), |
|
|
|
|
entry("error", "java.lang.RuntimeException: bang")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void withDetails() { |
|
|
|
|
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")) |
|
|
|
|
.withDetail("c", "d").build(); |
|
|
|
|
assertThat(health.getDetails().get("a")).isEqualTo("b"); |
|
|
|
|
assertThat(health.getDetails().get("c")).isEqualTo("d"); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "b"), entry("c", "d")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void withDetailsMap() { |
|
|
|
|
Map<String, Object> details = new LinkedHashMap<>(); |
|
|
|
|
details.put("a", "b"); |
|
|
|
|
details.put("c", "d"); |
|
|
|
|
Health health = Health.up().withDetails(details).build(); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "b"), entry("c", "d")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void withDetailsMapDuplicateKeys() { |
|
|
|
|
Map<String, Object> details = new LinkedHashMap<>(); |
|
|
|
|
details.put("c", "d"); |
|
|
|
|
details.put("a", "e"); |
|
|
|
|
Health health = Health.up().withDetail("a", "b").withDetails(details).build(); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "e"), entry("c", "d")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void withDetailsMultipleMaps() { |
|
|
|
|
Map<String, Object> details1 = new LinkedHashMap<>(); |
|
|
|
|
details1.put("a", "b"); |
|
|
|
|
details1.put("c", "d"); |
|
|
|
|
Map<String, Object> details2 = new LinkedHashMap<>(); |
|
|
|
|
details1.put("a", "e"); |
|
|
|
|
details1.put("1", "2"); |
|
|
|
|
Health health = Health.up().withDetails(details1).withDetails(details2).build(); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "e"), entry("c", "d"), |
|
|
|
|
entry("1", "2")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void unknownWithDetails() { |
|
|
|
|
Health health = new Health.Builder().unknown().withDetail("a", "b").build(); |
|
|
|
|
assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN); |
|
|
|
|
assertThat(health.getDetails().get("a")).isEqualTo("b"); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "b")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -107,7 +141,7 @@ public class HealthTests {
@@ -107,7 +141,7 @@ public class HealthTests {
|
|
|
|
|
public void upWithDetails() { |
|
|
|
|
Health health = new Health.Builder().up().withDetail("a", "b").build(); |
|
|
|
|
assertThat(health.getStatus()).isEqualTo(Status.UP); |
|
|
|
|
assertThat(health.getDetails().get("a")).isEqualTo("b"); |
|
|
|
|
assertThat(health.getDetails()).containsOnly(entry("a", "b")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -122,8 +156,8 @@ public class HealthTests {
@@ -122,8 +156,8 @@ public class HealthTests {
|
|
|
|
|
RuntimeException ex = new RuntimeException("bang"); |
|
|
|
|
Health health = Health.down(ex).build(); |
|
|
|
|
assertThat(health.getStatus()).isEqualTo(Status.DOWN); |
|
|
|
|
assertThat(health.getDetails().get("error")) |
|
|
|
|
.isEqualTo("java.lang.RuntimeException: bang"); |
|
|
|
|
assertThat(health.getDetails()) |
|
|
|
|
.containsOnly(entry("error", "java.lang.RuntimeException: bang")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|