Clearified intend in GraphApiErrorResponseErrorHandlerIntegrationTest
[facebook-errors] / src / test / java / de / juplo / facebook / errors / GraphApiErrorResponseErrorHandlerIntegrationTest.java
index 6593375..81bcfe6 100644 (file)
@@ -10,6 +10,7 @@ import org.slf4j.Logger;
 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;
 
 
@@ -30,21 +31,14 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
   @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)
     {
@@ -55,7 +49,8 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     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)
     {
@@ -66,7 +61,24 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     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)
     {
@@ -77,7 +89,12 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     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)
     {
@@ -89,9 +106,6 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
   @Test
   public void testValidError()
   {
-    LOG.info("testValidError");
-
-
     requestFactory.setBody(
         "{\n" +
         "  \"error\":\n" +
@@ -104,7 +118,7 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
 
     try
     {
-      clientTemplate.getForObject("ANY", SOME.class);
+      clientTemplate.getForObject("ANY", String.class);
       fail("The expected exception was not thrown");
     }
     catch(RateLimitExceededException e)
@@ -119,9 +133,6 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
   @Test
   public void testUnmappedError()
   {
-    LOG.info("testUnmappedError");
-
-
     requestFactory.setBody(
         "{\n" +
         "  \"error\":\n" +
@@ -134,7 +145,7 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
 
     try
     {
-      clientTemplate.getForObject("ANY", SOME.class);
+      clientTemplate.getForObject("ANY", String.class);
       fail("The expected exception was not thrown");
     }
     catch(GraphApiException e)
@@ -155,9 +166,6 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
   @Test
   public void testInvlalidError()
   {
-    LOG.info("testInvalidError");
-
-
     requestFactory.setBody(
         "{\n" +
         "  \"error\":\n" +
@@ -170,7 +178,7 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
 
     try
     {
-      clientTemplate.getForObject("ANY", SOME.class);
+      clientTemplate.getForObject("ANY", String.class);
       fail("The expected exception was not thrown");
     }
     catch(HttpClientErrorException e)
@@ -197,9 +205,4 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
         new GraphApiErrorResponseErrorHandler(clientTemplate.getErrorHandler())
         );
   }
-
-
-  static class SOME
-  {
-  }
 }