1 package de.juplo.facebook.errors;
4 import de.juplo.facebook.errors.GraphApiException.Type;
5 import java.time.Duration;
6 import okhttp3.mockwebserver.MockResponse;
7 import okhttp3.mockwebserver.MockWebServer;
8 import org.junit.After;
9 import static org.junit.Assert.assertEquals;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.junit.runners.Parameterized;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16 import org.springframework.http.client.reactive.ClientHttpConnector;
17 import org.springframework.http.client.reactive.JettyClientHttpConnector;
18 import org.springframework.http.client.reactive.ReactorClientHttpConnector;
19 import org.springframework.web.reactive.function.client.WebClient;
20 import reactor.core.publisher.Mono;
21 import reactor.test.StepVerifier;
28 @RunWith(Parameterized.class)
29 public class GraphApiExchangeFilterFunctionIntegrationTest
31 private static final Logger LOG =
32 LoggerFactory.getLogger(GraphApiExchangeFilterFunctionIntegrationTest.class);
34 private MockWebServer server;
35 private WebClient webClient;
37 @Parameterized.Parameter(0)
38 public ClientHttpConnector connector;
40 @Parameterized.Parameters(name = "webClient [{0}]")
41 public static Object[][] arguments()
45 { new JettyClientHttpConnector() },
46 { new ReactorClientHttpConnector() }
54 server = new MockWebServer();
58 .clientConnector(this.connector)
59 .baseUrl(server.url("/").toString())
60 .filter(GraphApiExchangeFilterFunction.INSTANCE)
65 public void shutdown() throws Exception
67 this.server.shutdown();
72 public void testValidError()
74 LOG.info("testValidError");
78 .enqueue(new MockResponse()
80 .setHeader("Content-Type", "application/json")
85 " \"message\": \"(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.\",\n" +
86 " \"type\": \"OAuthException\",\n" +
97 .bodyToMono(String.class);
101 .expectErrorSatisfies(throwable ->
103 assertEquals(RateLimitExceededException.class, throwable.getClass());
104 RateLimitExceededException e = (RateLimitExceededException)throwable;
105 LOG.debug("{}", e.toString());
106 assertEquals(new Integer(613), e.getCode());
107 assertEquals("(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.", e.getMessage());
108 assertEquals(Type.OAuthException, e.getType());
110 .verify(Duration.ofSeconds(3));