Refine search
@Test public void testGet() throws Exception { Document doc = getAsDOM("wfs?service=WFS&version=1.0.0&request=getCapabilities"); assertEquals("WFS_Capabilities", doc.getDocumentElement().getNodeName()); XpathEngine xpath = XMLUnit.newXpathEngine(); assertTrue(xpath.getMatchingNodes("//wfs:FeatureType", doc).getLength() > 0); }
@Test public void testSupportedSpatialOperators() throws Exception { Document doc = getAsDOM("wfs?service=WFS&request=getCapabilities&version=1.1.0"); // let's look for the spatial capabilities, extract all the spatial operators XpathEngine engine = XMLUnit.newXpathEngine(); NodeList spatialOperators = engine.getMatchingNodes( "//ogc:Spatial_Capabilities/ogc:SpatialOperators/ogc:SpatialOperator/@name", doc); Set<String> ops = new TreeSet<String>(); for (int i = 0; i < spatialOperators.getLength(); i++) { String format = spatialOperators.item(i).getFirstChild().getNodeValue(); ops.add(format); } List<String> expectedSpatialOperators = getSupportedSpatialOperatorsList(false); assertEquals(expectedSpatialOperators.size(), ops.size()); assertTrue(ops.containsAll(expectedSpatialOperators)); }
@Test public void testUpdateAttributeRestricted() throws Exception { setRequestAuth("cite_writeatts", "cite"); Document dom = postAsDOM("wfs", UPDATE_ADDRESS); // print(dom); // not sure why CITE tests make us throw an exception for this one instead of using // in transaction reporting... assertXpathEvaluatesTo("1", "count(//ows:ExceptionReport)", dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String message = xpath.evaluate("//ows:ExceptionText", dom); assertTrue(message.matches(".*write protected.*ADDRESS.*")); }
@Test public void testSupportedSpatialOperators() throws Exception { Document doc = getAsDOM("wfs?service=WFS&request=getCapabilities&version=2.0.0"); // let's look for the spatial capabilities, extract all the spatial operators XpathEngine engine = XMLUnit.newXpathEngine(); NodeList spatialOperators = engine.getMatchingNodes( "//fes:Spatial_Capabilities/fes:SpatialOperators/fes:SpatialOperator/@name", doc); Set<String> ops = new TreeSet<String>(); for (int i = 0; i < spatialOperators.getLength(); i++) { String format = spatialOperators.item(i).getFirstChild().getNodeValue(); ops.add(format); } List<String> expectedSpatialOperators = getSupportedSpatialOperatorsList(false); assertEquals(expectedSpatialOperators.size(), ops.size()); assertTrue(ops.containsAll(expectedSpatialOperators)); }
/** The UTF grid format shows up in the caps document. The format name is freeform */ @Test public void testCapabilities11() throws Exception { Document dom = getAsDOM("wms?service=WMS&request=GetCapabilities&version=1.1.0"); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); assertEquals("1", xpath.evaluate("count(//GetMap[Format='utfgrid'])", dom)); }
@Test public void testGet() throws Exception { Document doc = getAsDOM("wfs?service=WFS&request=getCapabilities&version=1.1.0"); String docText = getAsString("wfs?service=WFS&request=GetCapabilities&version=1.1.0"); assertEquals("wfs:WFS_Capabilities", doc.getDocumentElement().getNodeName()); assertEquals("1.1.0", doc.getDocumentElement().getAttribute("version")); XpathEngine xpath = XMLUnit.newXpathEngine(); assertTrue(xpath.getMatchingNodes("//wfs:FeatureType", doc).getLength() > 0); assertFalse(docText, docText.contains("xmlns:xml=")); }
/** * The UTF grid format shows up in the caps document. WMS 1.3 requires the usage of mime types * that will match the result content type */ @Test public void testCapabilities13() throws Exception { Document dom = getAsDOM("wms?service=WMS&request=GetCapabilities&version=1.3.0"); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); assertEquals( "1", xpath.evaluate( "count(//wms:GetMap[wms:Format='application/json;type=utfgrid'])", dom)); }
@Test public void testFilteredCapabilitiesCite() throws Exception { Document dom = dom(get("wms?request=getCapabilities&version=1.1.1&namespace=cite"), true); Element e = dom.getDocumentElement(); assertEquals("WMT_MS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); assertTrue( xpath.getMatchingNodes("//Layer/Name[starts-with(., cite)]", dom).getLength() > 0); assertEquals( 0, xpath.getMatchingNodes("//Layer/Name[not(starts-with(., cite))]", dom).getLength()); }
@Test public void testInsertRestricted() throws Exception { setRequestAuth("cite_insertfilter", "cite"); Document dom = postAsDOM("wfs", INSERT_RESTRICTED_STREET); // print(dom); assertXpathEvaluatesTo("1", "count(//wfs:WFS_TransactionResponse)", dom); assertXpathEvaluatesTo("1", "count(//wfs:Status/wfs:FAILED)", dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String message = xpath.evaluate("//wfs:Message", dom); assertTrue(message.matches(".*write restrictions.*")); }
@Test public void testResourceLink() throws Exception { addLayer(); Document doc = getAsDOM(RestBaseController.ROOT_PATH + "/layers/states.xml"); XpathEngine xpath = XMLUnit.newXpathEngine(); String resourceUrl = xpath.evaluate("//resource/atom:link/@href", doc); resourceUrl = resourceUrl.substring(resourceUrl.indexOf("/rest")); doc = getAsDOM(resourceUrl); assertXpathEvaluatesTo("states", "/wmsLayer/name", doc); } }
@Test public void testFilterRequestedAttribute() throws Exception { // should only see one feature setRequestAuth("cite_readatts", "cite"); Document doc = getAsDOM( "wfs?request=GetFeature&version=1.1.0&service=wfs&typeName=" + getLayerId(SystemTestData.BUILDINGS) + "&propertyName=FID,ADDRESS"); // print(doc); assertXpathEvaluatesTo("1", "count(//ows:ExceptionReport)", doc); XpathEngine xpath = XMLUnit.newXpathEngine(); String message = xpath.evaluate("//ows:ExceptionText", doc); Pattern pattern = Pattern.compile(".*ADDRESS.*not available.*", Pattern.MULTILINE | Pattern.DOTALL); assertTrue(pattern.matcher(message).matches()); }
@Test public void testExtraAttributesNoFilter() throws Exception { // should only see one feature setRequestAuth("cite_readattsnf", "cite"); Document doc = getAsDOM( "wfs?request=GetFeature&version=1.1.0&service=wfs&typeName=" + getLayerId(SystemTestData.BUILDINGS) + "&propertyName=FID,ADDRESS"); // print(doc); assertXpathEvaluatesTo("1", "count(//ows:ExceptionReport)", doc); XpathEngine xpath = XMLUnit.newXpathEngine(); String message = xpath.evaluate("//ows:ExceptionText", doc); Pattern pattern = Pattern.compile(".*ADDRESS.*not available.*", Pattern.MULTILINE | Pattern.DOTALL); assertTrue(pattern.matcher(message).matches()); }
@Test public void testGetBasic() throws Exception { Document dom = getAsDOM(BASEPATH + "?request=GetCapabilities&service=WCS&version=1.0.0"); // print(dom); checkValidationErrors(dom, WCS10_GETCAPABILITIES_SCHEMA); // checke backlinks URLs can simply string-appended to XpathEngine xpath = XMLUnit.newXpathEngine(); NodeList nodes = xpath.getMatchingNodes("//wcs:OnlineResource/@xlink:href", dom); assertTrue(nodes.getLength() > 0); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); String text = node.getTextContent(); assertThat(text, CoreMatchers.endsWith("?")); } }
@Test public void testTypeNameCount() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=2.0.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (!ft.isEnabled()) { it.remove(); } } final int enabledCount = enabledTypes.size(); assertEquals( enabledCount, xpath.getMatchingNodes( "/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType", doc) .getLength()); }
@Test public void testLayerCount() throws Exception { Document dom = dom(get("wms?request=getCapabilities&version=1.1.1"), true); XpathEngine xpath = XMLUnit.newXpathEngine(); NodeList nodeLayers = xpath.getMatchingNodes("/WMT_MS_Capabilities/Capability/Layer/Layer", dom); assertEquals(getRawTopLayerCount(), nodeLayers.getLength()); }
@org.junit.Test public void testLayerCount() throws Exception { int expectedLayerCount = getRawTopLayerCount(); Document dom = dom(get("wms?request=GetCapabilities&version=1.3.0"), true); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); NodeList nodeLayers = xpath.getMatchingNodes( "/wms:WMS_Capabilities/wms:Capability/wms:Layer/wms:Layer", dom); assertEquals( expectedLayerCount /* the layers under the opaque group */, nodeLayers.getLength()); }
@Test public void testTypeNameCount() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=1.1.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (!ft.enabled()) { it.remove(); } } final int enabledCount = enabledTypes.size(); assertEquals( enabledCount, xpath.getMatchingNodes( "/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType", doc) .getLength()); }
@Test public void testInsertAttributeRestricted() throws Exception { setRequestAuth("cite_writeatts", "cite"); Document dom = postAsDOM("wfs", INSERT_RESTRICTED_STREET); print(dom); assertXpathEvaluatesTo("1", "count(//wfs:WFS_TransactionResponse)", dom); assertXpathEvaluatesTo("1", "count(//wfs:Status/wfs:FAILED)", dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String message = xpath.evaluate("//wfs:Message", dom); assertTrue(message.matches(".*write protected.*ADDRESS.*")); }
@Test public void testTypeNameCount() throws Exception { // filter on an existing namespace Document doc = getAsDOM("wfs?service=WFS&version=1.0.0&request=getCapabilities"); Element e = doc.getDocumentElement(); assertEquals("WFS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); final List<FeatureTypeInfo> enabledTypes = getCatalog().getFeatureTypes(); for (Iterator<FeatureTypeInfo> it = enabledTypes.iterator(); it.hasNext(); ) { FeatureTypeInfo ft = it.next(); if (!ft.enabled()) { it.remove(); } } final int enabledCount = enabledTypes.size(); assertEquals( enabledCount, xpath.getMatchingNodes( "/wfs:WFS_Capabilities/wfs:FeatureTypeList/wfs:FeatureType", doc) .getLength()); }
@org.junit.Test public void testFilteredCapabilitiesCite() throws Exception { Document dom = dom(get("wms?request=getCapabilities&version=1.3.0&namespace=cite"), true); Element e = dom.getDocumentElement(); assertEquals("WMS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); assertTrue( xpath.getMatchingNodes("//wms:Layer/wms:Name[starts-with(., cite)]", dom) .getLength() > 0); assertEquals( 0, xpath.getMatchingNodes("//wms:Layer/wms:Name[not(starts-with(., cite))]", dom) .getLength()); }