Add exchangeSuccessfully to test clients

Closes gh-35582
This commit is contained in:
rstoyanchev
2025-10-14 11:02:13 +01:00
parent 180ea125d2
commit 00190a1111
4 changed files with 35 additions and 4 deletions
@@ -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 -> {
@@ -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();
}
@@ -269,6 +269,11 @@ class DefaultRestTestClient implements RestTestClient {
}, false),
DefaultRestTestClient.this.entityResultConsumer);
}
@Override
public ResponseSpec exchangeSuccessfully() {
return exchange().expectStatus().is2xxSuccessful();
}
}
@@ -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();
}