From e3cbe5e272845110ebe7862bcb35bc9999c416fe Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 21 Nov 2019 13:55:46 +0100 Subject: [PATCH] WIP: TMP - WebClient --- ...ExchangeFilterFunctionIntegrationTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java index 2c94a49..a10066b 100644 --- a/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java +++ b/src/test/java/de/juplo/facebook/errors/GraphApiExchangeFilterFunctionIntegrationTest.java @@ -3,6 +3,7 @@ package de.juplo.facebook.errors; import de.juplo.facebook.errors.GraphApiException.Type; import java.time.Duration; +import java.util.List; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import org.junit.After; @@ -13,6 +14,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.http.client.reactive.JettyClientHttpConnector; +import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -89,4 +91,36 @@ public class GraphApiExchangeFilterFunctionIntegrationTest }) .verify(Duration.ofSeconds(3)); } + + @Test + public void testTest() + { + WebClient webClient = + WebClient + .builder() + .clientConnector(new JettyClientHttpConnector()) + .baseUrl(server.url("/").toString()) + .filter(ExchangeFilterFunction.ofResponseProcessor(response -> + { + List headerValues = response.headers().header("Foo"); + return headerValues.isEmpty() ? Mono.error( + new Exception("Response does not contain Foo header")) : + Mono.just(response); + })) + .build(); + + server + .enqueue(new MockResponse() + .setHeader("Content-Type", "text/plain") + .setBody("Hello Spring!")); + + Mono result = webClient.get() + .uri("/greeting?name=Spring") + .retrieve() + .bodyToMono(String.class); + + StepVerifier.create(result) + .expectError(Exception.class) + .verify(Duration.ofSeconds(3)); + } } -- 2.20.1