changeset 973:4b5f5e253cab

Make tests more verbose on failure.
author Tom Gottfried <tom@intevation.de>
date Tue, 07 Jun 2016 16:20:18 +0200
parents 2f816d251a0d
children 6ab55e59cfae
files src/test/java/de/intevation/lada/test/ServiceTest.java src/test/java/de/intevation/lada/test/stamm/Stammdaten.java
diffstat 2 files changed, 66 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/java/de/intevation/lada/test/ServiceTest.java	Tue Jun 07 12:12:28 2016 +0200
+++ b/src/test/java/de/intevation/lada/test/ServiceTest.java	Tue Jun 07 16:20:18 2016 +0200
@@ -106,7 +106,8 @@
             JsonReader reader = Json.createReader(new StringReader(entity));
             JsonObject content = reader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n" + content,
+                content.getBoolean("success"));
             prot.addInfo("success", content.getBoolean("success"));
             Assert.assertEquals("200", content.getString("message"));
             prot.addInfo("message", content.getString("message"));
@@ -117,7 +118,8 @@
         }
         catch(JsonException je) {
             prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
+            Assert.fail("Exception while parsing '" + entity + "':\n"
+                + je.getMessage());
         }
         return null;
     }
@@ -137,23 +139,24 @@
         prot.setType("get by Id");
         prot.setPassed(false);
         protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target(baseUrl + parameter);
+        prot.addInfo("parameter", parameter);
+        /* Request a object by id*/
+        Response response = target.request()
+            .header("X-SHIB-user", BaseTest.TEST_USER)
+            .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+            .get();
+        String entity = response.readEntity(String.class);
         try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target = client.target(baseUrl + parameter);
-            prot.addInfo("parameter", parameter);
-            /* Request a object by id*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .get();
-            String entity = response.readEntity(String.class);
             /* Try to parse the response*/
             JsonReader fromServiceReader =
                 Json.createReader(new StringReader(entity));
             JsonObject content = fromServiceReader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n" + content,
+                content.getBoolean("success"));
             prot.addInfo("success", content.getBoolean("success"));
             Assert.assertEquals("200", content.getString("message"));
             prot.addInfo("message", content.getString("message"));
@@ -172,7 +175,8 @@
         }
         catch(JsonException je) {
             prot.addInfo("exception",je.getMessage());
-            Assert.fail(je.getMessage());
+            Assert.fail("Exception while parsing '" + entity + "':\n"
+                + je.getMessage());
         }
         return null;
     }
@@ -189,23 +193,24 @@
         prot.setType("filter");
         prot.setPassed(false);
         protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target =
+            client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24");
+        prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24");
+        /* Request the objects using the filter*/
+        Response response = target.request()
+            .header("X-SHIB-user", BaseTest.TEST_USER)
+            .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+            .get();
+        String entity = response.readEntity(String.class);
         try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target =
-                client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24");
-            prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24");
-            /* Request the objects using the filter*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .get();
-            String entity = response.readEntity(String.class);
             /* Try to parse the response*/
             JsonReader reader = Json.createReader(new StringReader(entity));
             JsonObject content = reader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n" + content,
+                content.getBoolean("success"));
             prot.addInfo("success", content.getBoolean("success"));
             Assert.assertEquals("200", content.getString("message"));
             prot.addInfo("message", content.getString("message"));
@@ -216,7 +221,8 @@
         }
         catch(JsonException je) {
             prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
+            Assert.fail("Exception while parsing '" + entity + "':\n"
+                + je.getMessage());
         }
         return null;
     }
@@ -233,22 +239,23 @@
         prot.setType("create");
         prot.setPassed(false);
         protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target(baseUrl + parameter);
+        /* Send a post request containing a new probe*/
+        Response response = target.request()
+            .header("X-SHIB-user", BaseTest.TEST_USER)
+            .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+            .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON));
+        String entity = response.readEntity(String.class);
         try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target = client.target(baseUrl + parameter);
-            /* Send a post request containing a new probe*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON));
-            String entity = response.readEntity(String.class);
             /* Try to parse the response*/
             JsonReader fromServiceReader =
                 Json.createReader(new StringReader(entity));
             JsonObject content = fromServiceReader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n" + content,
+                content.getBoolean("success"));
             prot.addInfo("success", content.getBoolean("success"));
             Assert.assertEquals("200", content.getString("message"));
             prot.addInfo("message", content.getString("message"));
@@ -257,7 +264,8 @@
         }
         catch(JsonException je) {
             prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
+            Assert.fail("Exception while parsing '" + entity + "':\n"
+                + je.getMessage());
         }
         return null;
     }
@@ -310,7 +318,9 @@
                 new StringReader(updated.readEntity(String.class)));
             JsonObject updatedObject = updatedReader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(updatedObject.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n"
+                + updatedObject,
+                updatedObject.getBoolean("success"));
             prot.addInfo("success", updatedObject.getBoolean("success"));
             Assert.assertEquals("200", updatedObject.getString("message"));
             prot.addInfo("message", updatedObject.getString("message"));
@@ -338,23 +348,24 @@
         prot.setType("delete");
         prot.setPassed(false);
         protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target =
+            client.target(baseUrl + parameter);
+        prot.addInfo("parameter", parameter);
+        /* Delete a probe with the id saved when created a probe*/
+        Response response = target.request()
+            .header("X-SHIB-user", BaseTest.TEST_USER)
+            .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+            .delete();
+        String entity = response.readEntity(String.class);
         try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target =
-                client.target(baseUrl + parameter);
-            prot.addInfo("parameter", parameter);
-            /* Delete a probe with the id saved when created a probe*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .delete();
-            String entity = response.readEntity(String.class);
             /* Try to parse the response*/
             JsonReader reader = Json.createReader(new StringReader(entity));
             JsonObject content = reader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n" + content,
+                content.getBoolean("success"));
             prot.addInfo("success", content.getBoolean("success"));
             Assert.assertEquals("200", content.getString("message"));
             prot.addInfo("message", content.getString("message"));
@@ -363,7 +374,8 @@
         }
         catch(JsonException je) {
             prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
+            Assert.fail("Exception while parsing '" + entity + "':\n"
+                + je.getMessage());
         }
         return null;
     }
--- a/src/test/java/de/intevation/lada/test/stamm/Stammdaten.java	Tue Jun 07 12:12:28 2016 +0200
+++ b/src/test/java/de/intevation/lada/test/stamm/Stammdaten.java	Tue Jun 07 16:20:18 2016 +0200
@@ -256,7 +256,8 @@
                 Json.createReader(new StringReader(entity));
             JsonObject content = fromServiceReader.readObject();
             /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertTrue("Unsuccessful response object:\n" + content,
+                content.getBoolean("success"));
             prot.addInfo("success", content.getBoolean("success"));
             Assert.assertEquals("200", content.getString("message"));
             prot.addInfo("message", content.getString("message"));
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)