changeset 646:ac7f69201d4a

Added tests for messprogramm service.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 30 Apr 2015 17:28:19 +0200
parents 7088d3c1da29
children 4da01934e46f
files src/test/java/de/intevation/lada/LadaLandTest.java src/test/java/de/intevation/lada/test/land/Messprogramm.java
diffstat 2 files changed, 375 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/java/de/intevation/lada/LadaLandTest.java	Thu Apr 30 17:27:40 2015 +0200
+++ b/src/test/java/de/intevation/lada/LadaLandTest.java	Thu Apr 30 17:28:19 2015 +0200
@@ -23,6 +23,7 @@
 
 import de.intevation.lada.test.land.KommentarM;
 import de.intevation.lada.test.land.KommentarP;
+import de.intevation.lada.test.land.Messprogramm;
 import de.intevation.lada.test.land.Messung;
 import de.intevation.lada.test.land.Messwert;
 import de.intevation.lada.test.land.Ort;
@@ -52,6 +53,7 @@
     private Ort ortTest;
     private Status statusTest;
     private Zusatzwert zusatzwertTest;
+    private Messprogramm messprogrammTest;
 
     public LadaLandTest() {
         probeTest = new Probe();
@@ -63,6 +65,7 @@
         ortTest = new Ort();
         statusTest = new Status();
         zusatzwertTest = new Zusatzwert();
+        messprogrammTest = new Messprogramm();
         testProtocol = new ArrayList<Protocol>();
         verboseLogging = false;
     }
@@ -321,6 +324,37 @@
     throws Exception {
         this.zusatzwertTest.filterService(baseUrl, testProtocol);
     }
+
+    /**
+     * Testing GET Services.
+     */
+    @Test
+    @RunAsClient
+    public final void testA_MessprogrammGetAllServices(@ArquillianResource URL baseUrl)
+    throws Exception {
+        this.messprogrammTest.getAllService(baseUrl, testProtocol);
+    }
+
+    /**
+     * Testing GET Services.
+     */
+    @Test
+    @RunAsClient
+    public final void testA_MessprogrammGetByIdServices(@ArquillianResource URL baseUrl)
+    throws Exception {
+        this.messprogrammTest.getByIdService(baseUrl, testProtocol);
+    }
+
+    /**
+     * Testing GET Services.
+     */
+    @Test
+    @RunAsClient
+    public final void testA_MessprogrammGetFilterServices(@ArquillianResource URL baseUrl)
+    throws Exception {
+        this.messprogrammTest.filterService(baseUrl, testProtocol);
+    }
+
     /**
      * Testing CREATE services.
      */
@@ -359,6 +393,9 @@
             baseUrl,
             testProtocol,
             this.messungTest.getCreatedMessungId());
+        this.messprogrammTest.createService(
+            baseUrl,
+            testProtocol);
     }
 
     /**
@@ -439,6 +476,17 @@
     }
 
     /**
+     * Testing UPDATE services.
+     */
+    @Test
+    @RunAsClient
+    public final void testC_messprogrammUpdateService(@ArquillianResource URL baseUrl)
+    throws Exception {
+        Assert.assertNotNull(this.ortTest.getCreatedId());
+        this.messprogrammTest.updateService(baseUrl, testProtocol);
+    }
+
+    /**
      * Testing DELETE services.
      */
     @Test
@@ -461,5 +509,6 @@
         this.messungTest.deleteService(baseUrl, testProtocol);
         Assert.assertNotNull(this.probeTest.getCreatedProbeId());
         this.probeTest.deleteService(baseUrl, testProtocol);
+        this.messprogrammTest.deleteService(baseUrl, testProtocol);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/test/land/Messprogramm.java	Thu Apr 30 17:28:19 2015 +0200
@@ -0,0 +1,326 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.test.land;
+
+import java.io.StringReader;
+import java.net.URL;
+import java.util.List;
+
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.junit.Assert;
+
+import de.intevation.lada.Protocol;
+
+/**
+ * Class containing test cases for messprogramm objects.
+ *
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
+public class Messprogramm {
+
+    private static final String COMPARE = "{\"id\":1,\"baId\":null," +
+        "\"datenbasisId\":2,\"gemId\":\"11000000\",\"gueltigBis\":null," +
+        "\"gueltigVon\":null,\"intervallOffset\":null,\"letzteAenderung\":" +
+        "1381413048800,\"mediaDesk\":\"D: 50 90 01 06 02 05 00 00 00 00 00 00\"," +
+        "\"mstId\":\"11010\",\"name\":null,\"netzbetreiberId\":\"11\"," +
+        "\"ortId\":null,\"probeKommentar\":null,\"probeNehmerId\":null," +
+        "\"probenartId\":3,\"probenintervall\":\"M\",\"teilintervallBis\":30," +
+        "\"teilintervallVon\":1,\"test\":false,\"umwId\":\"N81\"}";
+
+    private static final String CREATE = "{\"baId\":null," +
+        "\"datenbasisId\":2,\"gemId\":\"11000000\",\"gueltigBis\":null," +
+        "\"gueltigVon\":null,\"intervallOffset\":null,\"letzteAenderung\":" +
+        "1381413048800,\"mediaDesk\":\"D: 50 90 01 06 02 05 00 00 00 00 00 00\"," +
+        "\"mstId\":\"11010\",\"name\":\"Mess1\",\"netzbetreiberId\":\"11\"," +
+        "\"ortId\":null,\"probeKommentar\":null,\"probeNehmerId\":null," +
+        "\"probenartId\":3,\"probenintervall\":\"M\",\"teilintervallBis\":30," +
+        "\"teilintervallVon\":1,\"test\":false,\"umwId\":\"N81\"}";
+
+
+    private List<Protocol> protocol;
+
+    private static Integer createdId;
+
+    public Integer getCreatedId() {
+        return createdId;
+    }
+
+    /**
+     * @return The test protocol
+     */
+    public List<Protocol> getProtocol() {
+        return protocol;
+    }
+
+    /**
+     * Test the GET Service by requesting all objects.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public final void getAllService(URL baseUrl, List<Protocol> protocol)
+    throws Exception {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("MessprogrammService");
+        prot.setType("get all");
+        prot.setPassed(false);
+        protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target(baseUrl + "messprogramm");
+        /* Request all 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 object by id.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public final void getByIdService(URL baseUrl, List<Protocol> protocol)
+    throws Exception {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("MessprogrammService");
+        prot.setType("get by Id");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a json object from static messprogramm string*/
+            JsonReader fromStringRreader =
+                Json.createReader(new StringReader(COMPARE));
+            JsonObject staticMessung = fromStringRreader.readObject();
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target = client.target(baseUrl + "messprogramm/1");
+            prot.addInfo("messprogrammId", 1);
+            /* Request a 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(staticMessung,
+                content.getJsonObject("data"));
+            prot.addInfo("object", "equals");
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        prot.setPassed(true);
+    }
+
+    /**
+     * Test the GET service using filters.
+     *
+     * @param baseUrl The url poining to the test deployment.
+     */
+    public final void filterService(URL baseUrl, List<Protocol> protocol) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("MessprogrammService");
+        prot.setType("get by filter");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target =
+                client.target(baseUrl + "messprogramm?qid=1");
+            prot.addInfo("filter", "qid=1");
+            /* Request the objects using the filter*/
+            Response response = target.request().get();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject respObj = reader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(respObj.getBoolean("success"));
+            prot.addInfo("success", respObj.getBoolean("success"));
+            Assert.assertEquals("200", respObj.getString("message"));
+            prot.addInfo("message", respObj.getString("message"));
+            Assert.assertNotNull(respObj.getJsonArray("data"));
+            prot.addInfo("objects", respObj.getJsonArray("data").size());
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        prot.setPassed(true);
+    }
+
+    /**
+     * Test the CREATE Service.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public final void createService(
+        URL baseUrl,
+        List<Protocol> protocol)
+    throws Exception {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("MessprogrammService");
+        prot.setType("create");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target = client.target(baseUrl + "messprogramm");
+            /* Send a post request containing a new object*/
+            Response response = target.request().post(
+                    Entity.entity(CREATE, 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();
+            /* Save the id*/
+            createdId =
+                content.getJsonObject("data").getJsonNumber("id").intValue();
+            prot.addInfo("messprogrammId", createdId);
+            /* 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"));
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        prot.setPassed(true);
+    }
+
+    /**
+     * Test the UPDATE Service.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public final void updateService(URL baseUrl, List<Protocol> protocol)
+    throws Exception {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("MessprogrammService");
+        prot.setType("update");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target =
+                client.target(baseUrl + "messprogramm/" + createdId);
+            prot.addInfo("messprogrammId", createdId);
+            /* Request a messprogramm with the saved id*/
+            Response response = target.request().get();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject oldMessung = reader.readObject().getJsonObject("data");
+            /* Change the mmtId*/
+            String updatedEntity =
+                oldMessung.toString().replace("Mess1", "Mess2");
+            prot.addInfo("updated field", "name");
+            prot.addInfo("updated value", "Mess1");
+            prot.addInfo("updated to", "Mess2");
+            /* Send the updated messung via put request*/
+            WebTarget putTarget = client.target(baseUrl + "messprogramm/" + createdId);
+            Response updated = putTarget.request().put(
+                Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
+            /* Try to parse the response*/
+            JsonReader updatedReader = Json.createReader(
+                new StringReader(updated.readEntity(String.class)));
+            JsonObject updatedMessung = updatedReader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(updatedMessung.getBoolean("success"));
+            prot.addInfo("success", updatedMessung.getBoolean("success"));
+            Assert.assertEquals("200", updatedMessung.getString("message"));
+            prot.addInfo("message", updatedMessung.getString("message"));
+            Assert.assertEquals("Mess2",
+                updatedMessung.getJsonObject("data").getString("name"));
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        prot.setPassed(true);
+    }
+
+    /**
+     * Test the DELETE Service.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public final void deleteService(URL baseUrl, List<Protocol> protocol) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName("MessungService");
+        prot.setType("delete");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target =
+                client.target(baseUrl + "messprogramm/" + createdId);
+            prot.addInfo("messprogrammId", createdId);
+            /* Delete a messung with the saved id*/
+            Response response = target.request().delete();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject respObj = reader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(respObj.getBoolean("success"));
+            prot.addInfo("success", respObj.getBoolean("success"));
+            Assert.assertEquals("200", respObj.getString("message"));
+            prot.addInfo("message", respObj.getString("message"));
+        }
+        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)