-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6769be0
commit a45ffc9
Showing
5 changed files
with
261 additions
and
80 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
...pp-schema/app-schema-test/src/test/java/org/geoserver/test/CoordinatesFormattingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,94 @@ | |||
/* (c) 2018 Open Source Geospatial Foundation - all rights reserved | |||
* This code is licensed under the GPL 2.0 license, available at the root | |||
* application directory. | |||
*/ | |||
package org.geoserver.test; | |||
|
|||
import java.util.Optional; | |||
import org.geoserver.catalog.FeatureTypeInfo; | |||
import org.geotools.feature.NameImpl; | |||
import org.junit.Test; | |||
import org.opengis.feature.type.Name; | |||
import org.w3c.dom.Document; | |||
|
|||
/** Testing for Coordinates formatting configurations on WFS GML 3.1 & 3.2 on complex features */ | |||
public class CoordinatesFormattingTest extends StationsAppSchemaTestSupport { | |||
|
|||
@Test | |||
public void testCoordinateFormatWfs11() throws Exception { | |||
enableCoordinatesFormattingGml31(); | |||
Document doc = | |||
getAsDOM( | |||
"st_gml31/wfs?request=GetFeature&version=1.1.0&typename=st_gml31:Station_gml31"); | |||
checkCount( | |||
WFS11_XPATH_ENGINE, | |||
doc, | |||
1, | |||
"//wfs:FeatureCollection/gml:featureMember/st_gml31:Station_gml31[@gml:id=\"st.1\"]/st_gml31:location/gml:Point/gml:pos" | |||
+ "[text()=\"1.00000000 -1.00000000\"]"); | |||
// check force decimal notation | |||
checkCount( | |||
WFS11_XPATH_ENGINE, | |||
doc, | |||
1, | |||
"//wfs:FeatureCollection/gml:featureMember/st_gml31:Station_gml31[@gml:id=\"st.2\"]/st_gml31:location/gml:Point/gml:pos" | |||
+ "[text()=\"0.00000010 -0.00000010\"]"); | |||
} | |||
|
|||
@Test | |||
public void testCoordinateFormatWfs20() throws Exception { | |||
enableCoordinatesFormattingGml32(); | |||
Document document = | |||
getAsDOM("wfs?request=GetFeature&version=2.0&typename=st_gml32:Station_gml32"); | |||
checkCount( | |||
WFS20_XPATH_ENGINE, | |||
document, | |||
1, | |||
"//wfs:FeatureCollection/wfs:member/st_gml32:Station_gml32[@gml:id=\"st.1\"]/st_gml32:location/gml:Point/gml:pos" | |||
+ "[text()=\"1.00000000 -1.00000000\"]"); | |||
// check force decimal notation | |||
checkCount( | |||
WFS20_XPATH_ENGINE, | |||
document, | |||
1, | |||
"//wfs:FeatureCollection/wfs:member/st_gml32:Station_gml32[@gml:id=\"st.2\"]/st_gml32:location/gml:Point/gml:pos" | |||
+ "[text()=\"0.00000010 -0.00000010\"]"); | |||
} | |||
|
|||
private void enableCoordinatesFormattingGml31() { | |||
enableCoordinateFormatting( | |||
new NameImpl(StationsMockData.STATIONS_PREFIX_GML31, "Station_gml31")); | |||
} | |||
|
|||
private void enableCoordinatesFormattingGml32() { | |||
enableCoordinateFormatting( | |||
new NameImpl(StationsMockData.STATIONS_PREFIX_GML32, "Station_gml32")); | |||
} | |||
|
|||
private void enableCoordinateFormatting(Name qname) { | |||
FeatureTypeInfo info = | |||
getGeoServer().getCatalog().getResourceByName(qname, FeatureTypeInfo.class); | |||
info.setNumDecimals(8); | |||
info.setForcedDecimal(true); | |||
info.setPadWithZeros(true); | |||
getGeoServer().getCatalog().save(info); | |||
} | |||
|
|||
@Override | |||
protected StationsMockData createTestData() { | |||
return new StationsMockData() { | |||
@Override | |||
protected Optional<String> extraStationFeatures() { | |||
String features = | |||
"\nst.2=st.2|station2|32154895|station2@stations.org|POINT(-1.0E-7 1.0E-7)"; | |||
return Optional.of(features); | |||
} | |||
|
|||
@Override | |||
protected Optional<String> extraMeasurementFeatures() { | |||
String features = "\nms.3=ms.3|wind|km/h|st.2"; | |||
return Optional.of(features); | |||
} | |||
}; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...schema/app-schema-test/src/test/java/org/geoserver/test/StationsAppSchemaTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,95 @@ | |||
/* (c) 2018 Open Source Geospatial Foundation - all rights reserved | |||
* This code is licensed under the GPL 2.0 license, available at the root | |||
* application directory. | |||
*/ | |||
package org.geoserver.test; | |||
|
|||
import static org.hamcrest.CoreMatchers.is; | |||
import static org.hamcrest.MatcherAssert.assertThat; | |||
|
|||
import java.util.AbstractMap.SimpleEntry; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
import org.custommonkey.xmlunit.XpathEngine; | |||
import org.geoserver.data.test.SystemTestData; | |||
import org.junit.Before; | |||
import org.w3c.dom.Document; | |||
|
|||
/** Test support for GML 3.1 and GML 3.2 Stations data use case */ | |||
public abstract class StationsAppSchemaTestSupport extends AbstractAppSchemaTestSupport { | |||
|
|||
protected final Map<String, String> GML31_PARAMETERS = | |||
Collections.unmodifiableMap( | |||
Stream.of( | |||
new SimpleEntry<>("GML_PREFIX", "gml31"), | |||
new SimpleEntry<>( | |||
"GML_NAMESPACE", "http://www.opengis.net/gml"), | |||
new SimpleEntry<>( | |||
"GML_LOCATION", | |||
"http://schemas.opengis.net/gml/3.1.1/base/gml.xsd")) | |||
.collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))); | |||
|
|||
protected final Map<String, String> GML32_PARAMETERS = | |||
Collections.unmodifiableMap( | |||
Stream.of( | |||
new SimpleEntry<>("GML_PREFIX", "gml32"), | |||
new SimpleEntry<>( | |||
"GML_NAMESPACE", "http://www.opengis.net/gml/3.2"), | |||
new SimpleEntry<>( | |||
"GML_LOCATION", | |||
"http://schemas.opengis.net/gml/3.2.1/gml.xsd")) | |||
.collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()))); | |||
|
|||
// xpath engines used to check WFS responses | |||
protected XpathEngine WFS11_XPATH_ENGINE; | |||
protected XpathEngine WFS20_XPATH_ENGINE; | |||
|
|||
@Before | |||
public void beforeTest() { | |||
// instantiate WFS 1.1 xpath engine | |||
WFS11_XPATH_ENGINE = | |||
StationsMockData.buildXpathEngine( | |||
getTestData().getNamespaces(), | |||
"wfs", | |||
"http://www.opengis.net/wfs", | |||
"gml", | |||
"http://www.opengis.net/gml"); | |||
// instantiate WFS 2.0 xpath engine | |||
WFS20_XPATH_ENGINE = | |||
StationsMockData.buildXpathEngine( | |||
getTestData().getNamespaces(), | |||
"wfs", | |||
"http://www.opengis.net/wfs/2.0", | |||
"gml", | |||
"http://www.opengis.net/gml/3.2"); | |||
} | |||
|
|||
@Override | |||
protected void onSetUp(SystemTestData testData) throws Exception { | |||
super.onSetUp(testData); | |||
} | |||
|
|||
/** * GetFeature tests ** */ | |||
@Override | |||
protected StationsMockData createTestData() { | |||
// instantiate our custom complex types | |||
return new StationsMockData(); | |||
} | |||
|
|||
/** | |||
* Helper method that evaluates a xpath and checks if the number of nodes found correspond to | |||
* the expected number, | |||
*/ | |||
protected void checkCount( | |||
XpathEngine xpathEngine, Document document, int expectedCount, String xpath) { | |||
try { | |||
// evaluate the xpath and compare the number of nodes found | |||
assertThat( | |||
xpathEngine.getMatchingNodes(xpath, document).getLength(), is(expectedCount)); | |||
} catch (Exception exception) { | |||
throw new RuntimeException("Error evaluating xpath: " + xpath, exception); | |||
} | |||
} | |||
} |
Oops, something went wrong.