Rename body(Object) to bodyValue
The recently added body(Object) variant can be confused easily with body(Publisher, Class) forgetting to provide the element type and only running into the IllegalArgumentException at runtime. See gh-23212
This commit is contained in:
@@ -261,8 +261,8 @@ class DefaultWebTestClient implements WebTestClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestHeadersSpec<?> body(Object body) {
|
||||
this.bodySpec.body(body);
|
||||
public RequestHeadersSpec<?> bodyValue(Object body) {
|
||||
this.bodySpec.bodyValue(body);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ class DefaultWebTestClient implements WebTestClient {
|
||||
@Override
|
||||
@Deprecated
|
||||
public RequestHeadersSpec<?> syncBody(Object body) {
|
||||
return body(body);
|
||||
return bodyValue(body);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -642,7 +642,7 @@ public interface WebTestClient {
|
||||
* @return spec for decoding the response
|
||||
* @since 5.2
|
||||
*/
|
||||
RequestHeadersSpec<?> body(Object body);
|
||||
RequestHeadersSpec<?> bodyValue(Object body);
|
||||
|
||||
/**
|
||||
* Set the body of the request to the given producer.
|
||||
@@ -713,7 +713,7 @@ public interface WebTestClient {
|
||||
* @throws IllegalArgumentException if {@code body} is a {@link Publisher} or an
|
||||
* instance of a type supported by {@link ReactiveAdapterRegistry#getSharedInstance()},
|
||||
* for which {@link #body(Publisher, Class)} or {@link #body(Object, Class)} should be used.
|
||||
* @deprecated as of Spring Framework 5.2 in favor of {@link #body(Object)}
|
||||
* @deprecated as of Spring Framework 5.2 in favor of {@link #bodyValue(Object)}
|
||||
*/
|
||||
@Deprecated
|
||||
RequestHeadersSpec<?> syncBody(Object body);
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ApplicationContextSpecTests {
|
||||
.GET("/sessionClassName", request ->
|
||||
request.session().flatMap(session -> {
|
||||
String className = session.getClass().getSimpleName();
|
||||
return ServerResponse.ok().body(className);
|
||||
return ServerResponse.ok().bodyValue(className);
|
||||
}))
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ErrorTests {
|
||||
EntityExchangeResult<Void> result = this.client.post()
|
||||
.uri("/post")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(new Person("Dan"))
|
||||
.bodyValue(new Person("Dan"))
|
||||
.exchange()
|
||||
.expectStatus().isBadRequest()
|
||||
.expectBody().isEmpty();
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JsonContentTests {
|
||||
public void postJsonContent() {
|
||||
this.client.post().uri("/persons")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"John\"}")
|
||||
.bodyValue("{\"name\":\"John\"}")
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectBody().isEmpty();
|
||||
|
||||
@@ -145,7 +145,7 @@ public class ResponseEntityTests {
|
||||
@Test
|
||||
public void postEntity() {
|
||||
this.client.post()
|
||||
.body(new Person("John"))
|
||||
.bodyValue(new Person("John"))
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectHeader().valueEquals("location", "/persons/John")
|
||||
|
||||
@@ -116,7 +116,7 @@ public class XmlContentTests {
|
||||
|
||||
this.client.post().uri("/persons")
|
||||
.contentType(MediaType.APPLICATION_XML)
|
||||
.body(content)
|
||||
.bodyValue(content)
|
||||
.exchange()
|
||||
.expectStatus().isCreated()
|
||||
.expectHeader().valueEquals(HttpHeaders.LOCATION, "/persons/John")
|
||||
|
||||
@@ -45,7 +45,7 @@ public class HttpServerTests {
|
||||
@BeforeEach
|
||||
public void start() throws Exception {
|
||||
HttpHandler httpHandler = RouterFunctions.toHttpHandler(
|
||||
route(GET("/test"), request -> ServerResponse.ok().body("It works!")));
|
||||
route(GET("/test"), request -> ServerResponse.ok().bodyValue("It works!")));
|
||||
|
||||
this.server = new ReactorHttpServer();
|
||||
this.server.setHandler(httpHandler);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class RouterFunctionTests {
|
||||
public void setUp() throws Exception {
|
||||
|
||||
RouterFunction<?> route = route(GET("/test"), request ->
|
||||
ServerResponse.ok().body("It works!"));
|
||||
ServerResponse.ok().bodyValue("It works!"));
|
||||
|
||||
this.testClient = WebTestClient.bindToRouterFunction(route).build();
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ class WebTestClientExtensionsTests {
|
||||
@Test
|
||||
fun `KotlinBodySpec#isEqualTo`() {
|
||||
WebTestClient
|
||||
.bindToRouterFunction( router { GET("/") { ok().body("foo") } } )
|
||||
.bindToRouterFunction( router { GET("/") { ok().bodyValue("foo") } } )
|
||||
.build()
|
||||
.get().uri("/").exchange().expectBody<String>().isEqualTo("foo")
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class WebTestClientExtensionsTests {
|
||||
@Test
|
||||
fun `KotlinBodySpec#consumeWith`() {
|
||||
WebTestClient
|
||||
.bindToRouterFunction( router { GET("/") { ok().body("foo") } } )
|
||||
.bindToRouterFunction( router { GET("/") { ok().bodyValue("foo") } } )
|
||||
.build()
|
||||
.get().uri("/").exchange().expectBody<String>().consumeWith { assertEquals("foo", it.responseBody) }
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class WebTestClientExtensionsTests {
|
||||
@Test
|
||||
fun `KotlinBodySpec#returnResult`() {
|
||||
WebTestClient
|
||||
.bindToRouterFunction( router { GET("/") { ok().body("foo") } } )
|
||||
.bindToRouterFunction( router { GET("/") { ok().bodyValue("foo") } } )
|
||||
.build()
|
||||
.get().uri("/").exchange().expectBody<String>().returnResult().apply { assertEquals("foo", responseBody) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user