WIP: Clearified intend...
authorKai Moritz <kai@jupl.de>
Thu, 21 Nov 2019 21:24:12 +0000 (22:24 +0100)
committerKai Moritz <kai@jupl.de>
Thu, 21 Nov 2019 21:24:12 +0000 (22:24 +0100)
src/test/java/de/juplo/facebook/errors/GraphApiErrorResponseErrorHandlerIntegrationTest.java

index 9f70b35..28b6f4f 100644 (file)
@@ -51,34 +51,34 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
   @Test
   public void testNoError()
   {
-    server
-        .enqueue(new MockResponse()
-            .setResponseCode(HttpStatus.CONTINUE.value())
-            .setHeader("Content-Type", "application/json")
-            .setBody("{ \"message\": \"Hello World!\" }"));
-
-    try
-    {
-      SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
-      assertEquals("Hello World!", result.message);
-    }
-    catch(Exception e)
-    {
-      LOG.debug("{}", e.toString());
-      fail("Unexpected error: " + e);
-    }
+    //server
+    //    .enqueue(new MockResponse()
+    //        .setResponseCode(HttpStatus.CONTINUE.value())
+    //        .setHeader("Content-Type", "application/json")
+    //        .setBody("Hallo Welt!"));
+    //
+    //try
+    //{
+    //  String result = clientTemplate.getForObject(uri, String.class);
+    //  assertEquals("Hallo Welt!", result);
+    //}
+    //catch(Exception e)
+    //{
+    //  LOG.debug("{}", e.toString());
+    //  fail("Unexpected error: " + e);
+    //}
 
 
     server
         .enqueue(new MockResponse()
             .setResponseCode(HttpStatus.OK.value())
-            .setHeader("Content-Type", "application/json")
-            .setBody("{ \"message\": \"Hello World!\" }"));
+            .setHeader("Content-Type", "text/plain")
+            .setBody("Hallo Welt!"));
 
     try
     {
-      SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
-      assertEquals("Hello World!", result.message);
+      String result = clientTemplate.getForObject(uri, String.class);
+      assertEquals("Hallo Welt!", result);
     }
     catch(Exception e)
     {
@@ -90,13 +90,13 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     server
         .enqueue(new MockResponse()
             .setResponseCode(HttpStatus.TEMPORARY_REDIRECT.value())
-            .setHeader("Content-Type", "application/json")
-            .setBody("{ \"message\": \"Hello World!\" }"));
+            .setHeader("Content-Type", "text/plain")
+            .setBody("Hallo Welt!"));
 
     try
     {
-      SimpleMessage result = clientTemplate.getForObject(uri, SimpleMessage.class);
-      assertEquals("Hello World!", result.message);
+      String result = clientTemplate.getForObject(uri, String.class);
+      assertEquals("Hallo Welt!", result);
     }
     catch(Exception e)
     {
@@ -108,12 +108,12 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     server
         .enqueue(new MockResponse()
             .setResponseCode(HttpStatus.BAD_REQUEST.value())
-            .setHeader("Content-Type", "application/json")
-            .setBody("{ \"message\": \"Hello World!\" }"));
+            .setHeader("Content-Type", "text/plain")
+            .setBody("Hallo Welt!"));
 
     try
     {
-      clientTemplate.getForObject(uri, SimpleMessage.class);
+      clientTemplate.getForObject(uri, String.class);
       fail("The parent handler should have raised an exception!");
     }
     catch(HttpClientErrorException e)
@@ -130,12 +130,12 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     server
         .enqueue(new MockResponse()
             .setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
-            .setHeader("Content-Type", "application/json")
-            .setBody("{ \"message\": \"Hello World!\" }"));
+            .setHeader("Content-Type", "text/plain")
+            .setBody("Hallo Welt!"));
 
     try
     {
-      clientTemplate.getForObject(uri, SimpleMessage.class);
+      clientTemplate.getForObject(uri, String.class);
       fail("The parent handler should have raised an exception!");
     }
     catch(HttpServerErrorException e)
@@ -168,7 +168,7 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
 
     try
     {
-      clientTemplate.getForObject(uri, SimpleMessage.class);
+      clientTemplate.getForObject(uri, String.class);
       fail("The expected exception was not thrown");
     }
     catch(RateLimitExceededException e)
@@ -188,18 +188,18 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
             .setResponseCode(HttpStatus.BAD_REQUEST.value())
             .setHeader("Content-Type", "application/json")
             .setBody(
-        "{\n" +
-        "  \"error\":\n" +
-        "  {\n" +
-        "    \"message\": \"This error does not exist.\",\n" +
-        "    \"type\": \"NonexistentTypeException\",\n" +
-        "    \"code\": 999999999\n" +
-        "  }\n" +
-        "}"));
+                "{\n" +
+                "  \"error\":\n" +
+                "  {\n" +
+                "    \"message\": \"This error does not exist.\",\n" +
+                "    \"type\": \"NonexistentTypeException\",\n" +
+                "    \"code\": 999999999\n" +
+                "  }\n" +
+                "}"));
 
     try
     {
-      clientTemplate.getForObject(uri, SimpleMessage.class);
+      clientTemplate.getForObject(uri, String.class);
       fail("The expected exception was not thrown");
     }
     catch(GraphApiException e)
@@ -225,18 +225,18 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
             .setResponseCode(HttpStatus.BAD_REQUEST.value())
             .setHeader("Content-Type", "application/json")
             .setBody(
-        "{\n" +
-        "  \"error\":\n" +
-        "  {\n" +
-        "    \"message\": \"Not a Graph-Api-Exception.\",\n" +
-        "    \"type\": \"Whatever\",\n" +
-        "    \"code\": \"some string\"\n" +
-        "  }\n" +
-        "}"));
+                "{\n" +
+                "  \"error\":\n" +
+                "  {\n" +
+                "    \"message\": \"Not a Graph-Api-Exception.\",\n" +
+                "    \"type\": \"Whatever\",\n" +
+                "    \"code\": \"some string\"\n" +
+                "  }\n" +
+                "}"));
 
     try
     {
-      clientTemplate.getForObject(uri, SimpleMessage.class);
+      clientTemplate.getForObject(uri, String.class);
       fail("The expected exception was not thrown");
     }
     catch(HttpClientErrorException e)
@@ -247,11 +247,26 @@ public class GraphApiErrorResponseErrorHandlerIntegrationTest
     {
       fail("A wrong exception was thrown: " + e.toString());
     }
-  }
 
 
-  static class SimpleMessage
-  {
-    String message;
+    server
+        .enqueue(new MockResponse()
+            .setResponseCode(HttpStatus.BAD_REQUEST.value())
+            .setHeader("Content-Type", "text/plain")
+            .setBody("Hallo Welt!"));
+
+    try
+    {
+      clientTemplate.getForObject(uri, String.class);
+      fail("The expected exception was not thrown");
+    }
+    catch(HttpClientErrorException e)
+    {
+      LOG.debug("{}", e.toString());
+    }
+    catch(Exception e)
+    {
+      fail("A wrong exception was thrown: " + e.toString());
+    }
   }
 }