[Lada-commits] [PATCH 3 of 5] Add automatic tests for DeskriptorService

Wald Commits scm-commit at wald.intevation.org
Fri Dec 16 12:19:54 CET 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1481814992 -3600
# Node ID b652f4c9b75c50eefc308744bf14131346fa162e
# Parent  69be53d22a182dfb40408a04211e26258a285b3d
Add automatic tests for DeskriptorService.

diff -r 69be53d22a18 -r b652f4c9b75c src/test/java/de/intevation/lada/StammdatenTest.java
--- 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();
+    }
+
 }
diff -r 69be53d22a18 -r b652f4c9b75c src/test/java/de/intevation/lada/test/ServiceTest.java
--- 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;
diff -r 69be53d22a18 -r b652f4c9b75c src/test/java/de/intevation/lada/test/stamm/DeskriptorenTest.java
--- /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);
+    }
+}
diff -r 69be53d22a18 -r b652f4c9b75c src/test/resources/datasets/clean_and_seed.sql
--- 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
diff -r 69be53d22a18 -r b652f4c9b75c src/test/resources/datasets/dbUnit_deskriptor.json
--- /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
+    }]
+}


More information about the Lada-commits mailing list