[Lada-commits] [PATCH 8 of 8] Test output latitude and longitude against input geometry

Wald Commits scm-commit at wald.intevation.org
Tue Dec 13 20:36:33 CET 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1481657676 -3600
# Node ID 59bdb52bac1cbdff075894f409a3d95150aa0c0c
# Parent  a81de70d321d468f2e9f9bbba09b6a4c5db4d038
Test output latitude and longitude against input geometry.

diff -r a81de70d321d -r 59bdb52bac1c src/test/java/de/intevation/lada/BaseTest.java
--- a/src/test/java/de/intevation/lada/BaseTest.java	Tue Dec 13 20:32:00 2016 +0100
+++ b/src/test/java/de/intevation/lada/BaseTest.java	Tue Dec 13 20:34:36 2016 +0100
@@ -56,7 +56,10 @@
                 "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);
             }
diff -r a81de70d321d -r 59bdb52bac1c src/test/java/de/intevation/lada/test/ServiceTest.java
--- a/src/test/java/de/intevation/lada/test/ServiceTest.java	Tue Dec 13 20:32:00 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/ServiceTest.java	Tue Dec 13 20:34:36 2016 +0100
@@ -12,6 +12,7 @@
 import java.net.URL;
 import java.sql.Timestamp;
 import java.util.List;
+import java.util.ArrayList;
 import java.util.Map.Entry;
 import java.util.Scanner;
 
@@ -31,15 +32,24 @@
 import org.apache.commons.lang.WordUtils;
 import org.junit.Assert;
 
+import com.vividsolutions.jts.io.ParseException;
+import com.vividsolutions.jts.io.WKTReader;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.Point;
+
 import de.intevation.lada.BaseTest;
 import de.intevation.lada.Protocol;
 import de.intevation.lada.test.land.ProbeTest;
 
 public class ServiceTest {
 
+    private static final String LAT_KEY = "latitude";
+    private static final String LONG_KEY = "longitude";
+
     protected List<Protocol> protocol;
 
     protected List<String> timestampAttributes;
+    protected List<String> geomPointAttributes = new ArrayList<String>();
 
     protected URL baseUrl;
 
@@ -73,11 +83,34 @@
         for (Entry<String, JsonValue> entry : object.entrySet()) {
             String key = WordUtils.capitalize(
                 entry.getKey(), new char[]{'_'}).replaceAll("_","");
-            key = key.replaceFirst(key.substring(0, 1), key.substring(0, 1).toLowerCase());
+            key = key.replaceFirst(
+                key.substring(0, 1), key.substring(0, 1).toLowerCase());
             if (timestampAttributes.contains(key)) {
-                Timestamp timestamp = Timestamp.valueOf(entry.getValue().toString().replaceAll("\"", ""));
+                Timestamp timestamp = Timestamp.valueOf(
+                    entry.getValue().toString().replaceAll("\"", ""));
                 builder.add(key, timestamp.getTime());
             }
+            else if (geomPointAttributes.contains(key)) {
+                // Convert EWKT to latitude and longitude
+                String wkt = entry.getValue().toString().split(";")[1];
+                try {
+                    Geometry geom = new WKTReader().read(wkt);
+                    if (!(geom instanceof Point)) {
+                        throw new IllegalArgumentException(
+                            "WKT does not represent a point");
+                    }
+                    Point point = (Point)geom;
+                    builder.add(LONG_KEY, point.getX());
+                    builder.add(LAT_KEY, point.getY());
+                } catch (ParseException | IllegalArgumentException e) {
+                    Protocol prot = new Protocol();
+                    prot.addInfo("exception", e.getMessage());
+                    protocol.add(prot);
+                    Assert.fail("Exception while parsing WKT '"
+                        + wkt + "':\n"
+                        + e.getMessage());
+                }
+            }
             else {
                 builder.add(key, entry.getValue());
             }
diff -r a81de70d321d -r 59bdb52bac1c src/test/java/de/intevation/lada/test/stamm/OrtTest.java
--- a/src/test/java/de/intevation/lada/test/stamm/OrtTest.java	Tue Dec 13 20:32:00 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/stamm/OrtTest.java	Tue Dec 13 20:34:36 2016 +0100
@@ -40,6 +40,10 @@
         timestampAttributes = Arrays.asList(new String[]{
             "letzteAenderung"
         });
+        // Attributes with point geometries
+        geomPointAttributes = Arrays.asList(new String[]{
+                "geom"
+        });
 
         // Prepare expected object
         JsonObject content = readJsonResource("/datasets/dbUnit_ort.json");


More information about the Lada-commits mailing list