X-Git-Url: https://juplo.de/gitweb/?p=facebook-utils;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Ffacebook%2FGraphApiErrorHandlerTest.java;h=ef849cfb5362b3ae21dae54f85b5e0abc82ef24b;hp=d93121bfa0041390551e59e2feb86144ed6172c0;hb=c1c281d582d47643a1615a6525c4189d9788b9fc;hpb=450cc98b6aee21b0c7d9181a1a79437d558366c9 diff --git a/src/test/java/de/juplo/facebook/GraphApiErrorHandlerTest.java b/src/test/java/de/juplo/facebook/GraphApiErrorHandlerTest.java index d93121b..ef849cf 100644 --- a/src/test/java/de/juplo/facebook/GraphApiErrorHandlerTest.java +++ b/src/test/java/de/juplo/facebook/GraphApiErrorHandlerTest.java @@ -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; @@ -256,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()); } @@ -278,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()); } @@ -301,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()); } @@ -323,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()); } @@ -346,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()); } @@ -369,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()); } @@ -392,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()); } @@ -414,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()); } @@ -429,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()); } @@ -444,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()); } @@ -459,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()); } @@ -474,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()); } @@ -489,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()); } @@ -504,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()); } @@ -519,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()); } @@ -534,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()); } @@ -549,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()); + } }