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;
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;
}
}
+ @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()
{
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
}
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());
+ }
}