import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;
@Test
public void testNoError()
{
- LOG.info("testNoError");
-
- requestFactory.setBody("{\n" +
- " \"error\": {\n" +
- " \"message\": \"(#200) The user hasn't authorized the application to perform this action\",\n" +
- " \"type\": \"OAuthException\",\n" +
- " \"code\": 200\n" +
- " }\n" +
- "}");
+ requestFactory.setBody("{ \"message\": \"Hello World!\" }");
requestFactory.setStatus(HttpStatus.CONTINUE);
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ String result = clientTemplate.getForObject("ANY", String.class);
+ assertEquals("{ \"message\": \"Hello World!\" }", result);
}
catch(Exception e)
{
requestFactory.setStatus(HttpStatus.OK);
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ String result = clientTemplate.getForObject("ANY", String.class);
+ assertEquals("{ \"message\": \"Hello World!\" }", result);
}
catch(Exception e)
{
requestFactory.setStatus(HttpStatus.TEMPORARY_REDIRECT);
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ String result = clientTemplate.getForObject("ANY", String.class);
+ assertEquals("{ \"message\": \"Hello World!\" }", result);
+ }
+ catch(Exception e)
+ {
+ LOG.debug("{}", e.toString());
+ fail("Unexpected error: " + e);
+ }
+
+ requestFactory.setStatus(HttpStatus.BAD_REQUEST);
+ try
+ {
+ clientTemplate.getForObject("ANY", String.class);
+ fail("The parent handler should have raised an exception!");
+ }
+ catch(HttpClientErrorException e)
+ {
+ LOG.debug("Expexted error: {}", e.toString());
}
catch(Exception e)
{
requestFactory.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ clientTemplate.getForObject("ANY", String.class);
+ fail("The parent handler should have raised an exception!");
+ }
+ catch(HttpServerErrorException e)
+ {
+ LOG.debug("Expexted error: {}", e.toString());
}
catch(Exception e)
{
@Test
public void testValidError()
{
- LOG.info("testValidError");
-
-
requestFactory.setBody(
"{\n" +
" \"error\":\n" +
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ clientTemplate.getForObject("ANY", String.class);
fail("The expected exception was not thrown");
}
catch(RateLimitExceededException e)
@Test
public void testUnmappedError()
{
- LOG.info("testUnmappedError");
-
-
requestFactory.setBody(
"{\n" +
" \"error\":\n" +
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ clientTemplate.getForObject("ANY", String.class);
fail("The expected exception was not thrown");
}
catch(GraphApiException e)
@Test
public void testInvlalidError()
{
- LOG.info("testInvalidError");
-
-
requestFactory.setBody(
"{\n" +
" \"error\":\n" +
try
{
- clientTemplate.getForObject("ANY", SOME.class);
+ clientTemplate.getForObject("ANY", String.class);
fail("The expected exception was not thrown");
}
catch(HttpClientErrorException e)
new GraphApiErrorResponseErrorHandler(clientTemplate.getErrorHandler())
);
}
-
-
- static class SOME
- {
- }
}