Request body improvements in WebClient, WebTestClient

This commit makes changes to WebClient and WebTestClient in oder to
limit setting the body according to HTTP method and also to facilitate
providing the request body as Object.

Specifically, this commit:

 - Moves methods that operate on the request body to a RequestBodySpec
 in both WebClient and WebTestClient, and rename them to `body`.
 These methods now just *set* the body, without performing
 an exchange (which now requires an explicit exchange call).
 - Parameterizes UriSpec in both WebClient and WebTestClient, so that
 it returns either a RequestHeadersSpec or a RequestBodySpec.

Issue: SPR-15394
This commit is contained in:
Arjen Poutsma
2017-03-29 11:51:51 -04:00
committed by Rossen Stoyanchev
parent cbd98d5247
commit 118f33aeda
7 changed files with 293 additions and 207 deletions

View File

@@ -41,7 +41,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;
import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
/**
@@ -115,7 +115,8 @@ public class ResponseEntityTests {
@Test
public void postEntity() throws Exception {
this.client.post().uri("/persons")
.exchange(Mono.just(new Person("John")), Person.class)
.body(Mono.just(new Person("John")), Person.class)
.exchange()
.expectStatus().isCreated()
.expectHeader().valueEquals("location", "/persons/John")
.expectBody().isEmpty();