changeset 1048:6960275c4609 schema-update

Added unit tests for probe- and messung identifier.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 09 Sep 2016 15:35:49 +0200
parents 1b6adb3971d4
children 625b0adcba45
files src/test/java/de/intevation/lada/ImporterTest.java src/test/resources/datasets/clean_and_seed.sql src/test/resources/datasets/dbUnit_messung_import.json src/test/resources/datasets/dbUnit_probe.json src/test/resources/datasets/dbUnit_probe_import.json
diffstat 5 files changed, 419 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/ImporterTest.java	Fri Sep 09 15:35:49 2016 +0200
@@ -0,0 +1,318 @@
+/* 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;
+
+import java.util.ArrayList;
+
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+import org.apache.log4j.Logger;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.persistence.Cleanup;
+import org.jboss.arquillian.persistence.CleanupStrategy;
+import org.jboss.arquillian.persistence.DataSource;
+import org.jboss.arquillian.persistence.TestExecutionPhase;
+import org.jboss.arquillian.persistence.UsingDataSet;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import de.intevation.lada.importer.Identified;
+import de.intevation.lada.importer.Identifier;
+import de.intevation.lada.importer.IdentifierConfig;
+import de.intevation.lada.model.land.Messung;
+import de.intevation.lada.model.land.Probe;
+
+/**
+ * Class to test the Lada-Importer
+ *
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
+@RunWith(Arquillian.class)
+public class ImporterTest extends BaseTest{
+
+    @Inject
+    Logger internalLogger;
+
+    @PersistenceContext(unitName="land")
+    EntityManager em;
+
+    @Inject
+    @IdentifierConfig(type="Probe")
+    Identifier probeIdentifier;
+
+    @Inject
+    @IdentifierConfig(type="Messung")
+    Identifier messungIdentifier;
+
+    public ImporterTest() {
+        testProtocol = new ArrayList<Protocol>();
+    }
+
+    /**
+     * PROBE IDENTIFIER
+     */
+    @Test
+    @UsingDataSet("datasets/dbUnit_probe_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyProbeByHPNrMST() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify probe");
+        protocol.addInfo("import", "Compare and find Probe by HP-Nr. and MST, Update");
+
+        Probe probe = new Probe();
+        probe.setHauptprobenNr("120510002");
+        probe.setMstId("06010");
+
+        Identified found = probeIdentifier.find(probe);
+        Assert.assertEquals(Identified.UPDATE, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_probe_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyProbeByHPNrMSTNew() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify probe");
+        protocol.addInfo("import", "Compare and find Probe by HP-Nr. and MST, New");
+
+        Probe probe = new Probe();
+        probe.setHauptprobenNr("120510003");
+        probe.setMstId("06010");
+
+        Identified found = probeIdentifier.find(probe);
+        Assert.assertEquals(Identified.NEW, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_probe_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyProbeByIdAlt() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify probe");
+        protocol.addInfo("import", "Compare and find Probe by idAlt, Update");
+
+        Probe probe = new Probe();
+        probe.setIdAlt("T001");
+
+        Identified found = probeIdentifier.find(probe);
+        Assert.assertEquals(Identified.UPDATE, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_probe_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyProbeByIdAltNew() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify probe");
+        protocol.addInfo("import", "Compare and find Probe by idAlt, New");
+
+        Probe probe = new Probe();
+        probe.setIdAlt("T002");
+
+        Identified found = probeIdentifier.find(probe);
+        Assert.assertEquals(Identified.NEW, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_probe_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyProbeByIdAltReject() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify probe");
+        protocol.addInfo("import", "Compare and find Probe by idAlt, Reject");
+
+        Probe probe = new Probe();
+        probe.setIdAlt("T001");
+        probe.setHauptprobenNr("120510003");
+        probe.setMstId("06010");
+
+        Identified found = probeIdentifier.find(probe);
+        Assert.assertEquals(Identified.REJECT, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_probe_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyProbeByIdAltUpdate() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify probe");
+        protocol.addInfo("import", "Compare and find Probe by idAlt, Update");
+
+        Probe probe = new Probe();
+        probe.setIdAlt("T001");
+        probe.setHauptprobenNr("");
+        probe.setMstId("06010");
+
+        Identified found = probeIdentifier.find(probe);
+        Assert.assertEquals(Identified.UPDATE, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    /**
+     * MESSUNG IDENTIFIER
+     */
+    @Test
+    @UsingDataSet("datasets/dbUnit_messung_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyMessungByNpNr() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify messung");
+        protocol.addInfo("import", "Compare and find Messung by NP-Nr., Update");
+
+        Messung messung = new Messung();
+        messung.setProbeId(1000);
+        messung.setNebenprobenNr("06A0");
+
+        Identified found = messungIdentifier.find(messung);
+        Assert.assertEquals(Identified.UPDATE, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_messung_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyMessungByNpNrNew() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify messung");
+        protocol.addInfo("import", "Compare and find Messung by NP-Nr., New");
+
+        Messung messung = new Messung();
+        messung.setProbeId(1000);
+        messung.setNebenprobenNr("06A1");
+
+        Identified found = messungIdentifier.find(messung);
+        Assert.assertEquals(Identified.NEW, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_messung_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyMessungByIdAlt() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify messung");
+        protocol.addInfo("import", "Compare and find Messung by idAlt, Update");
+
+        Messung messung = new Messung();
+        messung.setProbeId(1000);
+        messung.setIdAlt(1);
+
+        Identified found = messungIdentifier.find(messung);
+        Assert.assertEquals(Identified.UPDATE, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_messung_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyMessungByIdAltNew() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify messung");
+        protocol.addInfo("import", "Compare and find Messung by idAlt, New");
+
+        Messung messung = new Messung();
+        messung.setProbeId(1000);
+        messung.setIdAlt(2);
+
+        Identified found = messungIdentifier.find(messung);
+        Assert.assertEquals(Identified.NEW, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_messung_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyMessungByIdAltReject() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify messung");
+        protocol.addInfo("import", "Compare and find Messung by idAlt, Reject");
+
+        Messung messung = new Messung();
+        messung.setProbeId(1000);
+        messung.setIdAlt(1);
+        messung.setNebenprobenNr("06A2");
+
+        Identified found = messungIdentifier.find(messung);
+        Assert.assertEquals(Identified.REJECT, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+
+    @Test
+    @UsingDataSet("datasets/dbUnit_messung_import.json")
+    @DataSource("java:jboss/lada-land")
+    @Cleanup(phase=TestExecutionPhase.AFTER,
+        strategy=CleanupStrategy.USED_TABLES_ONLY)
+    public final void identifyMessungByIdAltUpdate() throws Exception {
+        Protocol protocol = new Protocol();
+        protocol.setName("import");
+        protocol.setType("identify messung");
+        protocol.addInfo("import", "Compare and find Messung by idAlt, Update");
+
+        Messung messung = new Messung();
+        messung.setProbeId(1000);
+        messung.setIdAlt(1);
+        messung.setNebenprobenNr("");
+
+        Identified found = messungIdentifier.find(messung);
+        Assert.assertEquals(Identified.UPDATE, found);
+        protocol.setPassed(true);
+        testProtocol.add(protocol);
+    }
+}
--- a/src/test/resources/datasets/clean_and_seed.sql	Fri Sep 09 15:35:09 2016 +0200
+++ b/src/test/resources/datasets/clean_and_seed.sql	Fri Sep 09 15:35:49 2016 +0200
@@ -42,6 +42,9 @@
             id, bundesland, bezeichnung,
             is_bundesland, is_gemeinde, is_landkreis, is_regbezirk)
        VALUES ('11000000', '11000000', 'Berlin', 1, 1, 1, 0);
+INSERT INTO probenehmer (
+			id, netzbetreiber_id, prn_id, bezeichnung, kurz_bezeichnung)
+		VALUES (726, '06', 'prn', 'test', 'test');
 
 -- authorization data needed for tests
 INSERT INTO auth (ldap_group, netzbetreiber_id, mst_id, funktion_id)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/resources/datasets/dbUnit_messung_import.json	Fri Sep 09 15:35:49 2016 +0200
@@ -0,0 +1,54 @@
+{
+    "land.messprogramm": [{
+        "id": 1000,
+        "test": false,
+        "mst_id": "06010",
+        "labor_mst_id": "06010",
+        "datenbasis_id": 9,
+        "gem_id": "11000000",
+        "media_desk": "D: 50 90 01 06 02 05 00 00 00 00 00 00",
+        "umw_id": "L6",
+        "ort_id": 1000,
+        "probenart_id": 1,
+        "probenintervall": "M",
+        "gueltig_von": 1,
+        "gueltig_bis": 100,
+        "teilintervall_von": 1,
+        "teilintervall_bis": 30,
+        "letzte_aenderung": "2015-03-01 12:00:00"
+    }],
+    "land.probe": [{
+        "id": 1000,
+        "id_alt": "T001",
+        "ba_id": "1",
+        "datenbasis_id": 9,
+        "letzte_aenderung": "2012-05-05 11:12:00",
+        "media": "Trinkwasser Zentralversorgung Oberflächenwasser aufbereitet",
+        "media_desk": "D: 59 04 01 00 05 05 01 02 00 00 00 00",
+        "mst_id": "06010",
+        "labor_mst_id": "06010",
+        "probeentnahme_beginn": "2012-05-03 13:07:00",
+        "probenart_id": 1,
+        "test": false,
+        "umw_id":"L6",
+        "hauptproben_nr": "120510002",
+        "mpr_id": 1000,
+        "probe_nehmer_id": 726,
+        "solldatum_beginn": "2012-05-01 16:00:00",
+        "solldatum_ende": "2012-05-05 16:00:00",
+        "tree_modified": "2012-05-08 10:00:00"
+    }],
+    "land.messung": [{
+        "id": 1200,
+        "probe_id": 1000,
+        "nebenproben_nr": "06A0",
+        "id_alt": 1,
+        "mmt_id": "A3",
+        "messdauer": 3600,
+        "messzeitpunkt": "2012-05-06 14:00:00",
+        "fertig": false,
+        "letzte_aenderung": "2012-05-08 12:00:00",
+        "geplant": true,
+        "tree_modified": "2012-05-09 12:00:00"
+    }]
+}
--- a/src/test/resources/datasets/dbUnit_probe.json	Fri Sep 09 15:35:09 2016 +0200
+++ b/src/test/resources/datasets/dbUnit_probe.json	Fri Sep 09 15:35:49 2016 +0200
@@ -3,7 +3,7 @@
         "id": 1000,
         "id_alt": "T001",
         "ba_id": "1",
-        "datenbasis_id": 2,
+        "datenbasis_id": 9,
         "letzte_aenderung": "2012-05-05 11:12:00",
         "media": "Trinkwasser Zentralversorgung Oberflächenwasser aufbereitet",
         "media_desk": "D: 59 04 01 00 05 05 01 02 00 00 00 00",
@@ -12,10 +12,9 @@
         "probeentnahme_beginn": "2012-05-03 13:07:00",
         "probenart_id": 1,
         "test": false,
-        "umw_id":"N72",
+        "umw_id":"L6",
         "hauptproben_nr": "120510002",
-        "mp_kat": "1",
-        "mpr_id": 3749,
+        "mpr_id": 1000,
         "probe_nehmer_id": 726,
         "solldatum_beginn": "2012-05-01 16:00:00",
         "solldatum_ende": "2012-05-05 16:00:00",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/resources/datasets/dbUnit_probe_import.json	Fri Sep 09 15:35:49 2016 +0200
@@ -0,0 +1,41 @@
+{
+    "land.messprogramm": [{
+        "id": 1000,
+        "test": false,
+        "mst_id": "06010",
+        "labor_mst_id": "06010",
+        "datenbasis_id": 9,
+        "gem_id": "11000000",
+        "media_desk": "D: 50 90 01 06 02 05 00 00 00 00 00 00",
+        "umw_id": "L6",
+        "ort_id": 1000,
+        "probenart_id": 1,
+        "probenintervall": "M",
+        "gueltig_von": 1,
+        "gueltig_bis": 100,
+        "teilintervall_von": 1,
+        "teilintervall_bis": 30,
+        "letzte_aenderung": "2015-03-01 12:00:00"
+    }],
+    "land.probe": [{
+        "id": 1000,
+        "id_alt": "T001",
+        "ba_id": "1",
+        "datenbasis_id": 9,
+        "letzte_aenderung": "2012-05-05 11:12:00",
+        "media": "Trinkwasser Zentralversorgung Oberflächenwasser aufbereitet",
+        "media_desk": "D: 59 04 01 00 05 05 01 02 00 00 00 00",
+        "mst_id": "06010",
+        "labor_mst_id": "06010",
+        "probeentnahme_beginn": "2012-05-03 13:07:00",
+        "probenart_id": 1,
+        "test": false,
+        "umw_id":"L6",
+        "hauptproben_nr": "120510002",
+        "mpr_id": 1000,
+        "probe_nehmer_id": 726,
+        "solldatum_beginn": "2012-05-01 16:00:00",
+        "solldatum_ende": "2012-05-05 16:00:00",
+        "tree_modified": "2012-05-08 10:00:00"
+    }]
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)