Skip to content

Commit

Permalink
Merge pull request #12 from opengeospatial/feature-issue#16
Browse files Browse the repository at this point in the history
Updated test to count the features from the ESRI response.
  • Loading branch information
dstenger committed Jun 5, 2019
2 parents c7b8572 + a8a74c4 commit 8f80ff3
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import de.latlon.ets.wms13.core.client.WmsKvpRequest;
import de.latlon.ets.wms13.core.dgiwg.testsuite.AbstractBaseGetFixture;
import de.latlon.ets.wms13.core.domain.WmsNamespaces;
import de.latlon.ets.wms13.core.util.request.WmsRequestBuilder;

/**
Expand All @@ -30,18 +31,22 @@ public void buildGetMapRequest() {
}

protected NodeList parseFeatureMemberNodes( Document entity )
throws XPathFactoryConfigurationException, XPathExpressionException {
String xPathAbstract = "//gml:featureMember";
throws XPathFactoryConfigurationException, XPathExpressionException {
XPath xpath = createXPath();
return (NodeList) xpath.evaluate( xPathAbstract, entity, XPathConstants.NODESET );
String namespaceURI = entity.getDocumentElement().getNamespaceURI();
if ( WmsNamespaces.ESRI.equals( namespaceURI ) ) {
return (NodeList) xpath.evaluate( "//esri:FeatureInfoResponse//esri:FIELDS", entity, XPathConstants.NODESET );
}

return (NodeList) xpath.evaluate( "//*[local-name() = 'featureMember']", entity, XPathConstants.NODESET );
}

protected XPath createXPath()
throws XPathFactoryConfigurationException {
throws XPathFactoryConfigurationException {
XPathFactory factory = XPathFactory.newInstance( XPathConstants.DOM_OBJECT_MODEL );
XPath xpath = factory.newXPath();
xpath.setNamespaceContext( NS_BINDINGS );
return xpath;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ private WmsNamespaces() {

/** GML */
public static final String GML = "http://www.opengis.net/gml";

/** ESRI */
public static final String ESRI = "http://www.esri.com/wms";

/** ExtendedCapabilities Namespace used for SOAP binding */
public static final String SOAPWMS = "http://schemas.deegree.org/extensions/services/wms/1.3.0";
Expand All @@ -45,6 +48,7 @@ public static NamespaceBindings withStandardBindings() {
nsBindings.addNamespaceBinding( XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi" );
nsBindings.addNamespaceBinding( WmsNamespaces.GML, "gml" );
nsBindings.addNamespaceBinding( WmsNamespaces.SOAPWMS, "soapwms" );
nsBindings.addNamespaceBinding( WmsNamespaces.ESRI, "esri" );
return nsBindings;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.latlon.ets.wms13.core.dgiwg.testsuite.getfeatureinfo;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* @author <a href="mailto:goltz@lat-lon.de">Lyn Goltz </a>
*/
public class BaseGetFeatureInfoFixtureTest {

@Test
public void testParseFeatureMemberNodes_esri()
throws Exception {
BaseGetFeatureInfoFixture baseGetFeatureInfoFixture = new BaseGetFeatureInfoFixture();
Document documentEntity = parseDocument( "gfi-response_esri.xml" );
NodeList nodeList = baseGetFeatureInfoFixture.parseFeatureMemberNodes( documentEntity );

assertThat( nodeList.getLength(), is( 1 ) );
}

@Test
public void testParseFeatureMemberNodes_gml()
throws Exception {
BaseGetFeatureInfoFixture baseGetFeatureInfoFixture = new BaseGetFeatureInfoFixture();
Document documentEntity = parseDocument( "gfi-response_gml.xml" );
NodeList nodeList = baseGetFeatureInfoFixture.parseFeatureMemberNodes( documentEntity );

assertThat( nodeList.getLength(), is( 2 ) );
}

@Test
public void testParseFeatureMemberNodes_gml32()
throws Exception {
BaseGetFeatureInfoFixture baseGetFeatureInfoFixture = new BaseGetFeatureInfoFixture();
Document documentEntity = parseDocument( "gfi-response_gml32.xml" );
NodeList nodeList = baseGetFeatureInfoFixture.parseFeatureMemberNodes( documentEntity );

assertThat( nodeList.getLength(), is( 2 ) );
}

private Document parseDocument( String resource )
throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware( true );
DocumentBuilder builder = factory.newDocumentBuilder();
InputStream wmsCapabilities = getClass().getResourceAsStream( resource );
return builder.parse( new InputSource( wmsCapabilities ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<FeatureInfoResponse xmlns:esri_wms="http://www.esri.com/wms" xmlns="http://www.esri.com/wms">
<FIELDS OBJECTID="1" Shape="Polygon" Shape_Length="9.636801" Shape_Area="5.539155"></FIELDS>
</FeatureInfoResponse>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version='1.0' encoding='UTF-8'?>
<FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:epsg::4326">
<gml:lowerCorner>51.589828 13.421406</gml:lowerCorner>
<gml:upperCorner>51.600844 13.439423</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<xplan:BP_Bereich xmlns:xplan="http://www.deegree.org/xplanung/1/0" gml:id="XPLAN_BP_BEREICH_1">
<xplan:gmlId>XPLAN_BP_BEREICH_1</xplan:gmlId>
<xplan:xpVersion>4.1</xplan:xpVersion>
<xplan:xpPlanType>BP_Plan</xplan:xpPlanType>
<xplan:xpPlanName>Abrundungssatzung_Test</xplan:xpPlanName>
<xplan:inkrafttretensDatum>1999-05-17</xplan:inkrafttretensDatum>
<xplan:nummer>0</xplan:nummer>
<xplan:name>Teilbereich 1</xplan:name>
<xplan:bedeutung>Sonstiges</xplan:bedeutung>
<xplan:bedeutungCode>9999</xplan:bedeutungCode>
<xplan:gehoertZuPlan>[XPLAN_BP_PLAN_1]</xplan:gehoertZuPlan>
<xplan:rasterBasis>[/getAttachment?featureID=XPLAN_XP_EXTERNEREFERENZPLAN_1&amp;filename=Abrundungssatzung_Test_ergb.tif]</xplan:rasterBasis>
</xplan:BP_Bereich>
</gml:featureMember>
<gml:featureMember>
<xplan:BP_Bereich xmlns:xplan="http://www.deegree.org/xplanung/1/0" gml:id="XPLAN_BP_BEREICH_2">
<xplan:gmlId>XPLAN_BP_BEREICH_2</xplan:gmlId>
<xplan:xpVersion>4.1</xplan:xpVersion>
<xplan:xpPlanType>BP_Plan</xplan:xpPlanType>
<xplan:xpPlanName>Abrundungssatzung_Test</xplan:xpPlanName>
<xplan:inkrafttretensDatum>1999-05-17</xplan:inkrafttretensDatum>
<xplan:nummer>0</xplan:nummer>
<xplan:name>Teilbereich 2</xplan:name>
<xplan:bedeutung>Sonstiges</xplan:bedeutung>
<xplan:bedeutungCode>9999</xplan:bedeutungCode>
<xplan:gehoertZuPlan>[XPLAN_BP_PLAN_2]</xplan:gehoertZuPlan>
<xplan:rasterBasis>[/getAttachment?featureID=XPLAN_XP_EXTERNEREFERENZPLAN_2&amp;filename=Abrundungssatzung_Test_ergb.tif]</xplan:rasterBasis>
</xplan:BP_Bereich>
</gml:featureMember>
</FeatureCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version='1.0' encoding='UTF-8'?>
<FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml/3.2">
<gml:boundedBy>
<gml:Envelope srsName="urn:ogc:def:crs:epsg::4326">
<gml:lowerCorner>51.589828 13.421406</gml:lowerCorner>
<gml:upperCorner>51.600844 13.439423</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<xplan:BP_Bereich xmlns:xplan="http://www.deegree.org/xplanung/1/0" gml:id="XPLAN_BP_BEREICH_1">
<xplan:gmlId>XPLAN_BP_BEREICH_1</xplan:gmlId>
<xplan:xpVersion>4.1</xplan:xpVersion>
<xplan:xpPlanType>BP_Plan</xplan:xpPlanType>
<xplan:xpPlanName>Abrundungssatzung_Test</xplan:xpPlanName>
<xplan:inkrafttretensDatum>1999-05-17</xplan:inkrafttretensDatum>
<xplan:nummer>0</xplan:nummer>
<xplan:name>Teilbereich 1</xplan:name>
<xplan:bedeutung>Sonstiges</xplan:bedeutung>
<xplan:bedeutungCode>9999</xplan:bedeutungCode>
<xplan:gehoertZuPlan>[XPLAN_BP_PLAN_1]</xplan:gehoertZuPlan>
<xplan:rasterBasis>[/getAttachment?featureID=XPLAN_XP_EXTERNEREFERENZPLAN_1&amp;filename=Abrundungssatzung_Test_ergb.tif]</xplan:rasterBasis>
</xplan:BP_Bereich>
</gml:featureMember>
<gml:featureMember>
<xplan:BP_Bereich xmlns:xplan="http://www.deegree.org/xplanung/1/0" gml:id="XPLAN_BP_BEREICH_2">
<xplan:gmlId>XPLAN_BP_BEREICH_2</xplan:gmlId>
<xplan:xpVersion>4.1</xplan:xpVersion>
<xplan:xpPlanType>BP_Plan</xplan:xpPlanType>
<xplan:xpPlanName>Abrundungssatzung_Test</xplan:xpPlanName>
<xplan:inkrafttretensDatum>1999-05-17</xplan:inkrafttretensDatum>
<xplan:nummer>0</xplan:nummer>
<xplan:name>Teilbereich 2</xplan:name>
<xplan:bedeutung>Sonstiges</xplan:bedeutung>
<xplan:bedeutungCode>9999</xplan:bedeutungCode>
<xplan:gehoertZuPlan>[XPLAN_BP_PLAN_2]</xplan:gehoertZuPlan>
<xplan:rasterBasis>[/getAttachment?featureID=XPLAN_XP_EXTERNEREFERENZPLAN_2&amp;filename=Abrundungssatzung_Test_ergb.tif]</xplan:rasterBasis>
</xplan:BP_Bereich>
</gml:featureMember>
</FeatureCollection>

0 comments on commit 8f80ff3

Please sign in to comment.