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