22
22
import org .springframework .http .HttpHeaders ;
23
23
import org .springframework .http .HttpMethod ;
24
24
import org .springframework .http .HttpStatus ;
25
+ import org .springframework .http .ResponseCookie ;
25
26
import org .springframework .http .client .reactive .ClientHttpRequest ;
27
+ import org .springframework .util .MultiValueMap ;
26
28
import org .springframework .web .reactive .function .client .ClientResponse ;
27
29
28
30
/**
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}.
30
33
*
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 .
34
37
*
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 .
38
41
*
39
42
* @author Rossen Stoyanchev
40
43
* @since 5.0
44
+ * @see EntityExchangeResult
45
+ * @see FluxExchangeResult
41
46
*/
42
47
public class ExchangeResult {
43
48
@@ -51,21 +56,31 @@ public class ExchangeResult {
51
56
52
57
private final HttpHeaders responseHeaders ;
53
58
59
+ private final MultiValueMap <String , ResponseCookie > responseCookies ;
54
60
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 ) {
56
66
this .method = request .getMethod ();
57
67
this .url = request .getURI ();
58
68
this .requestHeaders = request .getHeaders ();
59
69
this .status = response .statusCode ();
60
70
this .responseHeaders = response .headers ().asHttpHeaders ();
71
+ this .responseCookies = response .cookies ();
61
72
}
62
73
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 ();
69
84
}
70
85
71
86
@@ -104,6 +119,13 @@ public HttpHeaders getResponseHeaders() {
104
119
return this .responseHeaders ;
105
120
}
106
121
122
+ /**
123
+ * Return response cookies received from the server.
124
+ */
125
+ public MultiValueMap <String , ResponseCookie > getResponseCookies () {
126
+ return this .responseCookies ;
127
+ }
128
+
107
129
108
130
/**
109
131
* Execute the given Runnable in the context of "this" instance and decorate
0 commit comments