Mercurial > lada > lada-server
changeset 1239:59bdb52bac1c
Test output latitude and longitude against input geometry.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Tue, 13 Dec 2016 20:34:36 +0100 |
parents | a81de70d321d |
children | 961d50dde3c2 7610f8f58c9c |
files | src/test/java/de/intevation/lada/BaseTest.java src/test/java/de/intevation/lada/test/ServiceTest.java src/test/java/de/intevation/lada/test/stamm/OrtTest.java |
diffstat | 3 files changed, 42 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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()); }
--- 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");