Browse Source

Polish "Migrate legacy endpoint that have a dash in their id"

See gh-21615
pull/23053/head
Stephane Nicoll 5 years ago
parent
commit
dd9c9fd171
  1. 24
      spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EndpointIdTests.java
  2. 4
      spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleLegacyEndpointWithDot.java

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

@ -101,22 +101,30 @@ class EndpointIdTests { @@ -101,22 +101,30 @@ class EndpointIdTests {
@Test
void ofWhenMigratingLegacyNameRemovesDots(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");
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

4
spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleLegacyEndpoint.java → spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-actuator/src/main/java/smoketest/actuator/SampleLegacyEndpointWithDot.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ import org.springframework.stereotype.Component; @@ -25,7 +25,7 @@ import org.springframework.stereotype.Component;
@Component
@Endpoint(id = "lega.cy")
public class SampleLegacyEndpoint {
public class SampleLegacyEndpointWithDot {
@ReadOperation
public Map<String, String> example() {
Loading…
Cancel
Save