mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Add exchangeSuccessfully to test clients
Closes gh-35582
This commit is contained in:
+5
@@ -381,6 +381,11 @@ class DefaultWebTestClient implements WebTestClient {
|
||||
DefaultWebTestClient.this.entityResultConsumer, getResponseTimeout());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseSpec exchangeSuccessfully() {
|
||||
return exchange().expectStatus().is2xxSuccessful();
|
||||
}
|
||||
|
||||
private ClientRequest.Builder initRequestBuilder() {
|
||||
return ClientRequest.create(this.httpMethod, initUri())
|
||||
.headers(headersToUse -> {
|
||||
|
||||
+13
-2
@@ -700,10 +700,21 @@ public interface WebTestClient {
|
||||
S attributes(Consumer<Map<String, Object>> attributesConsumer);
|
||||
|
||||
/**
|
||||
* Perform the exchange without a request body.
|
||||
* @return a spec for decoding the response
|
||||
* Perform the exchange.
|
||||
* @return a spec for expectations on the response
|
||||
*/
|
||||
ResponseSpec exchange();
|
||||
|
||||
/**
|
||||
* Variant of {@link #exchange()} that expects a successful response.
|
||||
* Effectively, a shortcut for:
|
||||
* <pre class="code">
|
||||
* exchange().is2xxSuccessful()
|
||||
* </pre>
|
||||
* @return a spec for expectations on the response
|
||||
* @since 7.0
|
||||
*/
|
||||
ResponseSpec exchangeSuccessfully();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
@@ -269,6 +269,11 @@ class DefaultRestTestClient implements RestTestClient {
|
||||
}, false),
|
||||
DefaultRestTestClient.this.entityResultConsumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseSpec exchangeSuccessfully() {
|
||||
return exchange().expectStatus().is2xxSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
-2
@@ -514,10 +514,20 @@ public interface RestTestClient {
|
||||
S attributes(Consumer<Map<String, Object>> attributesConsumer);
|
||||
|
||||
/**
|
||||
* Perform the exchange without a request body.
|
||||
* @return a spec for decoding the response
|
||||
* Perform the exchange.
|
||||
* @return a spec for expectations on the response
|
||||
*/
|
||||
ResponseSpec exchange();
|
||||
|
||||
/**
|
||||
* Variant of {@link #exchange()} that expects a successful response.
|
||||
* Effectively, a shortcut for:
|
||||
* <pre class="code">
|
||||
* exchange().is2xxSuccessful()
|
||||
* </pre>
|
||||
* @return a spec for expectations on the response
|
||||
*/
|
||||
ResponseSpec exchangeSuccessfully();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user