--- /dev/null
+package de.juplo.facebook.errors;
+
+
+import java.time.Duration;
+import java.util.List;
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
+import org.springframework.web.reactive.function.client.WebClient;
+import reactor.core.publisher.Mono;
+
+
+/**
+ *
+ * @author Kai Moritz
+ */
+public class GraphApiExchangeFilterFunctionIntegrationTest
+{
+ private MockWebServer server;
+
+ private WebClient webClient;
+
+
+ @Before
+ public void setup() {
+ this.server = new MockWebServer();
+ String baseUrl = this.server.url("/").toString();
+ this.webClient = WebClient.create(baseUrl);
+ }
+
+ @After
+ public void shutdown() throws Exception {
+ this.server.shutdown();
+ }
+
+
+ @Test
+ public void errorHandlingFilter() throws Exception
+ {
+
+ ExchangeFilterFunction filter = ExchangeFilterFunction.ofResponseProcessor(
+ clientResponse ->
+ {
+ List<String> headerValues = clientResponse.headers().header("Foo");
+ return headerValues.isEmpty() ? Mono.error(
+ new MyException("Response does not contain Foo header")) : Mono.just(
+ clientResponse);
+ }
+ );
+
+ WebClient filteredClient = this.webClient.filter(filter);
+
+ // header not present
+ this.server.enqueue(new MockResponse().setHeader("Content-Type",
+ "text/plain").setBody("Hello Spring!"));
+
+ Mono<String> result = filteredClient.get()
+ .uri("/greeting?name=Spring")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier.create(result)
+ .expectError(MyException.class)
+ .verify(Duration.ofSeconds(3));
+
+ // header present
+ this.server.enqueue(new MockResponse().setHeader("Content-Type",
+ "text/plain")
+ .setHeader("Foo", "Bar")
+ .setBody("Hello Spring!"));
+
+ result = filteredClient.get()
+ .uri("/greeting?name=Spring")
+ .retrieve()
+ .bodyToMono(String.class);
+
+ StepVerifier.create(result)
+ .expectNext("Hello Spring!")
+ .expectComplete()
+ .verify(Duration.ofSeconds(3));
+
+ Assert.assertEquals(2, server.getRequestCount());
+ }
+}