Upgraded all dependencies
[facebook-utils] / src / test / java / de / juplo / facebook / GraphApiErrorHandlerTest.java
index b9dc905..ef849cf 100644 (file)
@@ -11,7 +11,6 @@ import org.junit.runner.RunWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpStatus;
-import org.springframework.http.converter.HttpMessageNotReadableException;
 import org.springframework.security.access.AccessDeniedException;
 import org.springframework.security.oauth2.client.OAuth2RestTemplate;
 import org.springframework.security.oauth2.client.http.OAuth2ErrorHandler;
@@ -23,9 +22,9 @@ import org.springframework.security.oauth2.client.token.AccessTokenRequest;
 import org.springframework.security.oauth2.common.OAuth2AccessToken;
 import static org.springframework.security.oauth2.common.OAuth2AccessToken.OAUTH2_TYPE;
 import org.springframework.security.oauth2.common.OAuth2RefreshToken;
-import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.client.HttpClientErrorException;
 
 
 
@@ -173,6 +172,37 @@ public class GraphApiErrorHandlerTest
     }
   }
 
+  @Test
+  public void testError613()
+  {
+    log.info("testError613");
+
+
+    requestFactory.setBody(
+        "{\n" +
+        "  \"error\":\n" +
+        "  {\n" +
+        "    \"message\": \"(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.\",\n" +
+        "    \"type\": \"OAuthException\",\n" +
+        "    \"code\": 613\n" +
+        "  }\n" +
+        "}");
+
+    try
+    {
+      clientTemplate.getForObject("ANY", SOME.class);
+      fail("The expected exception was not thrown");
+    }
+    catch(RateExceededException e)
+    {
+      log.debug("{}", e.toString());
+      assertEquals("invalid_request", e.getOAuth2ErrorCode());
+      assertEquals(613, e.getCode());
+      assertEquals("(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.", e.getMessage());
+      assertEquals("OAuthException", e.getType());
+    }
+  }
+
   @Test
   public void testUnmappedError()
   {
@@ -225,11 +255,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -247,11 +279,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -270,11 +304,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -292,11 +328,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -315,11 +353,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -338,11 +378,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -361,11 +403,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -383,11 +427,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -398,11 +444,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -413,11 +461,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -428,11 +478,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -443,11 +495,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -458,11 +512,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -473,11 +529,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -488,11 +546,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -503,11 +563,13 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(OAuth2Exception e)
+    catch(HttpClientErrorException e)
     {
       log.debug("{}", e.toString());
-      assertEquals("invalid_request", e.getOAuth2ErrorCode());
-      assertFalse(e instanceof GraphApiException);
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
     }
 
 
@@ -518,11 +580,14 @@ public class GraphApiErrorHandlerTest
       clientTemplate.getForObject("ANY", SOME.class);
       fail("The expected exception was not thrown");
     }
-    catch(HttpMessageNotReadableException e)
+    catch(HttpClientErrorException e)
     {
-      // TODO: OAuth2ErrorHandler fails, if body contains no valid JSON!
       log.debug("{}", e.toString());
     }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
+    }
   }