[Lada-commits] [PATCH 2 of 2] merged

Wald Commits scm-commit at wald.intevation.org
Mon Dec 19 10:54:28 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1482141222 -3600
# Node ID f434ccd6486451d58132a1a0f2f06b0fc13b84b0
# Parent  7610f8f58c9c89ded1356f5d007b0677b396d3f6
# Parent  3d0d401b9d9aa4a089b41d80d33b8b612de3e2b8
merged.

diff -r 7610f8f58c9c -r f434ccd64864 .hgtags
--- a/.hgtags	Mon Dec 19 10:52:48 2016 +0100
+++ b/.hgtags	Mon Dec 19 10:53:42 2016 +0100
@@ -39,3 +39,4 @@
 d4d43d846a60211b935d673a0e34f89e260cf16d 2.2.0
 effef57f3f7e1587cae44b5907cf624105ced0db 2.3.0
 fb90e4d8bd0d09fb7bc638e67b4f482ba830e3b7 2.4.0
+204fb75b0c06e2f760dfe37d2fb0845ec31b68f1 2.4.1
diff -r 7610f8f58c9c -r f434ccd64864 Dockerfile
--- a/Dockerfile	Mon Dec 19 10:52:48 2016 +0100
+++ b/Dockerfile	Mon Dec 19 10:53:42 2016 +0100
@@ -76,7 +76,7 @@
 #
 # Build and deploy LADA-server
 #
-ENV LADA_VERSION 2.4.1-SNAPSHOT
+ENV LADA_VERSION 2.5-SNAPSHOT
 RUN mvn clean compile package && \
     mv target/lada-server-$LADA_VERSION.war \
        $JBOSS_HOME/standalone/deployments && \
diff -r 7610f8f58c9c -r f434ccd64864 db_schema/stammdaten_fill_verwaltungsgrenze.sql
--- a/db_schema/stammdaten_fill_verwaltungsgrenze.sql	Mon Dec 19 10:52:48 2016 +0100
+++ b/db_schema/stammdaten_fill_verwaltungsgrenze.sql	Mon Dec 19 10:53:42 2016 +0100
@@ -1,7 +1,7 @@
-insert into stammdaten.verwaltungsgrenze(gem_id, shape)
-SELECT 
+INSERT INTO stammdaten.verwaltungsgrenze(gem_id, shape)
+SELECT
   verwaltungseinheit.id,
   gem_utm.geom
-FROM 
+FROM
   stammdaten.verwaltungseinheit
-left join geo.gem_utm on verwaltungseinheit.id = gem_utm.ags;
+JOIN geo.gem_utm ON verwaltungseinheit.id = gem_utm.ags;
diff -r 7610f8f58c9c -r f434ccd64864 db_schema/stammdaten_schema.sql
--- a/db_schema/stammdaten_schema.sql	Mon Dec 19 10:52:48 2016 +0100
+++ b/db_schema/stammdaten_schema.sql	Mon Dec 19 10:53:42 2016 +0100
@@ -167,7 +167,7 @@
 CREATE TABLE verwaltungsgrenze (
     id serial PRIMARY KEY,
     gem_id character varying(8) NOT NULL REFERENCES verwaltungseinheit,
-    shape public.geometry(MultiPolygon, 4326)
+    shape public.geometry(MultiPolygon, 4326) NOT NULL
 );
 CREATE INDEX verwaltungsgrenze_sp_idx ON verwaltungsgrenze USING gist (shape);
 
diff -r 7610f8f58c9c -r f434ccd64864 pom.xml
--- a/pom.xml	Mon Dec 19 10:52:48 2016 +0100
+++ b/pom.xml	Mon Dec 19 10:53:42 2016 +0100
@@ -137,6 +137,7 @@
             <groupId>org.geotools</groupId>
             <artifactId>gt-epsg-hsql</artifactId>
             <version>14.5</version>
+            <scope>runtime</scope>
         </dependency>
         <dependency>
             <groupId>org.geotools</groupId>
@@ -368,5 +369,5 @@
             <url>http://www.hibernatespatial.org/repository</url>
         </repository>
     </repositories>
-    <version>2.4.1-SNAPSHOT</version>
+    <version>2.5-SNAPSHOT</version>
 </project>
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java
--- a/src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/main/java/de/intevation/lada/importer/laf/LafObjectMapper.java	Mon Dec 19 10:53:42 2016 +0100
@@ -842,6 +842,16 @@
             }
         }
 
+        ortFactory.transformCoordinates(ort);
+        if (hasKoord && !hasGem) {
+            ortFactory.findVerwaltungseinheit(ort);
+        }
+        if (ortFactory.hasErrors()) {
+            // Add to warnings because Probe object might be imported
+            currentWarnings.addAll(ortFactory.getErrors());
+            return null;
+        }
+
         Violation violation = ortValidator.validate(ort);
         for (Entry<String, List<Integer>> warn :
                  violation.getWarnings().entrySet()) {
@@ -862,17 +872,6 @@
             return null;
         }
 
-        ortFactory.transformCoordinates(ort);
-        if (hasKoord && !hasGem) {
-            logger.debug("find Verwaltungseinheit");
-            ortFactory.findVerwaltungseinheit(ort);
-        }
-        if (ortFactory.hasErrors()) {
-            // Add to warnings because Probe object might be imported
-            currentWarnings.addAll(ortFactory.getErrors());
-            return null;
-        }
-
         repository.create(ort, "stamm");
         return ort;
     }
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java
--- a/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/DeskriptorService.java	Mon Dec 19 10:53:42 2016 +0100
@@ -104,20 +104,20 @@
         QueryBuilder<Deskriptoren> builder = new QueryBuilder<Deskriptoren>(
             repository.entityManager("stamm"),
             Deskriptoren.class);
-        builder.andNot("sn", 0);
-        if (params.containsKey("layer") &&
-            !params.containsKey("parents")) {
-            String layer = params.getFirst("layer");
-            builder.and("ebene", layer);
-        }
-        else {
-            String layer = params.getFirst("layer");
-            String parents = params.getFirst("parents");
-            builder.and("ebene", layer);
-            List<String> parentList = new ArrayList<String>();
-            String[] parentArray = parents.split(", ");
-            parentList = Arrays.asList(parentArray);
-            builder.andIn("vorgaenger", parentList);
+        builder.and("sn", 0).not();
+        try {
+            builder.and("ebene",
+                Integer.valueOf(params.getFirst("layer")));
+            builder.and("ebene", params.getFirst("layer"));
+            if (params.containsKey("parents")) {
+                String parents = params.getFirst("parents");
+                List<String> parentList = new ArrayList<String>();
+                String[] parentArray = parents.split(", ");
+                parentList = Arrays.asList(parentArray);
+                builder.andIn("vorgaenger", parentList);
+            }
+        } catch (NumberFormatException nfe) {
+            return new Response(false, 612, null);
         }
         return repository.filter(builder.getQuery(), "stamm");
     }
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/rest/stamm/OrtService.java
--- a/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/stamm/OrtService.java	Mon Dec 19 10:53:42 2016 +0100
@@ -271,14 +271,6 @@
             return new Response(false, 699, ort);
         }
 
-        Violation violation = validator.validate(ort);
-        if (violation.hasErrors()) {
-            Response response = new Response(false, 604, ort);
-            response.setErrors(violation.getErrors());
-            response.setWarnings(violation.getWarnings());
-            return response;
-        }
-
         ortFactory.transformCoordinates(ort);
         if (ortFactory.hasErrors()) {
             Violation factoryErrs = new Violation();
@@ -289,6 +281,15 @@
             response.setErrors(factoryErrs.getErrors());
             return response;
         }
+
+        Violation violation = validator.validate(ort);
+        if (violation.hasErrors()) {
+            Response response = new Response(false, 604, ort);
+            response.setErrors(violation.getErrors());
+            response.setWarnings(violation.getWarnings());
+            return response;
+        }
+
         Response response = repository.create(ort, "stamm");
         if(violation.hasWarnings()) {
             response.setWarnings(violation.getWarnings());
@@ -341,14 +342,6 @@
             return new Response(false, 699, ort);
         }
 
-        Violation violation = validator.validate(ort);
-        if (violation.hasErrors()) {
-            Response response = new Response(false, 604, ort);
-            response.setErrors(violation.getErrors());
-            response.setWarnings(violation.getWarnings());
-            return response;
-        }
-
         ortFactory.transformCoordinates(ort);
         if (ortFactory.hasErrors()) {
             Violation factoryErrs = new Violation();
@@ -359,6 +352,15 @@
             response.setErrors(factoryErrs.getErrors());
             return response;
         }
+
+        Violation violation = validator.validate(ort);
+        if (violation.hasErrors()) {
+            Response response = new Response(false, 604, ort);
+            response.setErrors(violation.getErrors());
+            response.setWarnings(violation.getWarnings());
+            return response;
+        }
+
         Response response = repository.update(ort, "stamm");
         if(violation.hasWarnings()) {
             response.setWarnings(violation.getWarnings());
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/util/data/QueryBuilder.java
--- a/src/main/java/de/intevation/lada/util/data/QueryBuilder.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/main/java/de/intevation/lada/util/data/QueryBuilder.java	Mon Dec 19 10:53:42 2016 +0100
@@ -79,20 +79,14 @@
     }
 
     /**
-     * Logical AND NOT operation.
+     * Negate filter.
      *
-     * @param id    The database column name.
-     * @param value The filter value
-     * @return The builder itself.
      */
-    public QueryBuilder<T> andNot(String id, Object value) {
-        Predicate p = this.builder.equal(this.root.get(id), value);
-        if (this.filter != null) {
-            this.filter = this.builder.and(this.filter, p).not();
+    public QueryBuilder<T> not() {
+        if (this.filter == null) {
+            return this;
         }
-        else {
-            this.filter = this.builder.and(p).not();
-        }
+        this.filter = this.filter.not();
         return this;
     }
 
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java	Mon Dec 19 10:53:42 2016 +0100
@@ -0,0 +1,88 @@
+/* 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.validation.rules.ort;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import com.vividsolutions.jts.geom.Point;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.lada.model.stammdaten.Ort;
+import de.intevation.lada.model.stammdaten.Verwaltungseinheit;
+import de.intevation.lada.model.stammdaten.Verwaltungsgrenze;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+/**
+ * Validation rule for ort.
+ * Validates if the coordinates are in the specified "Verwaltungseinheit".
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at ValidationRule("Ort")
+public class CoordinatesInVE implements Rule {
+
+    @Inject
+    private Logger logger;
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Violation execute(Object object) {
+        Ort ort = (Ort)object;
+
+        String gemId = "".equals(ort.getGemId())
+            ? null
+            : ort.getGemId();
+
+        if (gemId != null) {
+
+            QueryBuilder<Verwaltungsgrenze> vg =
+                new QueryBuilder<Verwaltungsgrenze>(
+                    repository.entityManager("stamm"),
+                    Verwaltungsgrenze.class);
+            vg.and("gemId", gemId);
+            List<Verwaltungsgrenze> vgs = repository.filterPlain(
+                vg.getQuery(), "stamm");
+            if (vgs == null || vgs.isEmpty()) {
+                Violation violation = new Violation();
+                violation.addWarning("verwaltungsgrenze", 600);
+                return violation;
+            }
+
+            Point p = ort.getGeom();
+            if (p == null) {
+                logger.error("geom is null. "
+                    + "Probably OrtFactory.transformCoordinates() has not "
+                    + "been called on this ort.");
+            }
+            for (Verwaltungsgrenze singlevg : vgs) {
+                if(singlevg.getShape().contains(p)) {
+                    return null;
+                }
+            }
+            Violation violation = new Violation();
+            violation.addWarning("verwaltungsgrenze", 651);
+            return violation;
+        }
+
+        return null;
+    }
+
+}
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/validation/rules/ort/IsUnique.java
--- a/src/main/java/de/intevation/lada/validation/rules/ort/IsUnique.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/ort/IsUnique.java	Mon Dec 19 10:53:42 2016 +0100
@@ -31,12 +31,12 @@
 
         QueryBuilder<Ort> builder = new QueryBuilder<Ort>(
             repository.entityManager("stamm"), Ort.class);
+        if (ort.getId() != null) {
+            // Consider UPDATE
+            builder.and("id", ort.getId()).not();
+        }
         builder.and("netzbetreiberId", ort.getNetzbetreiberId());
         builder.and("ortId", ort.getOrtId());
-        if (ort.getId() != null) {
-            // Consider UPDATE
-            builder.andNot("id", ort.getId());
-        }
         if (!repository.filterPlain(builder.getQuery(), "stamm").isEmpty()) {
             Violation violation = new Violation();
             violation.addError("ortId", 672);
diff -r 7610f8f58c9c -r f434ccd64864 src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java
--- a/src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java	Mon Dec 19 10:52:48 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/* 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.validation.rules.ort;
-
-import java.util.List;
-
-import javax.inject.Inject;
-
-import com.vividsolutions.jts.geom.Point;
-
-import de.intevation.lada.model.land.Ortszuordnung;
-import de.intevation.lada.model.stammdaten.Ort;
-import de.intevation.lada.model.stammdaten.Verwaltungseinheit;
-import de.intevation.lada.model.stammdaten.Verwaltungsgrenze;
-import de.intevation.lada.util.annotation.RepositoryConfig;
-import de.intevation.lada.util.data.QueryBuilder;
-import de.intevation.lada.util.data.Repository;
-import de.intevation.lada.util.data.RepositoryType;
-import de.intevation.lada.validation.Violation;
-import de.intevation.lada.validation.annotation.ValidationRule;
-import de.intevation.lada.validation.rules.Rule;
-
-/**
- * Validation rule for ort.
- * Validates if the coordinates are in the specified "Verwaltungseinheit".
- *
- * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
- */
- at ValidationRule("Ortszuordnung")
-public class CoordinatesInVE implements Rule {
-
-    @Inject
-    @RepositoryConfig(type=RepositoryType.RO)
-    private Repository repository;
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public Violation execute(Object object) {
-        Ortszuordnung oz = (Ortszuordnung)object;
-        if (!"E".equals(oz.getOrtszuordnungTyp())) {
-            return null;
-        }
-
-        Ort ort = repository.getByIdPlain(Ort.class, oz.getOrtId(), "stamm");
-        String gemId = ort.getGemId();
-        if (gemId == null) {
-            Violation violation = new Violation();
-            violation.addWarning("gemId", 631);
-            return violation;
-        }
-
-        QueryBuilder<Verwaltungsgrenze> vg =
-            new QueryBuilder<Verwaltungsgrenze>(
-                repository.entityManager("stamm"), Verwaltungsgrenze.class);
-        vg.and("gemId", gemId);
-        List<Verwaltungsgrenze> vgs = repository.filterPlain(
-            vg.getQuery(), "stamm");
-        if (vgs == null || vgs.isEmpty()) {
-            Violation violation = new Violation();
-            violation.addWarning("verwaltungsgrenze", 600);
-            return violation;
-        }
-
-        Point p = ort.getGeom();
-        boolean hit = false;
-        for (Verwaltungsgrenze singlevg : vgs) {
-            if(singlevg.getShape().contains(p)) {
-                hit = true;
-            }
-        }
-        if (!hit) {
-            Violation violation = new Violation();
-            violation.addWarning("verwaltungsgrenze", 651);
-            return violation;
-        }
-        return null;
-    }
-
-}
diff -r 7610f8f58c9c -r f434ccd64864 src/test/java/de/intevation/lada/BaseTest.java
--- a/src/test/java/de/intevation/lada/BaseTest.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/test/java/de/intevation/lada/BaseTest.java	Mon Dec 19 10:53:42 2016 +0100
@@ -44,26 +44,23 @@
      */
     @Deployment(testable=true)
     public static WebArchive createDeployment() throws Exception {
-        File[] files = Maven.resolver().loadPomFromFile("pom.xml")
-            .importRuntimeAndTestDependencies().resolve().withTransitivity().asFile();
+        File antlr = Maven.resolver().loadPomFromFile("pom.xml")
+            .resolve("org.antlr:antlr4-runtime")
+            .withoutTransitivity().asSingleFile();
 
         WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME)
             .addPackages(true, Package.getPackage("de.intevation.lada"))
             .addAsResource("log4j.properties", "log4j.properties")
             .addAsResource("shibboleth.properties", "shibboleth.properties")
             .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+            .addAsLibrary(antlr)
             .addAsResource("META-INF/test-persistence.xml",
                 "META-INF/persistence.xml");
-        for (File f : files) {
-            if (f.getName().contains("antlr4")
-                || f.getName().contains("gt-metadata")
-                || f.getName().contains("gt-opengis")
-                || f.getName().contains("gt-referencing")
-                //TODO: still something missing. One test will fail.
-            ) {
-                archive.addAsLibrary(f);
-            }
-        }
+        addWithDependencies("org.geotools:gt-api", archive);
+        addWithDependencies("org.geotools:gt-referencing", archive);
+        addWithDependencies("org.geotools:gt-epsg-hsql", archive);
+        addWithDependencies("org.geotools:gt-opengis", archive);
+
         return archive;
     }
 
@@ -78,4 +75,12 @@
     public static final void afterTests() {
         System.out.println("");
     }
+
+    private static void addWithDependencies(String coordinate, WebArchive archive) {
+        File[] files = Maven.resolver().loadPomFromFile("pom.xml")
+            .resolve(coordinate).withTransitivity().asFile();
+        for (File f : files) {
+            archive.addAsLibrary(f);
+        }
+    }
 }
diff -r 7610f8f58c9c -r f434ccd64864 src/test/java/de/intevation/lada/StammdatenTest.java
--- a/src/test/java/de/intevation/lada/StammdatenTest.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/test/java/de/intevation/lada/StammdatenTest.java	Mon Dec 19 10:53:42 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 7610f8f58c9c -r f434ccd64864 src/test/java/de/intevation/lada/test/ServiceTest.java
--- a/src/test/java/de/intevation/lada/test/ServiceTest.java	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/ServiceTest.java	Mon Dec 19 10:53:42 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;
@@ -159,7 +159,6 @@
     /**
      * Test the GET Service by requesting a single object by id.
      *
-     * @param baseUrl The url pointing to the test deployment.
      */
     public JsonObject getById(
         String name,
@@ -218,7 +217,6 @@
     /**
      * Test the GET service using filters.
      *
-     * @param baseUrl The url poining to the test deployment.
      */
     public JsonObject filter(String name, String parameter) {
         System.out.print(".");
@@ -230,8 +228,8 @@
         /* Create a client*/
         Client client = ClientBuilder.newClient();
         WebTarget target =
-            client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24");
-        prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24");
+            client.target(baseUrl + parameter);
+        prot.addInfo("filter", parameter);
         /* Request the objects using the filter*/
         Response response = target.request()
             .header("X-SHIB-user", BaseTest.TEST_USER)
@@ -264,7 +262,6 @@
     /**
      * Test the CREATE Service.
      *
-     * @param baseUrl The url pointing to the test deployment.
      */
     public JsonObject create(String name, String parameter, JsonObject create) {
         System.out.print(".");
@@ -276,7 +273,7 @@
         /* Create a client*/
         Client client = ClientBuilder.newClient();
         WebTarget target = client.target(baseUrl + parameter);
-        /* Send a post request containing a new probe*/
+        /* Send a post request containing a new object*/
         Response response = target.request()
             .header("X-SHIB-user", BaseTest.TEST_USER)
             .header("X-SHIB-roles", BaseTest.TEST_ROLES)
@@ -305,9 +302,8 @@
     }
 
     /**
-     * Test the probe update service.
+     * Test an update service.
      *
-     * @param baseUrl The url pointing to the test deployment.
      */
     public JsonObject update(
         String name,
@@ -326,7 +322,7 @@
             /* Create a client*/
             Client client = ClientBuilder.newClient();
             WebTarget target = client.target(baseUrl + parameter);
-            /* Request a with the saved id*/
+            /* Request object corresponding to id in URL */
             Response response = target.request()
                 .header("X-SHIB-user", BaseTest.TEST_USER)
                 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
@@ -335,18 +331,21 @@
             /* Try to parse the response*/
             JsonReader reader = Json.createReader(new StringReader(entity));
             JsonObject oldObject = reader.readObject().getJsonObject("data");
-            /* Change the hauptprobenNr*/
+
+            /* Value replacement */
             String updatedEntity =
                 oldObject.toString().replace(oldValue, newValue);
             prot.addInfo("updated datafield", updateAttribute);
             prot.addInfo("updated value", oldValue);
             prot.addInfo("updated to", newValue);
-            /* Send the updated probe via put request*/
+
+            /* Send modified object via put request*/
             WebTarget putTarget = client.target(baseUrl + parameter);
             Response updated = putTarget.request()
                 .header("X-SHIB-user", BaseTest.TEST_USER)
                 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
                 .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
+
             /* Try to parse the response*/
             JsonReader updatedReader = Json.createReader(
                 new StringReader(updated.readEntity(String.class)));
@@ -373,7 +372,6 @@
     /**
      * Test the DELETE Service.
      *
-     * @param baseUrl The url pointing to the test deployment.
      */
     public JsonObject delete(String name, String parameter) {
         System.out.print(".");
@@ -387,7 +385,7 @@
         WebTarget target =
             client.target(baseUrl + parameter);
         prot.addInfo("parameter", parameter);
-        /* Delete a probe with the id saved when created a probe*/
+        /* Delete object with ID given in URL */
         Response response = target.request()
             .header("X-SHIB-user", BaseTest.TEST_USER)
             .header("X-SHIB-roles", BaseTest.TEST_ROLES)
diff -r 7610f8f58c9c -r f434ccd64864 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	Mon Dec 19 10:53:42 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 7610f8f58c9c -r f434ccd64864 src/test/resources/datasets/clean_and_seed.sql
--- a/src/test/resources/datasets/clean_and_seed.sql	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/test/resources/datasets/clean_and_seed.sql	Mon Dec 19 10:53:42 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 7610f8f58c9c -r f434ccd64864 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	Mon Dec 19 10:53:42 2016 +0100
@@ -0,0 +1,5 @@
+{
+    "stammdaten.deskriptoren": [{
+        "id": 1000
+    }]
+}
diff -r 7610f8f58c9c -r f434ccd64864 src/test/resources/log4j.properties
--- a/src/test/resources/log4j.properties	Mon Dec 19 10:52:48 2016 +0100
+++ b/src/test/resources/log4j.properties	Mon Dec 19 10:53:42 2016 +0100
@@ -3,6 +3,7 @@
 log4j.logger.org.xnio=WARN
 log4j.logger.org.hibernate=INFO
 log4j.logger.org.jboss=INFO
+log4j.logger.org.geotools=WARN
 log4j.appender.lada=org.apache.log4j.RollingFileAppender
 log4j.appender.lada.File=/var/log/wildfly/lada-server-test.log
 log4j.appender.lada.MaxFileSize=5MB


More information about the Lada-commits mailing list