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.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14 import org.springframework.http.HttpStatus;
15 import org.springframework.http.client.reactive.JettyClientHttpConnector;
16 import org.springframework.web.reactive.function.client.WebClient;
17 import reactor.core.publisher.Mono;
18 import reactor.test.StepVerifier;
25 public class GraphApiExchangeFilterFunctionIntegrationTest
27 private static final Logger LOG =
28 LoggerFactory.getLogger(GraphApiExchangeFilterFunctionIntegrationTest.class);
30 private MockWebServer server;
31 private WebClient webClient;
37 server = new MockWebServer();
41 .clientConnector(new JettyClientHttpConnector())
42 .baseUrl(server.url("/").toString())
43 .filter(GraphApiExchangeFilterFunction.INSTANCE)
48 public void shutdown() throws Exception
50 this.server.shutdown();
55 public void testValidError()
58 .enqueue(new MockResponse()
59 .setResponseCode(HttpStatus.BAD_REQUEST.value())
60 .setHeader("Content-Type", "application/json")
65 " \"message\": \"(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.\",\n" +
66 " \"type\": \"OAuthException\",\n" +
77 .bodyToMono(String.class);
81 .expectErrorSatisfies(throwable ->
83 assertEquals(RateLimitExceededException.class, throwable.getClass());
84 RateLimitExceededException e = (RateLimitExceededException)throwable;
85 LOG.debug("{}", e.toString());
86 assertEquals(new Integer(613), e.getCode());
87 assertEquals("(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.", e.getMessage());
88 assertEquals(Type.OAuthException, e.getType());
90 .verify(Duration.ofSeconds(3));