diff --git a/src/test/java/org/springframework/metrics/instrument/web/MockServerRequest.java b/src/test/java/org/springframework/metrics/instrument/web/MockServerRequest.java index abaf29ead..e8ab9fd63 100644 --- a/src/test/java/org/springframework/metrics/instrument/web/MockServerRequest.java +++ b/src/test/java/org/springframework/metrics/instrument/web/MockServerRequest.java @@ -18,6 +18,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.nio.charset.Charset; +import java.security.Principal; import java.time.Instant; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -46,8 +47,6 @@ import org.springframework.web.server.WebSession; /** - * Mock implementation of {@link ServerRequest}. - * * @author Arjen Poutsma */ public class MockServerRequest implements ServerRequest { @@ -68,11 +67,12 @@ public class MockServerRequest implements ServerRequest { private final WebSession session; + private Principal principal; private MockServerRequest(HttpMethod method, URI uri, - MockHeaders headers, Object body, Map attributes, - MultiValueMap queryParams, - Map pathVariables, WebSession session) { + MockHeaders headers, Object body, Map attributes, + MultiValueMap queryParams, + Map pathVariables, WebSession session, Principal principal) { this.method = method; this.uri = uri; @@ -82,6 +82,7 @@ private MockServerRequest(HttpMethod method, URI uri, this.queryParams = queryParams; this.pathVariables = pathVariables; this.session = session; + this.principal = principal; } @@ -150,6 +151,10 @@ public Mono session() { return Mono.justOrEmpty(this.session); } + @Override + public Mono principal() { + return Mono.justOrEmpty(this.principal); + } public static Builder builder() { return new BuilderImpl(); @@ -180,6 +185,8 @@ public interface Builder { Builder session(WebSession session); + Builder session(Principal principal); + MockServerRequest body(Object body); MockServerRequest build(); @@ -204,6 +211,8 @@ private static class BuilderImpl implements Builder { private WebSession session; + private Principal principal; + @Override public Builder method(HttpMethod method) { Assert.notNull(method, "'method' must not be null"); @@ -285,17 +294,26 @@ public Builder session(WebSession session) { return this; } + @Override + public Builder session(Principal principal) { + Assert.notNull(principal, "'principal' must not be null"); + this.principal = principal; + return this; + } + @Override public MockServerRequest body(Object body) { this.body = body; return new MockServerRequest(this.method, this.uri, this.headers, this.body, - this.attributes, this.queryParams, this.pathVariables, this.session); + this.attributes, this.queryParams, this.pathVariables, this.session, + this.principal); } @Override public MockServerRequest build() { return new MockServerRequest(this.method, this.uri, this.headers, null, - this.attributes, this.queryParams, this.pathVariables, this.session); + this.attributes, this.queryParams, this.pathVariables, this.session, + this.principal); } }