Skip to content

Commit dd9c9fd

Browse files
committed
Polish "Migrate legacy endpoint that have a dash in their id"
See gh-21615
1 parent 0f9f10f commit dd9c9fd

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EndpointIdTests.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,30 @@ void ofWhenContainsDeprecatedCharsLogsWarning(CapturedOutput output) {
101101

102102
@Test
103103
void ofWhenMigratingLegacyNameRemovesDots(CapturedOutput output) {
104-
EndpointId.resetLoggedWarnings();
105-
MockEnvironment environment = new MockEnvironment();
106-
environment.setProperty("management.endpoints.migrate-legacy-ids", "true");
107-
EndpointId endpointId = EndpointId.of(environment, "foo.bar");
108-
assertThat(endpointId.toString()).isEqualTo("foobar");
104+
EndpointId endpointId = migrateLegacyName("one.two.three");
105+
assertThat(endpointId.toString()).isEqualTo("onetwothree");
109106
assertThat(output).doesNotContain("contains invalid characters");
110107
}
111108

112109
@Test
113110
void ofWhenMigratingLegacyNameRemovesHyphens(CapturedOutput output) {
111+
EndpointId endpointId = migrateLegacyName("one-two-three");
112+
assertThat(endpointId.toString()).isEqualTo("onetwothree");
113+
assertThat(output).doesNotContain("contains invalid characters");
114+
}
115+
116+
@Test
117+
void ofWhenMigratingLegacyNameRemovesMixOfDashAndDot(CapturedOutput output) {
118+
EndpointId endpointId = migrateLegacyName("one.two-three");
119+
assertThat(endpointId.toString()).isEqualTo("onetwothree");
120+
assertThat(output).doesNotContain("contains invalid characters");
121+
}
122+
123+
private EndpointId migrateLegacyName(String name) {
114124
EndpointId.resetLoggedWarnings();
115125
MockEnvironment environment = new MockEnvironment();
116126
environment.setProperty("management.endpoints.migrate-legacy-ids", "true");
117-
EndpointId endpointId = EndpointId.of(environment, "foo-bar");
118-
assertThat(endpointId.toString()).isEqualTo("foobar");
119-
assertThat(output).doesNotContain("contains invalid characters");
127+
return EndpointId.of(environment, name);
120128
}
121129

122130
@Test
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525

2626
@Component
2727
@Endpoint(id = "lega.cy")
28-
public class SampleLegacyEndpoint {
28+
public class SampleLegacyEndpointWithDot {
2929

3030
@ReadOperation
3131
public Map<String, String> example() {

0 commit comments

Comments
 (0)