Use lowercase default endpoint paths

Update `MappingWebEndpointPathMapper` to use the lowercase version of
the endpoint ID when no explicit path mapping has been set. An endpoint
with the ID 'myEndpoint' will now be mapped to the path 'myendpoint'.

See gh-14773
This commit is contained in:
Phillip Webb 2018-10-13 23:10:37 -07:00
parent df5dfbf4be
commit a00ee15e16
2 changed files with 20 additions and 2 deletions

View File

@ -16,6 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.endpoint.web;
import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.actuate.endpoint.EndpointId;
@ -29,10 +30,12 @@ import org.springframework.boot.actuate.endpoint.web.PathMapper;
*/
class MappingWebEndpointPathMapper implements PathMapper {
private final Map<String, String> pathMapping;
private final Map<EndpointId, String> pathMapping;
MappingWebEndpointPathMapper(Map<String, String> pathMapping) {
this.pathMapping = pathMapping;
this.pathMapping = new HashMap<>();
pathMapping.forEach((id, path) -> this.pathMapping
.put(EndpointId.fromPropertyValue(id), path));
}
@Override

View File

@ -45,4 +45,19 @@ public class MappingWebEndpointPathMapperTests {
assertThat(mapper.getRootPath(EndpointId.of("test"))).isEqualTo("custom");
}
@Test
public void mixedCaseDefaultConfiguration() {
MappingWebEndpointPathMapper mapper = new MappingWebEndpointPathMapper(
Collections.emptyMap());
assertThat(mapper.getRootPath(EndpointId.of("testEndpoint")))
.isEqualTo("testendpoint");
}
@Test
public void mixedCaseUserConfiguration() {
MappingWebEndpointPathMapper mapper = new MappingWebEndpointPathMapper(
Collections.singletonMap("test-endpoint", "custom"));
assertThat(mapper.getRootPath(EndpointId.of("testEndpoint"))).isEqualTo("custom");
}
}