Browse Source

Polish tests to use WebClient retrieve()

pull/1799/merge
Rossen Stoyanchev 8 years ago
parent
commit
30c98c8a1c
  1. 20
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java
  2. 13
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java
  3. 8
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java
  4. 23
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java
  5. 3
      spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java

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

@ -106,8 +106,8 @@ public class WebClientIntegrationTests { @@ -106,8 +106,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!")
@ -256,8 +256,8 @@ public class WebClientIntegrationTests { @@ -256,8 +256,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()))
@ -280,8 +280,8 @@ public class WebClientIntegrationTests { @@ -280,8 +280,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")))
@ -306,8 +306,8 @@ public class WebClientIntegrationTests { @@ -306,8 +306,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()))
@ -332,8 +332,8 @@ public class WebClientIntegrationTests { @@ -332,8 +332,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")

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

@ -63,8 +63,8 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn @@ -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 @@ -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 @@ -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 -> {

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

@ -70,8 +70,8 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra @@ -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 @@ -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"))

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

@ -43,7 +43,6 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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")

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

@ -59,8 +59,7 @@ public class LocaleContextResolverIntegrationTests extends AbstractRequestMappin @@ -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());

Loading…
Cancel
Save