Polish tests to use WebClient retrieve()

This commit is contained in:
Rossen Stoyanchev
2018-04-19 09:39:34 -04:00
parent 922fd1e785
commit 881343e928
5 changed files with 31 additions and 36 deletions

View File

@@ -108,8 +108,8 @@ public class WebClientIntegrationTests {
Mono<String> result = this.webClient.get()
.uri("/greeting?name=Spring")
.header("X-Test-Header", "testvalue")
.exchange()
.flatMap(response -> response.bodyToMono(String.class));
.retrieve()
.bodyToMono(String.class);
StepVerifier.create(result)
.expectNext("Hello Spring!")
@@ -255,8 +255,8 @@ public class WebClientIntegrationTests {
Mono<Pojo> result = this.webClient.get()
.uri("/pojo")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMap(response -> response.bodyToMono(Pojo.class));
.retrieve()
.bodyToMono(Pojo.class);
StepVerifier.create(result)
.consumeNextWith(p -> assertEquals("barbar", p.getBar()))
@@ -279,8 +279,8 @@ public class WebClientIntegrationTests {
Flux<Pojo> result = this.webClient.get()
.uri("/pojos")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMapMany(response -> response.bodyToFlux(Pojo.class));
.retrieve()
.bodyToFlux(Pojo.class);
StepVerifier.create(result)
.consumeNextWith(p -> assertThat(p.getBar(), Matchers.is("bar1")))
@@ -305,8 +305,8 @@ public class WebClientIntegrationTests {
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.syncBody(new Pojo("foofoo", "barbar"))
.exchange()
.flatMap(response -> response.bodyToMono(Pojo.class));
.retrieve()
.bodyToMono(Pojo.class);
StepVerifier.create(result)
.consumeNextWith(p -> assertEquals("BARBAR", p.getBar()))
@@ -331,8 +331,8 @@ public class WebClientIntegrationTests {
Mono<String> result = this.webClient.get()
.uri("/test")
.cookie("testkey", "testvalue")
.exchange()
.flatMap(response -> response.bodyToMono(String.class));
.retrieve()
.bodyToMono(String.class);
StepVerifier.create(result)
.expectNext("test")

View File

@@ -63,8 +63,8 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
Flux<String> result = this.webClient.get()
.uri("/string")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.body(toFlux(String.class)));
.retrieve()
.bodyToFlux(String.class);
StepVerifier.create(result)
.expectNext("foo 0")
@@ -78,8 +78,8 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
Flux<Person> result = this.webClient.get()
.uri("/person")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.body(toFlux(Person.class)));
.retrieve()
.bodyToFlux(Person.class);
StepVerifier.create(result)
.expectNext(new Person("foo 0"))
@@ -93,9 +93,8 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.body(toFlux(
new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
.retrieve()
.bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
StepVerifier.create(result)
.consumeNextWith( event -> {

View File

@@ -70,8 +70,8 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra
Flux<Person> result = this.webClient.get()
.uri("/stream")
.accept(APPLICATION_STREAM_JSON)
.exchange()
.flatMapMany(response -> response.bodyToFlux(Person.class));
.retrieve()
.bodyToFlux(Person.class);
StepVerifier.create(result)
.expectNext(new Person("foo 0"))
@@ -85,8 +85,8 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra
Flux<Person> result = this.webClient.get()
.uri("/stream")
.accept(new MediaType("application", "stream+x-jackson-smile"))
.exchange()
.flatMapMany(response -> response.bodyToFlux(Person.class));
.retrieve()
.bodyToFlux(Person.class);
StepVerifier.create(result)
.expectNext(new Person("foo 0"))

View File

@@ -43,7 +43,6 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import static org.springframework.http.MediaType.*;
import static org.springframework.web.reactive.function.BodyExtractors.*;
/**
* @author Sebastien Deleuze
@@ -77,8 +76,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<String> result = this.webClient.get()
.uri("/string")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.bodyToFlux(String.class));
.retrieve()
.bodyToFlux(String.class);
StepVerifier.create(result)
.expectNext("foo 0")
@@ -92,8 +91,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<Person> result = this.webClient.get()
.uri("/person")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.bodyToFlux(Person.class));
.retrieve()
.bodyToFlux(Person.class);
StepVerifier.create(result)
.expectNext(new Person("foo 0"))
@@ -107,9 +106,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.body(
toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
.retrieve()
.bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
StepVerifier.create(result)
.consumeNextWith( event -> {
@@ -135,9 +133,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.body(
toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
.retrieve()
.bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
StepVerifier.create(result)
.consumeNextWith( event -> {
@@ -167,8 +164,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<String> result = this.webClient.get()
.uri("/infinite")
.accept(TEXT_EVENT_STREAM)
.exchange()
.flatMapMany(response -> response.bodyToFlux(String.class));
.retrieve()
.bodyToFlux(String.class);
StepVerifier.create(result)
.expectNext("foo 0")

View File

@@ -59,8 +59,7 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin
.uri("http://localhost:" + this.port + "/")
.exchange();
StepVerifier
.create(result)
StepVerifier.create(result)
.consumeNextWith(response -> {
assertEquals(HttpStatus.OK, response.statusCode());
assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage());