changeset 1243:b652f4c9b75c

Add automatic tests for DeskriptorService.
author Tom Gottfried <tom@intevation.de>
date Thu, 15 Dec 2016 16:16:32 +0100
parents 69be53d22a18
children 86ef81592f67
files src/test/java/de/intevation/lada/StammdatenTest.java src/test/java/de/intevation/lada/test/ServiceTest.java src/test/java/de/intevation/lada/test/stamm/DeskriptorenTest.java src/test/resources/datasets/clean_and_seed.sql src/test/resources/datasets/dbUnit_deskriptor.json
diffstat 5 files changed, 96 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/test/java/de/intevation/lada/StammdatenTest.java	Thu Dec 15 13:19:00 2016 +0100
+++ b/src/test/java/de/intevation/lada/StammdatenTest.java	Thu Dec 15 16:16:32 2016 +0100
@@ -34,10 +34,12 @@
 import de.intevation.lada.model.stammdaten.MessprogrammKategorie;
 import de.intevation.lada.model.stammdaten.Ort;
 import de.intevation.lada.model.stammdaten.Probenehmer;
+import de.intevation.lada.model.stammdaten.Deskriptoren;
 import de.intevation.lada.test.stamm.DatensatzErzeugerTest;
 import de.intevation.lada.test.stamm.MessprogrammKategorieTest;
 import de.intevation.lada.test.stamm.OrtTest;
 import de.intevation.lada.test.stamm.ProbenehmerTest;
+import de.intevation.lada.test.stamm.DeskriptorenTest;
 import de.intevation.lada.test.stamm.Stammdaten;
 
 
@@ -59,6 +61,7 @@
     private ProbenehmerTest probenehmerTest;
     private MessprogrammKategorieTest messprogrammkategorieTest;
     private OrtTest ortTest;
+    private DeskriptorenTest deskriptorenTest;
 
     public StammdatenTest () {
         stammdatenTest = new Stammdaten();
@@ -66,6 +69,7 @@
         probenehmerTest = new ProbenehmerTest();
         messprogrammkategorieTest = new MessprogrammKategorieTest();
         ortTest = new OrtTest();
+        deskriptorenTest = new DeskriptorenTest();
         testProtocol = new ArrayList<Protocol>();
         verboseLogging = false;
     }
@@ -382,4 +386,36 @@
         stammdatenTest.getById(baseUrl, "verwaltungseinheit",
             "11000000", testProtocol);
     }
+
+    /**
+     * Insert deskriptoren into the database.
+     */
+    @Test
+    @InSequence(35)
+    @UsingDataSet("datasets/dbUnit_deskriptor.json")
+    @DataSource("java:jboss/lada-stamm")
+    @Cleanup(phase=TestExecutionPhase.NONE)
+    public final void prepareDatabaseDeskriptoren() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("database");
+        protocol.setType("insert deskriptor");
+        protocol.addInfo("database", "Insert deskriptor into database");
+        testProtocol.add(protocol);
+        Deskriptoren deskriptor = em.find(Deskriptoren.class, 1000);
+        Assert.assertNotNull(deskriptor);
+        protocol.setPassed(true);
+    }
+
+    /**
+     * Tests deskriptoren service
+     */
+    @Test
+    @InSequence(36)
+    @RunAsClient
+    public final void testDeskriptoren(@ArquillianResource URL baseUrl)
+    throws Exception {
+        deskriptorenTest.init(baseUrl, testProtocol);
+        deskriptorenTest.execute();
+    }
+
 }
--- a/src/test/java/de/intevation/lada/test/ServiceTest.java	Thu Dec 15 13:19:00 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/ServiceTest.java	Thu Dec 15 16:16:32 2016 +0100
@@ -48,7 +48,7 @@
 
     protected List<Protocol> protocol;
 
-    protected List<String> timestampAttributes;
+    protected List<String> timestampAttributes = new ArrayList<String>();
     protected List<String> geomPointAttributes = new ArrayList<String>();
 
     protected URL baseUrl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/test/stamm/DeskriptorenTest.java	Thu Dec 15 16:16:32 2016 +0100
@@ -0,0 +1,53 @@
+/* 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.stamm;
+
+import java.net.URL;
+import java.util.List;
+
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+
+import org.junit.Assert;
+
+import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
+
+public class DeskriptorenTest extends ServiceTest {
+    private JsonObject expectedById;
+    private JsonObject create;
+
+    /**
+     * @return The test protocol
+     */
+    public List<Protocol> getProtocol() {
+        return protocol;
+    }
+
+    @Override
+    public void init(
+        URL baseUrl,
+        List<Protocol> protocol
+    ) {
+        super.init(baseUrl, protocol);
+
+        // Prepare expected object
+        JsonObject content = readJsonResource("/datasets/dbUnit_deskriptor.json")
+            .getJsonArray("stammdaten.deskriptoren").getJsonObject(0);
+        JsonObjectBuilder builder = convertObject(content);
+        expectedById = builder.build();
+        Assert.assertNotNull(expectedById);
+    }
+
+    public final void execute() {
+        getAll("deskriptor", "rest/deskriptor");
+        getAll("deskriptor", "rest/deskriptor?layer=1");
+        getAll("deskriptor", "rest/deskriptor?layer=1&parents=1, 2");
+        getById("deskriptor", "rest/deskriptor/1000", expectedById);
+    }
+}
--- a/src/test/resources/datasets/clean_and_seed.sql	Thu Dec 15 13:19:00 2016 +0100
+++ b/src/test/resources/datasets/clean_and_seed.sql	Thu Dec 15 16:16:32 2016 +0100
@@ -20,6 +20,7 @@
 DELETE FROM staat;
 DELETE FROM umwelt;
 DELETE FROM verwaltungseinheit;
+DELETE FROM deskriptoren;
 
 -- seed
 -- minimal master data to make interface tests runnable
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/resources/datasets/dbUnit_deskriptor.json	Thu Dec 15 16:16:32 2016 +0100
@@ -0,0 +1,5 @@
+{
+    "stammdaten.deskriptoren": [{
+        "id": 1000
+    }]
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)