Skip to content

Commit

Permalink
GEOT-6128 Complex features fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandor777 committed Oct 18, 2018
1 parent 6769be0 commit a45ffc9
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 80 deletions.
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);
}
};
}
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;


import java.io.StringReader; import java.io.StringReader;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.opengis.wfs20.StoredQueryDescriptionType; import net.opengis.wfs20.StoredQueryDescriptionType;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.custommonkey.xmlunit.XpathEngine;
import org.geoserver.catalog.impl.NamespaceInfoImpl; import org.geoserver.catalog.impl.NamespaceInfoImpl;
import org.geoserver.data.test.SystemTestData; import org.geoserver.data.test.SystemTestData;
import org.geoserver.wfs.StoredQuery; import org.geoserver.wfs.StoredQuery;
import org.geoserver.wfs.StoredQueryProvider; import org.geoserver.wfs.StoredQueryProvider;
import org.geotools.wfs.v2_0.WFS; import org.geotools.wfs.v2_0.WFS;
import org.geotools.wfs.v2_0.WFSConfiguration; import org.geotools.wfs.v2_0.WFSConfiguration;
import org.geotools.xml.Parser; import org.geotools.xml.Parser;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;


/** /**
* Tests that namespaces are correctly handled by WFS and app-schema when features belonging to * Tests that namespaces are correctly handled by WFS and app-schema when features belonging to
* different namespaces are chained together. * different namespaces are chained together.
*/ */
public final class NamespacesWfsTest extends AbstractAppSchemaTestSupport { public final class NamespacesWfsTest extends StationsAppSchemaTestSupport {


private static final String TEST_STORED_QUERY_ID = "NamespacesTestStoredQuery"; private static final String TEST_STORED_QUERY_ID = "NamespacesTestStoredQuery";


Expand Down Expand Up @@ -62,66 +56,13 @@ public final class NamespacesWfsTest extends AbstractAppSchemaTestSupport {
+ " </wfs:QueryExpressionText>\n" + " </wfs:QueryExpressionText>\n"
+ "</wfs:StoredQueryDescription>"; + "</wfs:StoredQueryDescription>";


private static 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())));

private static 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
private XpathEngine WFS11_XPATH_ENGINE;
private 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 @Override
protected void onSetUp(SystemTestData testData) throws Exception { protected void onSetUp(SystemTestData testData) throws Exception {
super.onSetUp(testData); super.onSetUp(testData);
// inject a test namespace to check on responses // inject a test namespace to check on responses
addTestNamespaceToCatalog(); addTestNamespaceToCatalog();
} }


/** * GetFeature tests ** */
@Override
protected StationsMockData createTestData() {
// instantiate our custom complex types
return new StationsMockData();
}

@Test @Test
public void globalServiceGetFeatureNamespacesWfs11() { public void globalServiceGetFeatureNamespacesWfs11() {
Document document = Document document =
Expand Down Expand Up @@ -332,21 +273,6 @@ private void checkGml32StationsGetPropertyValueResult(Document document) {
+ "st_gml32:measurements/ms_gml32:Measurement_gml32[ms_gml32:name='wind']"); + "st_gml32:measurements/ms_gml32:Measurement_gml32[ms_gml32:name='wind']");
} }


/**
* Helper method that evaluates a xpath and checks if the number of nodes found correspond to
* the expected number,
*/
private 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.", exception);
}
}

/** /**
* Test a request with two queries (to different featureTypes and namespaces) Checks null * Test a request with two queries (to different featureTypes and namespaces) Checks null
* prefixes issue on multiple query WFS 2.0.0 GML 3.2 versions * prefixes issue on multiple query WFS 2.0.0 GML 3.2 versions
Expand Down
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);
}
}
}

0 comments on commit a45ffc9

Please sign in to comment.