|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.availability;
|
18 | 18 |
|
19 |
| -import java.util.Arrays; |
20 | 19 | import java.util.Collections;
|
21 |
| -import java.util.LinkedHashSet; |
22 | 20 |
|
23 | 21 | import org.junit.jupiter.api.BeforeEach;
|
24 | 22 | import org.junit.jupiter.api.Test;
|
25 | 23 |
|
| 24 | +import org.springframework.boot.actuate.health.AdditionalHealthEndpointPath; |
26 | 25 | import org.springframework.boot.actuate.health.HealthEndpointGroup;
|
27 | 26 | import org.springframework.boot.actuate.health.HealthEndpointGroups;
|
| 27 | +import org.springframework.boot.actuate.health.HttpCodeStatusMapper; |
28 | 28 |
|
29 | 29 | import static org.assertj.core.api.Assertions.assertThat;
|
30 | 30 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
|
35 | 35 | * Tests for {@link AvailabilityProbesHealthEndpointGroups}.
|
36 | 36 | *
|
37 | 37 | * @author Phillip Webb
|
| 38 | + * @author Madhura Bhave |
38 | 39 | */
|
39 | 40 | class AvailabilityProbesHealthEndpointGroupsTests {
|
40 | 41 |
|
@@ -69,10 +70,32 @@ void getNamesIncludesAvailabilityProbeGroups() {
|
69 | 70 | }
|
70 | 71 |
|
71 | 72 | @Test
|
72 |
| - void getWhenProbeInDelegateReturnsGroupFromDelegate() { |
73 |
| - given(this.delegate.get("liveness")).willReturn(this.group); |
| 73 | + void getWhenProbeInDelegateReturnsOriginalGroup() { |
| 74 | + HealthEndpointGroup group = mock(HealthEndpointGroup.class); |
| 75 | + HttpCodeStatusMapper mapper = mock(HttpCodeStatusMapper.class); |
| 76 | + given(group.getHttpCodeStatusMapper()).willReturn(mapper); |
| 77 | + given(this.delegate.get("liveness")).willReturn(group); |
74 | 78 | HealthEndpointGroups availabilityProbes = new AvailabilityProbesHealthEndpointGroups(this.delegate, false);
|
75 |
| - assertThat(availabilityProbes.get("liveness")).isEqualTo(this.group); |
| 79 | + assertThat(availabilityProbes.get("liveness")).isEqualTo(group); |
| 80 | + assertThat(group.getHttpCodeStatusMapper()).isEqualTo(mapper); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + void getWhenProbeInDelegateAndExistingAdditionalPathReturnsOriginalGroup() { |
| 85 | + HealthEndpointGroup group = mock(HealthEndpointGroup.class); |
| 86 | + given(group.getAdditionalPath()).willReturn(AdditionalHealthEndpointPath.from("server:test")); |
| 87 | + given(this.delegate.get("liveness")).willReturn(group); |
| 88 | + HealthEndpointGroups availabilityProbes = new AvailabilityProbesHealthEndpointGroups(this.delegate, true); |
| 89 | + HealthEndpointGroup liveness = availabilityProbes.get("liveness"); |
| 90 | + assertThat(liveness).isEqualTo(group); |
| 91 | + assertThat(liveness.getAdditionalPath().getValue()).isEqualTo("test"); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + void getWhenProbeInDelegateAndAdditionalPathReturnsGroupWithAdditionalPath() { |
| 96 | + given(this.delegate.get("liveness")).willReturn(this.group); |
| 97 | + HealthEndpointGroups availabilityProbes = new AvailabilityProbesHealthEndpointGroups(this.delegate, true); |
| 98 | + assertThat(availabilityProbes.get("liveness").getAdditionalPath().getValue()).isEqualTo("/livez"); |
76 | 99 | }
|
77 | 100 |
|
78 | 101 | @Test
|
@@ -103,22 +126,4 @@ void getReadinessProbeHasOnlyReadinessStateAsMember() {
|
103 | 126 | assertThat(probeGroup.isMember("readinessState")).isTrue();
|
104 | 127 | }
|
105 | 128 |
|
106 |
| - @Test |
107 |
| - void containsAllWhenContainsAllReturnTrue() { |
108 |
| - given(this.delegate.getNames()).willReturn(new LinkedHashSet<>(Arrays.asList("test", "liveness", "readiness"))); |
109 |
| - assertThat(AvailabilityProbesHealthEndpointGroups.containsAllProbeGroups(this.delegate)).isTrue(); |
110 |
| - } |
111 |
| - |
112 |
| - @Test |
113 |
| - void containsAllWhenContainsOneReturnFalse() { |
114 |
| - given(this.delegate.getNames()).willReturn(new LinkedHashSet<>(Arrays.asList("test", "liveness"))); |
115 |
| - assertThat(AvailabilityProbesHealthEndpointGroups.containsAllProbeGroups(this.delegate)).isFalse(); |
116 |
| - } |
117 |
| - |
118 |
| - @Test |
119 |
| - void containsAllWhenContainsNoneReturnFalse() { |
120 |
| - given(this.delegate.getNames()).willReturn(new LinkedHashSet<>(Arrays.asList("test", "spring"))); |
121 |
| - assertThat(AvailabilityProbesHealthEndpointGroups.containsAllProbeGroups(this.delegate)).isFalse(); |
122 |
| - } |
123 |
| - |
124 | 129 | }
|
0 commit comments