Migrate legacy endpoint that have a dash in their id

See gh-21615
This commit is contained in:
Gabriele Bianchet-David
2020-05-28 15:01:31 -04:00
committed by Stephane Nicoll
parent 8962d6ca21
commit 0f9f10f97e
4 changed files with 55 additions and 2 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

@@ -109,6 +109,16 @@ class EndpointIdTests {
assertThat(output).doesNotContain("contains invalid characters");
}
@Test
void ofWhenMigratingLegacyNameRemovesHyphens(CapturedOutput output) {
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");
}
@Test
void equalsAndHashCode() {
EndpointId one = EndpointId.of("foobar1");