From e7c3ab3e274e1769889a531bdd6bb157b50dbf2a Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 20 Aug 2019 13:03:24 +0200 Subject: [PATCH] Rename WebFlux response body methods This commit adapts to recent changes in Spring Framework. See spring-projects/spring-framework#23212 --- .../AbstractWebEndpointIntegrationTests.java | 4 ++-- ...ndpointHandlerMappingIntegrationTests.java | 2 +- ...ndpointHandlerMappingIntegrationTests.java | 2 +- .../LoggersEndpointWebIntegrationTests.java | 23 +++++++++++-------- .../AbstractErrorWebExceptionHandler.java | 4 ++-- ...orWebExceptionHandlerIntegrationTests.java | 2 +- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java index 5054be7e95..dcef4df5b5 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java @@ -179,7 +179,7 @@ public abstract class AbstractWebEndpointIntegrationTests body = new HashMap<>(); body.put("foo", "one"); body.put("bar", "two"); - client.post().uri("/test").body(body).exchange().expectStatus().isNoContent().expectBody().isEmpty(); + client.post().uri("/test").bodyValue(body).exchange().expectStatus().isNoContent().expectBody().isEmpty(); }); } @@ -210,7 +210,7 @@ public abstract class AbstractWebEndpointIntegrationTests { Map body = new HashMap<>(); body.put("foo", "one"); - client.post().uri("/test").body(body).exchange().expectStatus().isNoContent().expectBody().isEmpty(); + client.post().uri("/test").bodyValue(body).exchange().expectStatus().isNoContent().expectBody().isEmpty(); verify(context.getBean(EndpointDelegate.class)).write("one", null); }); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java index fe54be2d34..bcbffcee65 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/ControllerEndpointHandlerMappingIntegrationTests.java @@ -80,7 +80,7 @@ class ControllerEndpointHandlerMappingIntegrationTests { @Test void post() { this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.post().uri("/actuator/example/two") - .body(Collections.singletonMap("id", "test")).exchange().expectStatus().isCreated().expectHeader() + .bodyValue(Collections.singletonMap("id", "test")).exchange().expectStatus().isCreated().expectHeader() .valueEquals(HttpHeaders.LOCATION, "/example/test"))); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java index eb365525ad..ef42dc9783 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/ControllerEndpointHandlerMappingIntegrationTests.java @@ -79,7 +79,7 @@ class ControllerEndpointHandlerMappingIntegrationTests { @Test void post() { this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.post().uri("/actuator/example/two") - .body(Collections.singletonMap("id", "test")).exchange().expectStatus().isCreated().expectHeader() + .bodyValue(Collections.singletonMap("id", "test")).exchange().expectStatus().isCreated().expectHeader() .valueEquals(HttpHeaders.LOCATION, "/example/test"))); } diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java index a3b857c6d3..e7411d979c 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LoggersEndpointWebIntegrationTests.java @@ -118,7 +118,8 @@ class LoggersEndpointWebIntegrationTests { @WebEndpointTest void setLoggerUsingApplicationJsonShouldSetLogLevel() { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.APPLICATION_JSON) - .body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent(); + .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() + .isNoContent(); verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); } @@ -126,7 +127,8 @@ class LoggersEndpointWebIntegrationTests { void setLoggerUsingActuatorV2JsonShouldSetLogLevel() { this.client.post().uri("/actuator/loggers/ROOT") .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)) - .body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent(); + .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() + .isNoContent(); verify(this.loggingSystem).setLogLevel("ROOT", LogLevel.DEBUG); } @@ -134,7 +136,8 @@ class LoggersEndpointWebIntegrationTests { void setLoggerGroupUsingActuatorV2JsonShouldSetLogLevel() { this.client.post().uri("/actuator/loggers/test") .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)) - .body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent(); + .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() + .isNoContent(); verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG); verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG); } @@ -142,7 +145,8 @@ class LoggersEndpointWebIntegrationTests { @WebEndpointTest void setLoggerGroupUsingApplicationJsonShouldSetLogLevel() { this.client.post().uri("/actuator/loggers/test").contentType(MediaType.APPLICATION_JSON) - .body(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus().isNoContent(); + .bodyValue(Collections.singletonMap("configuredLevel", "debug")).exchange().expectStatus() + .isNoContent(); verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG); verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG); } @@ -150,7 +154,8 @@ class LoggersEndpointWebIntegrationTests { @WebEndpointTest void setLoggerOrLoggerGroupWithWrongLogLevelResultInBadRequestResponse() { this.client.post().uri("/actuator/loggers/ROOT").contentType(MediaType.APPLICATION_JSON) - .body(Collections.singletonMap("configuredLevel", "other")).exchange().expectStatus().isBadRequest(); + .bodyValue(Collections.singletonMap("configuredLevel", "other")).exchange().expectStatus() + .isBadRequest(); verifyZeroInteractions(this.loggingSystem); } @@ -158,14 +163,14 @@ class LoggersEndpointWebIntegrationTests { void setLoggerWithNullLogLevel() { this.client.post().uri("/actuator/loggers/ROOT") .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)) - .body(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent(); + .bodyValue(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent(); verify(this.loggingSystem).setLogLevel("ROOT", null); } @WebEndpointTest void setLoggerWithNoLogLevel() { this.client.post().uri("/actuator/loggers/ROOT") - .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)).body(Collections.emptyMap()) + .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)).bodyValue(Collections.emptyMap()) .exchange().expectStatus().isNoContent(); verify(this.loggingSystem).setLogLevel("ROOT", null); } @@ -174,7 +179,7 @@ class LoggersEndpointWebIntegrationTests { void setLoggerGroupWithNullLogLevel() { this.client.post().uri("/actuator/loggers/test") .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)) - .body(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent(); + .bodyValue(Collections.singletonMap("configuredLevel", null)).exchange().expectStatus().isNoContent(); verify(this.loggingSystem).setLogLevel("test.member1", null); verify(this.loggingSystem).setLogLevel("test.member2", null); } @@ -182,7 +187,7 @@ class LoggersEndpointWebIntegrationTests { @WebEndpointTest void setLoggerGroupWithNoLogLevel() { this.client.post().uri("/actuator/loggers/test") - .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)).body(Collections.emptyMap()) + .contentType(MediaType.parseMediaType(ActuatorMediaType.V2_JSON)).bodyValue(Collections.emptyMap()) .exchange().expectStatus().isNoContent(); verify(this.loggingSystem).setLogLevel("test.member1", null); verify(this.loggingSystem).setLogLevel("test.member2", null); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java index b67ae96b37..2d4732b0e5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/AbstractErrorWebExceptionHandler.java @@ -171,7 +171,7 @@ public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExcept } Resource resource = resolveResource(viewName); if (resource != null) { - return responseBody.body(BodyInserters.fromResource(resource)); + return responseBody.bodyValue(BodyInserters.fromResource(resource)); } return Mono.empty(); } @@ -223,7 +223,7 @@ public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExcept builder.append("
").append(htmlEscape(trace)).append("
"); } builder.append(""); - return responseBody.body(builder.toString()); + return responseBody.bodyValue(builder.toString()); } private String htmlEscape(Object input) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java index c30f452632..ede71b38ba 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java @@ -111,7 +111,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests { void bindingResultError() { this.contextRunner.run((context) -> { WebTestClient client = getWebClient(context); - client.post().uri("/bind").contentType(MediaType.APPLICATION_JSON).body("{}").exchange().expectStatus() + client.post().uri("/bind").contentType(MediaType.APPLICATION_JSON).bodyValue("{}").exchange().expectStatus() .isBadRequest().expectBody().jsonPath("status").isEqualTo("400").jsonPath("error") .isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path").isEqualTo(("/bind")) .jsonPath("exception").doesNotExist().jsonPath("errors").isArray().jsonPath("message").isNotEmpty()