diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 3fcc8163b9..b1c6ba60d8 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -261,7 +261,7 @@ class DefaultWebTestClient implements WebTestClient { } /** - * ExchangeResult that contains the live {@link ClientResponse}. + * The {@code ExchangeResult} with live, undecoded {@link ClientResponse}. */ private class UndecodedExchangeResult extends ExchangeResult { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java index df7d9db7b8..94c67d5e13 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java @@ -16,13 +16,14 @@ package org.springframework.test.web.reactive.server; /** - * {@code ExchangeResult} variant with the response body fully extracted to a - * representation of type {@code }. + * {@code ExchangeResult} sub-class that exposes the response body fully + * extracted to a representation of type {@code }. * * @param the response body type * * @author Rossen Stoyanchev * @since 5.0 + * @see FluxExchangeResult */ public class EntityExchangeResult extends ExchangeResult { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java index 22134d52cb..a9d0275932 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java @@ -22,22 +22,27 @@ import java.util.stream.Collectors; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseCookie; import org.springframework.http.client.reactive.ClientHttpRequest; +import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.ClientResponse; /** - * Container for the result of an exchange through the {@link WebTestClient}. + * Simple container for request and response details from an exchange performed + * through the {@link WebTestClient}. * - *

This type only exposes the status and response headers that are available - * when the {@link ClientResponse} is first received and before the response - * body has been consumed. + *

An {@code ExchangeResult} only exposes the status and the headers from + * the response which is all that's available when a {@link ClientResponse} is + * first created. * - *

The sub-classes {@link EntityExchangeResult} and {@link FluxExchangeResult} - * expose further information about the response body and are returned only - * after the test client has been used to decode and consume the response. + *

Sub-types {@link EntityExchangeResult} and {@link FluxExchangeResult} + * further expose the response body either as a fully extracted representation + * or as a {@code Flux} of representations to be consumed. * * @author Rossen Stoyanchev * @since 5.0 + * @see EntityExchangeResult + * @see FluxExchangeResult */ public class ExchangeResult { @@ -51,21 +56,31 @@ public class ExchangeResult { private final HttpHeaders responseHeaders; + private final MultiValueMap responseCookies; - ExchangeResult(ClientHttpRequest request, ClientResponse response) { + + /** + * Constructor used when a {@code ClientResponse} is first created. + */ + protected ExchangeResult(ClientHttpRequest request, ClientResponse response) { this.method = request.getMethod(); this.url = request.getURI(); this.requestHeaders = request.getHeaders(); this.status = response.statusCode(); this.responseHeaders = response.headers().asHttpHeaders(); + this.responseCookies = response.cookies(); } - ExchangeResult(ExchangeResult result) { - this.method = result.getMethod(); - this.url = result.getUrl(); - this.requestHeaders = result.getRequestHeaders(); - this.status = result.getStatus(); - this.responseHeaders = result.getResponseHeaders(); + /** + * Copy constructor used when the body is decoded or consumed. + */ + protected ExchangeResult(ExchangeResult other) { + this.method = other.getMethod(); + this.url = other.getUrl(); + this.requestHeaders = other.getRequestHeaders(); + this.status = other.getStatus(); + this.responseHeaders = other.getResponseHeaders(); + this.responseCookies = other.getResponseCookies(); } @@ -104,6 +119,13 @@ public class ExchangeResult { return this.responseHeaders; } + /** + * Return response cookies received from the server. + */ + public MultiValueMap getResponseCookies() { + return this.responseCookies; + } + /** * Execute the given Runnable in the context of "this" instance and decorate diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/FluxExchangeResult.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/FluxExchangeResult.java index b6b0224010..76676062b1 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/FluxExchangeResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/FluxExchangeResult.java @@ -26,6 +26,7 @@ import org.springframework.core.ResolvableType; * * @author Rossen Stoyanchev * @since 5.0 + * @see EntityExchangeResult */ public class FluxExchangeResult extends ExchangeResult {