Skip to content

Commit f2a52a8

Browse files
committed
Merge branch '2.3.x'
Closes gh-22850
2 parents 342a98a + 980ddcf commit f2a52a8

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/EndpointId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public static EndpointId of(Environment environment, String value) {
131131

132132
private static String migrateLegacyId(Environment environment, String value) {
133133
if (environment.getProperty(MIGRATE_LEGACY_NAMES_PROPERTY, Boolean.class, false)) {
134-
return value.replace(".", "");
134+
return value.replaceAll("[-.]+", "");
135135
}
136136
return value;
137137
}

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

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

102102
@Test
103103
void ofWhenMigratingLegacyNameRemovesDots(CapturedOutput output) {
104+
EndpointId endpointId = migrateLegacyName("one.two.three");
105+
assertThat(endpointId.toString()).isEqualTo("onetwothree");
106+
assertThat(output).doesNotContain("contains invalid characters");
107+
}
108+
109+
@Test
110+
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) {
104124
EndpointId.resetLoggedWarnings();
105125
MockEnvironment environment = new MockEnvironment();
106126
environment.setProperty("management.endpoints.migrate-legacy-ids", "true");
107-
EndpointId endpointId = EndpointId.of(environment, "foo.bar");
108-
assertThat(endpointId.toString()).isEqualTo("foobar");
109-
assertThat(output).doesNotContain("contains invalid characters");
127+
return EndpointId.of(environment, name);
110128
}
111129

112130
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.actuator;
18+
19+
import java.util.Collections;
20+
import java.util.Map;
21+
22+
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
23+
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
24+
import org.springframework.stereotype.Component;
25+
26+
@Component
27+
@Endpoint(id = "lega.cy")
28+
public class SampleLegacyEndpointWithDot {
29+
30+
@ReadOperation
31+
public Map<String, String> example() {
32+
return Collections.singletonMap("legacy", "legacy");
33+
}
34+
35+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.springframework.stereotype.Component;
2525

2626
@Component
27-
@Endpoint(id = "lega.cy")
28-
public class SampleLegacyEndpoint {
27+
@Endpoint(id = "another-legacy")
28+
public class SampleLegacyEndpointWithHyphen {
2929

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

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/test/java/smoketest/actuator/SampleActuatorApplicationTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,21 @@ void testConfigProps() {
173173
}
174174

175175
@Test
176-
void testLegacy() {
176+
void testLegacyDot() {
177177
ResponseEntity<Map<String, Object>> entity = asMapEntity(
178178
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/legacy", Map.class));
179179
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
180180
assertThat(entity.getBody()).contains(entry("legacy", "legacy"));
181181
}
182182

183+
@Test
184+
void testLegacyHyphen() {
185+
ResponseEntity<Map<String, Object>> entity = asMapEntity(
186+
this.restTemplate.withBasicAuth("user", "password").getForEntity("/actuator/anotherlegacy", Map.class));
187+
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
188+
assertThat(entity.getBody()).contains(entry("legacy", "legacy"));
189+
}
190+
183191
@SuppressWarnings({ "unchecked", "rawtypes" })
184192
static <K, V> ResponseEntity<Map<K, V>> asMapEntity(ResponseEntity<Map> entity) {
185193
return (ResponseEntity) entity;

0 commit comments

Comments
 (0)