Browse Source

Add toString method for EndpointRequestMatcher

See gh-33690
pull/33774/head
rishal 3 years ago committed by Moritz Halbritter
parent
commit
c84399e705
  1. 18
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java
  2. 28
      spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java

18
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequest.java

@ -273,6 +273,24 @@ public final class EndpointRequest { @@ -273,6 +273,24 @@ public final class EndpointRequest {
.collect(Collectors.toList());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (this.includes.isEmpty()) {
sb.append("EndpointRequest [includes='[").append("*").append("]'");
}
else {
sb.append("EndpointRequest [includes='")
.append(this.includes.stream().map(this::getEndpointId).collect(Collectors.toList()))
.append("'");
}
sb.append(", Excludes='")
.append(this.excludes.stream().map(this::getEndpointId).collect(Collectors.toList())).append("'");
sb.append(", IncludeLinks='").append(this.includeLinks).append("'");
sb.append("]");
return sb.toString();
}
}
/**

28
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/EndpointRequestTests.java

@ -216,6 +216,34 @@ class EndpointRequestTests { @@ -216,6 +216,34 @@ class EndpointRequestTests {
assertMatcher(matcher, (PathMappedEndpoints) null).doesNotMatch("/actuator/bar");
}
@Test
void toStringIncludedEndpoints() {
RequestMatcher matcher = EndpointRequest.to("foo", "bar");
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[foo, bar]', Excludes='[]', IncludeLinks='false']");
}
@Test
void toStringEmptyIncludedEndpoints() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint();
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[*]', Excludes='[]', IncludeLinks='true']");
}
@Test
void toStringIncludedEndpointsClasses() {
RequestMatcher matcher = EndpointRequest.to(FooEndpoint.class).excluding("bar");
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[foo]', Excludes='[bar]', IncludeLinks='false']");
}
@Test
void toStringIncludedExcludedEndpoints() {
RequestMatcher matcher = EndpointRequest.toAnyEndpoint().excluding("bar").excludingLinks();
assertThat(matcher.toString())
.isEqualTo("EndpointRequest [includes='[*]', Excludes='[bar]', IncludeLinks='false']");
}
private RequestMatcherAssert assertMatcher(RequestMatcher matcher) {
return assertMatcher(matcher, mockPathMappedEndpoints("/actuator"));
}

Loading…
Cancel
Save