Skip to content

Commit c6e7b56

Browse files
committed
Stabilize WebTestClientRequestConverterTests
Closes gh-736
1 parent 88fe8a6 commit c6e7b56

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

spring-restdocs-webtestclient/src/test/java/org/springframework/restdocs/webtestclient/WebTestClientRequestConverterTests.java

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -182,10 +182,14 @@ public void postRequestWithNoContentType() throws Exception {
182182
public void multipartUpload() throws Exception {
183183
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
184184
multipartData.add("file", new byte[] { 1, 2, 3, 4 });
185-
ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> {
186-
req.body(BodyExtractors.toMultipartData()).block();
187-
return null;
188-
})).configureClient().baseUrl("http://localhost").build().post().uri("/foo")
185+
ExchangeResult result = WebTestClient
186+
.bindToRouterFunction(
187+
RouterFunctions
188+
.route(POST("/foo"),
189+
(req) -> ServerResponse.ok()
190+
.body(req.body(BodyExtractors.toMultipartData())
191+
.map((parts) -> parts.size()), Integer.class)))
192+
.configureClient().baseUrl("http://localhost").build().post().uri("/foo")
189193
.body(BodyInserters.fromMultipartData(multipartData)).exchange().expectBody().returnResult();
190194
OperationRequest request = this.converter.convert(result);
191195
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
@@ -211,10 +215,14 @@ public String getFilename() {
211215
}
212216

213217
});
214-
ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> {
215-
req.body(BodyExtractors.toMultipartData()).block();
216-
return null;
217-
})).configureClient().baseUrl("http://localhost").build().post().uri("/foo")
218+
ExchangeResult result = WebTestClient
219+
.bindToRouterFunction(
220+
RouterFunctions
221+
.route(POST("/foo"),
222+
(req) -> ServerResponse.ok()
223+
.body(req.body(BodyExtractors.toMultipartData())
224+
.map((parts) -> parts.size()), Integer.class)))
225+
.configureClient().baseUrl("http://localhost").build().post().uri("/foo")
218226
.body(BodyInserters.fromMultipartData(multipartData)).exchange().expectBody().returnResult();
219227
OperationRequest request = this.converter.convert(result);
220228
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));

0 commit comments

Comments
 (0)