|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2025 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.availability;
|
18 | 18 |
|
19 | 19 | import java.util.LinkedHashSet;
|
| 20 | +import java.util.List; |
20 | 21 | import java.util.Set;
|
21 | 22 |
|
22 | 23 | import org.junit.jupiter.api.Test;
|
| 24 | +import org.mockito.Mockito; |
23 | 25 |
|
| 26 | +import org.springframework.boot.actuate.endpoint.EndpointId; |
| 27 | +import org.springframework.boot.actuate.endpoint.web.AdditionalPathsMapper; |
| 28 | +import org.springframework.boot.actuate.endpoint.web.WebServerNamespace; |
24 | 29 | import org.springframework.boot.actuate.health.HealthEndpointGroup;
|
25 | 30 | import org.springframework.boot.actuate.health.HealthEndpointGroups;
|
26 | 31 | import org.springframework.mock.env.MockEnvironment;
|
@@ -103,6 +108,39 @@ void postProcessHealthEndpointGroupsWhenGroupsAlreadyContainedAndAdditionalPathP
|
103 | 108 | assertThat(readiness.getAdditionalPath()).hasToString("server:/readyz");
|
104 | 109 | }
|
105 | 110 |
|
| 111 | + @Test |
| 112 | + void delegatesAdditionalPathMappingToOriginalBean() { |
| 113 | + HealthEndpointGroups groups = mock(HealthEndpointGroups.class, |
| 114 | + Mockito.withSettings().extraInterfaces(AdditionalPathsMapper.class)); |
| 115 | + given(((AdditionalPathsMapper) groups).getAdditionalPaths(EndpointId.of("health"), WebServerNamespace.SERVER)) |
| 116 | + .willReturn(List.of("/one", "/two", "/three")); |
| 117 | + MockEnvironment environment = new MockEnvironment(); |
| 118 | + AvailabilityProbesHealthEndpointGroupsPostProcessor postProcessor = new AvailabilityProbesHealthEndpointGroupsPostProcessor( |
| 119 | + environment); |
| 120 | + HealthEndpointGroups postProcessed = postProcessor.postProcessHealthEndpointGroups(groups); |
| 121 | + assertThat(postProcessed).isInstanceOf(AdditionalPathsMapper.class); |
| 122 | + AdditionalPathsMapper additionalPathsMapper = (AdditionalPathsMapper) postProcessed; |
| 123 | + assertThat(additionalPathsMapper.getAdditionalPaths(EndpointId.of("health"), WebServerNamespace.SERVER)) |
| 124 | + .containsExactly("/one", "/two", "/three"); |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + void whenAddAdditionalPathsIsTrueThenIncludesOwnAdditionalPathsInGetAdditionalPathsResult() { |
| 129 | + HealthEndpointGroups groups = mock(HealthEndpointGroups.class, |
| 130 | + Mockito.withSettings().extraInterfaces(AdditionalPathsMapper.class)); |
| 131 | + given(((AdditionalPathsMapper) groups).getAdditionalPaths(EndpointId.of("health"), WebServerNamespace.SERVER)) |
| 132 | + .willReturn(List.of("/one", "/two", "/three")); |
| 133 | + MockEnvironment environment = new MockEnvironment(); |
| 134 | + environment.setProperty("management.endpoint.health.probes.add-additional-paths", "true"); |
| 135 | + AvailabilityProbesHealthEndpointGroupsPostProcessor postProcessor = new AvailabilityProbesHealthEndpointGroupsPostProcessor( |
| 136 | + environment); |
| 137 | + HealthEndpointGroups postProcessed = postProcessor.postProcessHealthEndpointGroups(groups); |
| 138 | + assertThat(postProcessed).isInstanceOf(AdditionalPathsMapper.class); |
| 139 | + AdditionalPathsMapper additionalPathsMapper = (AdditionalPathsMapper) postProcessed; |
| 140 | + assertThat(additionalPathsMapper.getAdditionalPaths(EndpointId.of("health"), WebServerNamespace.SERVER)) |
| 141 | + .containsExactly("/one", "/two", "/three", "/livez", "/readyz"); |
| 142 | + } |
| 143 | + |
106 | 144 | private HealthEndpointGroups getPostProcessed(String value) {
|
107 | 145 | MockEnvironment environment = new MockEnvironment();
|
108 | 146 | environment.setProperty("management.endpoint.health.probes.add-additional-paths", value);
|
|
0 commit comments