Skip to content

Commit 30c98c8

Browse files
committed
Polish tests to use WebClient retrieve()
1 parent 7eb8070 commit 30c98c8

File tree

5 files changed

+31
-36
lines changed

5 files changed

+31
-36
lines changed

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public void shouldReceivePlainText() throws Exception {
106106
Mono<String> result = this.webClient.get()
107107
.uri("/greeting?name=Spring")
108108
.header("X-Test-Header", "testvalue")
109-
.exchange()
110-
.flatMap(response -> response.bodyToMono(String.class));
109+
.retrieve()
110+
.bodyToMono(String.class);
111111

112112
StepVerifier.create(result)
113113
.expectNext("Hello Spring!")
@@ -256,8 +256,8 @@ public void shouldReceiveJsonAsPojo() throws Exception {
256256
Mono<Pojo> result = this.webClient.get()
257257
.uri("/pojo")
258258
.accept(MediaType.APPLICATION_JSON)
259-
.exchange()
260-
.flatMap(response -> response.bodyToMono(Pojo.class));
259+
.retrieve()
260+
.bodyToMono(Pojo.class);
261261

262262
StepVerifier.create(result)
263263
.consumeNextWith(p -> assertEquals("barbar", p.getBar()))
@@ -280,8 +280,8 @@ public void shouldReceiveJsonAsFluxPojo() throws Exception {
280280
Flux<Pojo> result = this.webClient.get()
281281
.uri("/pojos")
282282
.accept(MediaType.APPLICATION_JSON)
283-
.exchange()
284-
.flatMapMany(response -> response.bodyToFlux(Pojo.class));
283+
.retrieve()
284+
.bodyToFlux(Pojo.class);
285285

286286
StepVerifier.create(result)
287287
.consumeNextWith(p -> assertThat(p.getBar(), Matchers.is("bar1")))
@@ -306,8 +306,8 @@ public void shouldSendPojoAsJson() throws Exception {
306306
.accept(MediaType.APPLICATION_JSON)
307307
.contentType(MediaType.APPLICATION_JSON)
308308
.syncBody(new Pojo("foofoo", "barbar"))
309-
.exchange()
310-
.flatMap(response -> response.bodyToMono(Pojo.class));
309+
.retrieve()
310+
.bodyToMono(Pojo.class);
311311

312312
StepVerifier.create(result)
313313
.consumeNextWith(p -> assertEquals("BARBAR", p.getBar()))
@@ -332,8 +332,8 @@ public void shouldSendCookies() throws Exception {
332332
Mono<String> result = this.webClient.get()
333333
.uri("/test")
334334
.cookie("testkey", "testvalue")
335-
.exchange()
336-
.flatMap(response -> response.bodyToMono(String.class));
335+
.retrieve()
336+
.bodyToMono(String.class);
337337

338338
StepVerifier.create(result)
339339
.expectNext("test")

spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public void sseAsString() {
6363
Flux<String> result = this.webClient.get()
6464
.uri("/string")
6565
.accept(TEXT_EVENT_STREAM)
66-
.exchange()
67-
.flatMapMany(response -> response.body(toFlux(String.class)));
66+
.retrieve()
67+
.bodyToFlux(String.class);
6868

6969
StepVerifier.create(result)
7070
.expectNext("foo 0")
@@ -78,8 +78,8 @@ public void sseAsPerson() {
7878
Flux<Person> result = this.webClient.get()
7979
.uri("/person")
8080
.accept(TEXT_EVENT_STREAM)
81-
.exchange()
82-
.flatMapMany(response -> response.body(toFlux(Person.class)));
81+
.retrieve()
82+
.bodyToFlux(Person.class);
8383

8484
StepVerifier.create(result)
8585
.expectNext(new Person("foo 0"))
@@ -93,9 +93,8 @@ public void sseAsEvent() {
9393
Flux<ServerSentEvent<String>> result = this.webClient.get()
9494
.uri("/event")
9595
.accept(TEXT_EVENT_STREAM)
96-
.exchange()
97-
.flatMapMany(response -> response.body(toFlux(
98-
new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
96+
.retrieve()
97+
.bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
9998

10099
StepVerifier.create(result)
101100
.consumeNextWith( event -> {

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public void jsonStreaming() {
7070
Flux<Person> result = this.webClient.get()
7171
.uri("/stream")
7272
.accept(APPLICATION_STREAM_JSON)
73-
.exchange()
74-
.flatMapMany(response -> response.bodyToFlux(Person.class));
73+
.retrieve()
74+
.bodyToFlux(Person.class);
7575

7676
StepVerifier.create(result)
7777
.expectNext(new Person("foo 0"))
@@ -85,8 +85,8 @@ public void smileStreaming() {
8585
Flux<Person> result = this.webClient.get()
8686
.uri("/stream")
8787
.accept(new MediaType("application", "stream+x-jackson-smile"))
88-
.exchange()
89-
.flatMapMany(response -> response.bodyToFlux(Person.class));
88+
.retrieve()
89+
.bodyToFlux(Person.class);
9090

9191
StepVerifier.create(result)
9292
.expectNext(new Person("foo 0"))

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import static org.junit.Assert.*;
4444
import static org.junit.Assume.*;
4545
import static org.springframework.http.MediaType.*;
46-
import static org.springframework.web.reactive.function.BodyExtractors.*;
4746

4847
/**
4948
* @author Sebastien Deleuze
@@ -77,8 +76,8 @@ public void sseAsString() {
7776
Flux<String> result = this.webClient.get()
7877
.uri("/string")
7978
.accept(TEXT_EVENT_STREAM)
80-
.exchange()
81-
.flatMapMany(response -> response.bodyToFlux(String.class));
79+
.retrieve()
80+
.bodyToFlux(String.class);
8281

8382
StepVerifier.create(result)
8483
.expectNext("foo 0")
@@ -92,8 +91,8 @@ public void sseAsPerson() {
9291
Flux<Person> result = this.webClient.get()
9392
.uri("/person")
9493
.accept(TEXT_EVENT_STREAM)
95-
.exchange()
96-
.flatMapMany(response -> response.bodyToFlux(Person.class));
94+
.retrieve()
95+
.bodyToFlux(Person.class);
9796

9897
StepVerifier.create(result)
9998
.expectNext(new Person("foo 0"))
@@ -107,9 +106,8 @@ public void sseAsEvent() {
107106
Flux<ServerSentEvent<String>> result = this.webClient.get()
108107
.uri("/event")
109108
.accept(TEXT_EVENT_STREAM)
110-
.exchange()
111-
.flatMapMany(response -> response.body(
112-
toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
109+
.retrieve()
110+
.bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
113111

114112
StepVerifier.create(result)
115113
.consumeNextWith( event -> {
@@ -135,9 +133,8 @@ public void sseAsEventWithoutAcceptHeader() {
135133
Flux<ServerSentEvent<String>> result = this.webClient.get()
136134
.uri("/event")
137135
.accept(TEXT_EVENT_STREAM)
138-
.exchange()
139-
.flatMapMany(response -> response.body(
140-
toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
136+
.retrieve()
137+
.bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
141138

142139
StepVerifier.create(result)
143140
.consumeNextWith( event -> {
@@ -167,8 +164,8 @@ public void serverDetectsClientDisconnect() {
167164
Flux<String> result = this.webClient.get()
168165
.uri("/infinite")
169166
.accept(TEXT_EVENT_STREAM)
170-
.exchange()
171-
.flatMapMany(response -> response.bodyToFlux(String.class));
167+
.retrieve()
168+
.bodyToFlux(String.class);
172169

173170
StepVerifier.create(result)
174171
.expectNext("foo 0")

spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public void fixedLocale() {
5959
.uri("http://localhost:" + this.port + "/")
6060
.exchange();
6161

62-
StepVerifier
63-
.create(result)
62+
StepVerifier.create(result)
6463
.consumeNextWith(response -> {
6564
assertEquals(HttpStatus.OK, response.statusCode());
6665
assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage());

0 commit comments

Comments
 (0)