[Lada-commits] [PATCH 5 of 5] Added test for proben kommentar service

Wald Commits scm-commit at wald.intevation.org
Tue Feb 17 13:43:54 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1424177059 -3600
# Node ID c4a6145d16ea05f87f82eb64a2038c3552fbd682
# Parent  72e63977aa60caeeb96e80ef07f404988b400930
Added test for proben kommentar service.

diff -r 72e63977aa60 -r c4a6145d16ea src/test/java/de/intevation/lada/test/GetTests.java
--- a/src/test/java/de/intevation/lada/test/GetTests.java	Tue Feb 17 13:43:46 2015 +0100
+++ b/src/test/java/de/intevation/lada/test/GetTests.java	Tue Feb 17 13:44:19 2015 +0100
@@ -363,4 +363,87 @@
         prot.setPassed(true);
     }
 
+    /**
+     * Test the GET Service by requesting all KommentarP objects.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    private final void pkommentarGetAllService(URL baseUrl)
+    throws Exception {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("ProbeKommentarService");
+        prot.setType("get all");
+        prot.setPassed(false);
+        protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target(baseUrl + "pkommentar");
+        /* Request all probe objects*/
+        Response response = target.request().get();
+        String entity = response.readEntity(String.class);
+        try{
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject content = reader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            Assert.assertNotNull(content.getJsonArray("data"));
+            prot.addInfo("objects", content.getJsonArray("data").size());
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        prot.setPassed(true);
+    }
+
+    /**
+     * Test the GET Service by requesting a single KommentarP object by id.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    private final void pkommentarGetByIdService(URL baseUrl)
+    throws Exception {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("ProbeKommentarService");
+        prot.setType("get by Id");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a json object from static messung string*/
+            JsonReader fromStringRreader =
+                Json.createReader(new StringReader(COMPARE_KOMMENTARP));
+            JsonObject staticKommentar = fromStringRreader.readObject();
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target = client.target(baseUrl + "pkommentar/1");
+            prot.addInfo("kommentarId", 1);
+            /* Request a probe object by id*/
+            Response response = target.request().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"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            Assert.assertEquals(staticKommentar,
+                content.getJsonObject("data"));
+            prot.addInfo("object", "equals");
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        prot.setPassed(true);
+    }
+
 }


More information about the Lada-commits mailing list