mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Add WebClient integration test for multipart
This commit adds an integration test for `WebClient`, specifically testing that a failure happening while pulishing the request body is reported on the main reactive pipeline. See gh-35678
This commit is contained in:
+30
@@ -71,12 +71,14 @@ import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseCookie;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.MultipartBodyBuilder;
|
||||
import org.springframework.http.client.reactive.ClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JdkClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.JettyClientHttpConnector;
|
||||
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||
import org.springframework.web.reactive.function.BodyExtractors;
|
||||
import org.springframework.web.reactive.function.BodyInserters;
|
||||
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
|
||||
import org.springframework.web.testfixture.xml.Pojo;
|
||||
|
||||
@@ -1320,6 +1322,34 @@ class WebClientIntegrationTests {
|
||||
.verify(Duration.ofSeconds(3));
|
||||
}
|
||||
|
||||
@ParameterizedWebClientTest
|
||||
void failWhileSendingMultipartRequest(ClientHttpConnector connector) throws IOException {
|
||||
startServer(connector);
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "text/plain").body("Hello"));
|
||||
|
||||
MultipartBodyBuilder data = new MultipartBodyBuilder();
|
||||
data.part("first", "success");
|
||||
data.asyncPart("second",
|
||||
Mono.delay(Duration.ofMillis(500)).then(Mono.error(new IllegalStateException("multipart client error"))),
|
||||
String.class);
|
||||
|
||||
Mono<ResponseEntity<String>> result = this.webClient.post()
|
||||
.uri("/multipart").accept(MediaType.TEXT_PLAIN)
|
||||
.body(BodyInserters.fromMultipartData(data.build()))
|
||||
.retrieve()
|
||||
.toEntity(String.class)
|
||||
.log();
|
||||
|
||||
StepVerifier.create(result)
|
||||
.expectErrorSatisfies(error -> assertThat(error)
|
||||
.isInstanceOf(WebClientRequestException.class)
|
||||
.hasMessageContaining("multipart client error"))
|
||||
.verify(Duration.ofSeconds(5));
|
||||
|
||||
expectRequestCount(0);
|
||||
}
|
||||
|
||||
private <T> Mono<T> doMalformedChunkedResponseTest(
|
||||
ClientHttpConnector connector, Function<ResponseSpec, Mono<T>> handler) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user