From c6e7b567e34d316cbb2424d44d011e2de971201b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 9 Jul 2021 19:45:26 +0100 Subject: [PATCH] Stabilize WebTestClientRequestConverterTests Closes gh-736 --- .../WebTestClientRequestConverterTests.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/spring-restdocs-webtestclient/src/test/java/org/springframework/restdocs/webtestclient/WebTestClientRequestConverterTests.java b/spring-restdocs-webtestclient/src/test/java/org/springframework/restdocs/webtestclient/WebTestClientRequestConverterTests.java index 5a18b79b..cd56ef40 100644 --- a/spring-restdocs-webtestclient/src/test/java/org/springframework/restdocs/webtestclient/WebTestClientRequestConverterTests.java +++ b/spring-restdocs-webtestclient/src/test/java/org/springframework/restdocs/webtestclient/WebTestClientRequestConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -182,10 +182,14 @@ public class WebTestClientRequestConverterTests { public void multipartUpload() throws Exception { MultiValueMap multipartData = new LinkedMultiValueMap<>(); multipartData.add("file", new byte[] { 1, 2, 3, 4 }); - ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> { - req.body(BodyExtractors.toMultipartData()).block(); - return null; - })).configureClient().baseUrl("http://localhost").build().post().uri("/foo") + ExchangeResult result = WebTestClient + .bindToRouterFunction( + RouterFunctions + .route(POST("/foo"), + (req) -> ServerResponse.ok() + .body(req.body(BodyExtractors.toMultipartData()) + .map((parts) -> parts.size()), Integer.class))) + .configureClient().baseUrl("http://localhost").build().post().uri("/foo") .body(BodyInserters.fromMultipartData(multipartData)).exchange().expectBody().returnResult(); OperationRequest request = this.converter.convert(result); assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo")); @@ -211,10 +215,14 @@ public class WebTestClientRequestConverterTests { } }); - ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> { - req.body(BodyExtractors.toMultipartData()).block(); - return null; - })).configureClient().baseUrl("http://localhost").build().post().uri("/foo") + ExchangeResult result = WebTestClient + .bindToRouterFunction( + RouterFunctions + .route(POST("/foo"), + (req) -> ServerResponse.ok() + .body(req.body(BodyExtractors.toMultipartData()) + .map((parts) -> parts.size()), Integer.class))) + .configureClient().baseUrl("http://localhost").build().post().uri("/foo") .body(BodyInserters.fromMultipartData(multipartData)).exchange().expectBody().returnResult(); OperationRequest request = this.converter.convert(result); assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));