changeset 466:c4a6145d16ea

Added test for proben kommentar service.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 17 Feb 2015 13:44:19 +0100
parents 72e63977aa60
children e147de48162a
files src/test/java/de/intevation/lada/test/GetTests.java
diffstat 1 files changed, 83 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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);
+    }
+
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)