Merge branch '2.2.x' into 2.3.x

Closes gh-22849
This commit is contained in:
Stephane Nicoll
2020-08-10 16:05:13 +02:00
5 changed files with 68 additions and 7 deletions

View File

@@ -131,7 +131,7 @@ public final class EndpointId {
private static String migrateLegacyId(Environment environment, String value) {
if (environment.getProperty(MIGRATE_LEGACY_NAMES_PROPERTY, Boolean.class, false)) {
return value.replace(".", "");
return value.replaceAll("[-.]+", "");
}
return value;
}

View File

@@ -101,12 +101,30 @@ class EndpointIdTests {
@Test
void ofWhenMigratingLegacyNameRemovesDots(CapturedOutput output) {
EndpointId endpointId = migrateLegacyName("one.two.three");
assertThat(endpointId.toString()).isEqualTo("onetwothree");
assertThat(output).doesNotContain("contains invalid characters");
}
@Test
void ofWhenMigratingLegacyNameRemovesHyphens(CapturedOutput output) {
EndpointId endpointId = migrateLegacyName("one-two-three");
assertThat(endpointId.toString()).isEqualTo("onetwothree");
assertThat(output).doesNotContain("contains invalid characters");
}
@Test
void ofWhenMigratingLegacyNameRemovesMixOfDashAndDot(CapturedOutput output) {
EndpointId endpointId = migrateLegacyName("one.two-three");
assertThat(endpointId.toString()).isEqualTo("onetwothree");
assertThat(output).doesNotContain("contains invalid characters");
}
private EndpointId migrateLegacyName(String name) {
EndpointId.resetLoggedWarnings();
MockEnvironment environment = new MockEnvironment();
environment.setProperty("management.endpoints.migrate-legacy-ids", "true");
EndpointId endpointId = EndpointId.of(environment, "foo.bar");
assertThat(endpointId.toString()).isEqualTo("foobar");
assertThat(output).doesNotContain("contains invalid characters");
return EndpointId.of(environment, name);
}
@Test