X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Ffacebook%2Fclient%2FGraphApiErrorHandlerTest.java;h=0c900b3128c9eee47852023343152c94f593dd8b;hb=5db7dd6aafb490a8a7cbdf3e1adf3066e11f96f5;hp=f0c26e9442eac20802912f7af85d90ff1680e88a;hpb=e90955777d96c9aa0f7f6827d13bbaae87075f06;p=facebook-utils diff --git a/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java b/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java index f0c26e9..0c900b3 100644 --- a/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/client/GraphApiErrorHandlerTest.java @@ -6,9 +6,11 @@ import de.juplo.facebook.exceptions.UnsupportedGetRequestException; import de.juplo.facebook.exceptions.UnexpectedErrorException; import de.juplo.facebook.exceptions.RateExceededException; import de.juplo.facebook.exceptions.GraphApiException; +import de.juplo.facebook.exceptions.GraphApiException.Type; import de.juplo.facebook.exceptions.UnknownErrorException; import de.juplo.facebook.exceptions.PageMigratedException; import de.juplo.facebook.exceptions.UnmappedErrorException; +import de.juplo.facebook.exceptions.UserAccessTokenRequiredException; import java.util.Date; import java.util.Map; import java.util.Set; @@ -84,7 +86,7 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(1), e.getCode()); assertEquals("An unknown error has occurred.", e.getMessage()); - assertEquals("OAuthException", e.getType()); + assertEquals(Type.OAuthException, e.getType()); } } @@ -115,7 +117,7 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(2), e.getCode()); assertEquals("An unexpected error has occurred. Please retry your request later.", e.getMessage()); - assertEquals("OAuthException", e.getType()); + assertEquals(Type.OAuthException, e.getType()); } } @@ -146,7 +148,7 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(21), e.getCode()); assertEquals("(#21) Page ID 590408587650316 was migrated to page ID 1421620791415603. Please update your API calls to the new ID", e.getMessage()); - assertEquals("OAuthException", e.getType()); + assertEquals(Type.OAuthException, e.getType()); } } @@ -177,7 +179,30 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(100), e.getCode()); assertEquals("Unsupported get request.", e.getMessage()); - assertEquals("GraphMethodException", e.getType()); + assertEquals(Type.GraphMethodException, e.getType()); + } + } + + @Test + public void testError102() + { + log.info("testError102"); + + requestFactory.setBody("{\"error\":{\"message\":\"A user access token is required to request this resource.\",\"type\":\"OAuthException\",\"code\":102,\"fbtrace_id\":\"DhdMyf23Ki7\"}}"); + + try + { + clientTemplate.getForObject("ANY", SOME.class); + fail("The expected exception was not thrown"); + } + catch(UserAccessTokenRequiredException e) + { + log.debug("{}", e.toString()); + assertEquals("invalid_request", e.getOAuth2ErrorCode()); + assertEquals(new Integer(102), e.getCode()); + assertEquals("A user access token is required to request this resource.", e.getMessage()); + assertEquals(Type.OAuthException, e.getType()); + assertEquals("DhdMyf23Ki7", e.getTraceId()); } } @@ -199,7 +224,7 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(104), e.getCode()); assertEquals("An access token is required to request this resource.", e.getMessage()); - assertEquals("OAuthException", e.getType()); + assertEquals(Type.OAuthException, e.getType()); assertEquals("E2Jjkj5++LL", e.getTraceId()); } } @@ -231,7 +256,7 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(613), e.getCode()); assertEquals("(#613) Calls to stream have exceeded the rate of 600 calls per 600 seconds.", e.getMessage()); - assertEquals("OAuthException", e.getType()); + assertEquals(Type.OAuthException, e.getType()); } } @@ -267,7 +292,7 @@ public class GraphApiErrorHandlerTest " \"error\":\n" + " {\n" + " \"message\": \"This error does not exist.\",\n" + - " \"type\": \"NonexistentException\",\n" + + " \"type\": \"NonexistentTypeException\",\n" + " \"code\": 999999999\n" + " }\n" + "}"); @@ -283,7 +308,13 @@ public class GraphApiErrorHandlerTest assertEquals("invalid_request", e.getOAuth2ErrorCode()); assertEquals(new Integer(999999999), e.getCode()); assertEquals("This error does not exist.", e.getMessage()); - assertEquals("NonexistentException", e.getType()); + try + { + Type type = e.getType(); + log.error("unknown type: {}", type); + fail("unmapped type was resolved by enum: " + type); + } + catch (IllegalArgumentException ee) {} } } @@ -298,7 +329,7 @@ public class GraphApiErrorHandlerTest " \"error\":\n" + " {\n" + " \"message\": null,\n" + - " \"type\": \"Whatever\",\n" + + " \"type\": \"WhateverTypeException\",\n" + " \"code\": 999999999\n" + " }\n" + "}"); @@ -312,7 +343,13 @@ public class GraphApiErrorHandlerTest { log.debug("{}", e.toString()); assertNull(e.getMessage()); - assertEquals("Whatever", e.getType()); + try + { + Type type = e.getType(); + log.error("unknown type: {}", type); + fail("unmapped type was resolved by enum: " + type); + } + catch (IllegalArgumentException ee) {} assertEquals(new Integer(999999999), e.getCode()); assertNull(e.getSubCode()); assertNull(e.getUserTitle()); @@ -329,7 +366,7 @@ public class GraphApiErrorHandlerTest "{\n" + " \"error\":\n" + " {\n" + - " \"type\": \"Whatever\",\n" + + " \"type\": \"WhateverTypeException\",\n" + " \"code\": 999999999\n" + " }\n" + "}"); @@ -343,7 +380,13 @@ public class GraphApiErrorHandlerTest { log.debug("{}", e.toString()); assertNull(e.getMessage()); - assertEquals("Whatever", e.getType()); + try + { + Type type = e.getType(); + log.error("unknown type: {}", type); + fail("unmapped type was resolved by enum: " + type); + } + catch (IllegalArgumentException ee) {} assertEquals(new Integer(999999999), e.getCode()); assertNull(e.getSubCode()); assertNull(e.getUserTitle());