Skip to content

Commit d59dc97

Browse files
committed
Expose response cookies from ExchangeResult
1 parent 1ddf8ec commit d59dc97

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private DefaultResponseSpec toResponseSpec(Mono<ClientResponse> mono) {
261261
}
262262

263263
/**
264-
* ExchangeResult that contains the live {@link ClientResponse}.
264+
* The {@code ExchangeResult} with live, undecoded {@link ClientResponse}.
265265
*/
266266
private class UndecodedExchangeResult extends ExchangeResult {
267267

spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
package org.springframework.test.web.reactive.server;
1717

1818
/**
19-
* {@code ExchangeResult} variant with the response body fully extracted to a
20-
* representation of type {@code <T>}.
19+
* {@code ExchangeResult} sub-class that exposes the response body fully
20+
* extracted to a representation of type {@code <T>}.
2121
*
2222
* @param <T> the response body type
2323
*
2424
* @author Rossen Stoyanchev
2525
* @since 5.0
26+
* @see FluxExchangeResult
2627
*/
2728
public class EntityExchangeResult<T> extends ExchangeResult {
2829

spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@
2222
import org.springframework.http.HttpHeaders;
2323
import org.springframework.http.HttpMethod;
2424
import org.springframework.http.HttpStatus;
25+
import org.springframework.http.ResponseCookie;
2526
import org.springframework.http.client.reactive.ClientHttpRequest;
27+
import org.springframework.util.MultiValueMap;
2628
import org.springframework.web.reactive.function.client.ClientResponse;
2729

2830
/**
29-
* Container for the result of an exchange through the {@link WebTestClient}.
31+
* Simple container for request and response details from an exchange performed
32+
* through the {@link WebTestClient}.
3033
*
31-
* <p>This type only exposes the status and response headers that are available
32-
* when the {@link ClientResponse} is first received and before the response
33-
* body has been consumed.
34+
* <p>An {@code ExchangeResult} only exposes the status and the headers from
35+
* the response which is all that's available when a {@link ClientResponse} is
36+
* first created.
3437
*
35-
* <p>The sub-classes {@link EntityExchangeResult} and {@link FluxExchangeResult}
36-
* expose further information about the response body and are returned only
37-
* after the test client has been used to decode and consume the response.
38+
* <p>Sub-types {@link EntityExchangeResult} and {@link FluxExchangeResult}
39+
* further expose the response body either as a fully extracted representation
40+
* or as a {@code Flux} of representations to be consumed.
3841
*
3942
* @author Rossen Stoyanchev
4043
* @since 5.0
44+
* @see EntityExchangeResult
45+
* @see FluxExchangeResult
4146
*/
4247
public class ExchangeResult {
4348

@@ -51,21 +56,31 @@ public class ExchangeResult {
5156

5257
private final HttpHeaders responseHeaders;
5358

59+
private final MultiValueMap<String, ResponseCookie> responseCookies;
5460

55-
ExchangeResult(ClientHttpRequest request, ClientResponse response) {
61+
62+
/**
63+
* Constructor used when a {@code ClientResponse} is first created.
64+
*/
65+
protected ExchangeResult(ClientHttpRequest request, ClientResponse response) {
5666
this.method = request.getMethod();
5767
this.url = request.getURI();
5868
this.requestHeaders = request.getHeaders();
5969
this.status = response.statusCode();
6070
this.responseHeaders = response.headers().asHttpHeaders();
71+
this.responseCookies = response.cookies();
6172
}
6273

63-
ExchangeResult(ExchangeResult result) {
64-
this.method = result.getMethod();
65-
this.url = result.getUrl();
66-
this.requestHeaders = result.getRequestHeaders();
67-
this.status = result.getStatus();
68-
this.responseHeaders = result.getResponseHeaders();
74+
/**
75+
* Copy constructor used when the body is decoded or consumed.
76+
*/
77+
protected ExchangeResult(ExchangeResult other) {
78+
this.method = other.getMethod();
79+
this.url = other.getUrl();
80+
this.requestHeaders = other.getRequestHeaders();
81+
this.status = other.getStatus();
82+
this.responseHeaders = other.getResponseHeaders();
83+
this.responseCookies = other.getResponseCookies();
6984
}
7085

7186

@@ -104,6 +119,13 @@ public HttpHeaders getResponseHeaders() {
104119
return this.responseHeaders;
105120
}
106121

122+
/**
123+
* Return response cookies received from the server.
124+
*/
125+
public MultiValueMap<String, ResponseCookie> getResponseCookies() {
126+
return this.responseCookies;
127+
}
128+
107129

108130
/**
109131
* Execute the given Runnable in the context of "this" instance and decorate

spring-test/src/main/java/org/springframework/test/web/reactive/server/FluxExchangeResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*
2727
* @author Rossen Stoyanchev
2828
* @since 5.0
29+
* @see EntityExchangeResult
2930
*/
3031
public class FluxExchangeResult<T> extends ExchangeResult {
3132

0 commit comments

Comments
 (0)