Browse Source

Polish tests to use WebClient retrieve()

pull/1800/head
Rossen Stoyanchev 8 years ago
parent
commit
881343e928
  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

@ -108,8 +108,8 @@ public class WebClientIntegrationTests {
Mono<String> result = this.webClient.get() Mono<String> result = this.webClient.get()
.uri("/greeting?name=Spring") .uri("/greeting?name=Spring")
.header("X-Test-Header", "testvalue") .header("X-Test-Header", "testvalue")
.exchange() .retrieve()
.flatMap(response -> response.bodyToMono(String.class)); .bodyToMono(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("Hello Spring!") .expectNext("Hello Spring!")
@ -255,8 +255,8 @@ public class WebClientIntegrationTests {
Mono<Pojo> result = this.webClient.get() Mono<Pojo> result = this.webClient.get()
.uri("/pojo") .uri("/pojo")
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.exchange() .retrieve()
.flatMap(response -> response.bodyToMono(Pojo.class)); .bodyToMono(Pojo.class);
StepVerifier.create(result) StepVerifier.create(result)
.consumeNextWith(p -> assertEquals("barbar", p.getBar())) .consumeNextWith(p -> assertEquals("barbar", p.getBar()))
@ -279,8 +279,8 @@ public class WebClientIntegrationTests {
Flux<Pojo> result = this.webClient.get() Flux<Pojo> result = this.webClient.get()
.uri("/pojos") .uri("/pojos")
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.exchange() .retrieve()
.flatMapMany(response -> response.bodyToFlux(Pojo.class)); .bodyToFlux(Pojo.class);
StepVerifier.create(result) StepVerifier.create(result)
.consumeNextWith(p -> assertThat(p.getBar(), Matchers.is("bar1"))) .consumeNextWith(p -> assertThat(p.getBar(), Matchers.is("bar1")))
@ -305,8 +305,8 @@ public class WebClientIntegrationTests {
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)
.syncBody(new Pojo("foofoo", "barbar")) .syncBody(new Pojo("foofoo", "barbar"))
.exchange() .retrieve()
.flatMap(response -> response.bodyToMono(Pojo.class)); .bodyToMono(Pojo.class);
StepVerifier.create(result) StepVerifier.create(result)
.consumeNextWith(p -> assertEquals("BARBAR", p.getBar())) .consumeNextWith(p -> assertEquals("BARBAR", p.getBar()))
@ -331,8 +331,8 @@ public class WebClientIntegrationTests {
Mono<String> result = this.webClient.get() Mono<String> result = this.webClient.get()
.uri("/test") .uri("/test")
.cookie("testkey", "testvalue") .cookie("testkey", "testvalue")
.exchange() .retrieve()
.flatMap(response -> response.bodyToMono(String.class)); .bodyToMono(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("test") .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
Flux<String> result = this.webClient.get() Flux<String> result = this.webClient.get()
.uri("/string") .uri("/string")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.body(toFlux(String.class))); .bodyToFlux(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("foo 0") .expectNext("foo 0")
@ -78,8 +78,8 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
Flux<Person> result = this.webClient.get() Flux<Person> result = this.webClient.get()
.uri("/person") .uri("/person")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.body(toFlux(Person.class))); .bodyToFlux(Person.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext(new Person("foo 0")) .expectNext(new Person("foo 0"))
@ -93,9 +93,8 @@ public class SseHandlerFunctionIntegrationTests extends AbstractRouterFunctionIn
Flux<ServerSentEvent<String>> result = this.webClient.get() Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event") .uri("/event")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.body(toFlux( .bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
StepVerifier.create(result) StepVerifier.create(result)
.consumeNextWith( event -> { .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
Flux<Person> result = this.webClient.get() Flux<Person> result = this.webClient.get()
.uri("/stream") .uri("/stream")
.accept(APPLICATION_STREAM_JSON) .accept(APPLICATION_STREAM_JSON)
.exchange() .retrieve()
.flatMapMany(response -> response.bodyToFlux(Person.class)); .bodyToFlux(Person.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext(new Person("foo 0")) .expectNext(new Person("foo 0"))
@ -85,8 +85,8 @@ public class JacksonStreamingIntegrationTests extends AbstractHttpHandlerIntegra
Flux<Person> result = this.webClient.get() Flux<Person> result = this.webClient.get()
.uri("/stream") .uri("/stream")
.accept(new MediaType("application", "stream+x-jackson-smile")) .accept(new MediaType("application", "stream+x-jackson-smile"))
.exchange() .retrieve()
.flatMapMany(response -> response.bodyToFlux(Person.class)); .bodyToFlux(Person.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext(new Person("foo 0")) .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;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.junit.Assume.*; import static org.junit.Assume.*;
import static org.springframework.http.MediaType.*; import static org.springframework.http.MediaType.*;
import static org.springframework.web.reactive.function.BodyExtractors.*;
/** /**
* @author Sebastien Deleuze * @author Sebastien Deleuze
@ -77,8 +76,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<String> result = this.webClient.get() Flux<String> result = this.webClient.get()
.uri("/string") .uri("/string")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.bodyToFlux(String.class)); .bodyToFlux(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("foo 0") .expectNext("foo 0")
@ -92,8 +91,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<Person> result = this.webClient.get() Flux<Person> result = this.webClient.get()
.uri("/person") .uri("/person")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.bodyToFlux(Person.class)); .bodyToFlux(Person.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext(new Person("foo 0")) .expectNext(new Person("foo 0"))
@ -107,9 +106,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<ServerSentEvent<String>> result = this.webClient.get() Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event") .uri("/event")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.body( .bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
StepVerifier.create(result) StepVerifier.create(result)
.consumeNextWith( event -> { .consumeNextWith( event -> {
@ -135,9 +133,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<ServerSentEvent<String>> result = this.webClient.get() Flux<ServerSentEvent<String>> result = this.webClient.get()
.uri("/event") .uri("/event")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.body( .bodyToFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {});
toFlux(new ParameterizedTypeReference<ServerSentEvent<String>>() {})));
StepVerifier.create(result) StepVerifier.create(result)
.consumeNextWith( event -> { .consumeNextWith( event -> {
@ -167,8 +164,8 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
Flux<String> result = this.webClient.get() Flux<String> result = this.webClient.get()
.uri("/infinite") .uri("/infinite")
.accept(TEXT_EVENT_STREAM) .accept(TEXT_EVENT_STREAM)
.exchange() .retrieve()
.flatMapMany(response -> response.bodyToFlux(String.class)); .bodyToFlux(String.class);
StepVerifier.create(result) StepVerifier.create(result)
.expectNext("foo 0") .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
.uri("http://localhost:" + this.port + "/") .uri("http://localhost:" + this.port + "/")
.exchange(); .exchange();
StepVerifier StepVerifier.create(result)
.create(result)
.consumeNextWith(response -> { .consumeNextWith(response -> {
assertEquals(HttpStatus.OK, response.statusCode()); assertEquals(HttpStatus.OK, response.statusCode());
assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage()); assertEquals(Locale.GERMANY, response.headers().asHttpHeaders().getContentLanguage());

Loading…
Cancel
Save