@Test public void testModifySettingsChangeWorkspace() throws Exception { testAddSettings(); WorkspaceInfo ws1 = catalog.getWorkspaceByName("acme"); WorkspaceInfo ws2 = catalog.getFactory().createWorkspace(); ws2.setName("foo"); catalog.add(ws2); SettingsInfo settings = getGeoServer().getSettings(ws1); settings.setWorkspace(ws2); getGeoServer().save(settings); File f = catalog.getResourceLoader().find("workspaces", ws1.getName(), "settings.xml"); assertNull(f); f = catalog.getResourceLoader().find("workspaces", ws2.getName(), "settings.xml"); assertNotNull(f); Document dom = dom(f); assertXpathEvaluatesTo(ws2.getId(), "/settings/workspace/id", dom); }
public static void assertXmlSimilar(CharSequence expected, CharSequence actual) throws SAXException, IOException { Diff diff = new Diff(expected.toString(), actual.toString()); diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); assertXMLEqual(diff, true); } }
@Test public void testModifyDataStore() throws Exception { testAddDataStore(); DataStoreInfo ds = catalog.getDataStoreByName("acme", "foostore"); assertTrue(ds.getConnectionParameters().isEmpty()); ds.getConnectionParameters().put("foo", "bar"); catalog.save(ds); File f = new File(testData.getDataDirectoryRoot(), "workspaces/acme/foostore/datastore.xml"); Document dom = dom(f); assertXpathExists("/dataStore/connectionParameters/entry[@key='foo']", dom); }
@Test public void testWmsStorePasswordEncryption() throws Exception { WMSStoreInfo wms = buildWmsStore(); ByteArrayOutputStream out = new ByteArrayOutputStream(); persister.save(wms, out); Document dom = dom(new ByteArrayInputStream(out.toByteArray())); // print(dom); // check password has been encrypted XMLAssert.assertXpathExists("/wmsStore/password", dom); XMLAssert.assertXpathNotExists("/wmsStore[password = 'password']", dom); XMLAssert.assertXpathExists("/wmsStore[starts-with(password, 'crypt1:')]", dom); WMSStoreInfo loaded = persister.load(new ByteArrayInputStream(out.toByteArray()), WMSStoreInfo.class); assertEquals("password", loaded.getPassword()); }
XMLAssert.assertXpathExists("//settings/metadata/map", doc); XMLAssert.assertXpathEvaluatesTo("2", "count(//settings/metadata/map/entry)", doc); XMLAssert.assertXpathEvaluatesTo("key1", "//settings/metadata/map/entry[1]/string[1]", doc); XMLAssert.assertXpathEvaluatesTo( "value1", "//settings/metadata/map/entry[1]/string[2]", doc); XMLAssert.assertXpathEvaluatesTo("key2", "//settings/metadata/map/entry[2]/string[1]", doc); XMLAssert.assertXpathEvaluatesTo( "value2", "//settings/metadata/map/entry[2]/string[2]", doc);
@Test public void testPostWithViewParams_v100() throws Exception { String xml = "<wfs:GetFeature service=\"WFS\" version=\"1.0.0\" " + "viewParams=\"bool:true;name:name-f003\" " + "xmlns:cdf=\"http://www.opengis.net/cite/data\" " + "xmlns:wfs=\"http://www.opengis.net/wfs\" " + "xmlns:ogc=\"http://www.opengis.net/ogc\" > " + "<wfs:Query typeName=\"" + viewTypeName + "\"> " + "</wfs:Query></wfs:GetFeature>"; Document doc = postAsDOM("wfs", xml); assertEquals("wfs:FeatureCollection", doc.getDocumentElement().getNodeName()); NodeList featureMembers = doc.getElementsByTagName("gml:featureMember"); assertFalse(featureMembers.getLength() == 0); assertXpathEvaluatesTo("name-f003", "//gs:pgeo_view/gs:name", doc); assertXpathEvaluatesTo("1", "count(//gs:pgeo_view)", doc); }
@Test public void testGetAsXML() throws Exception { Document dom = getAsDOM(RestBaseController.ROOT_PATH + "/services/wms/settings.xml"); assertEquals("wms", dom.getDocumentElement().getLocalName()); assertEquals(1, dom.getElementsByTagName("name").getLength()); assertXpathEvaluatesTo("true", "/wms/enabled", dom); assertXpathEvaluatesTo("WMS", "/wms/name", dom); assertXpathEvaluatesTo("false", "/wms/watermark/enabled", dom); assertXpathEvaluatesTo("Nearest", "/wms/interpolation", dom); }
protected String checkOws11Exception(Document dom) throws Exception { assertEquals("ServiceExceptionReport", dom.getFirstChild().getNodeName()); assertEquals( "1.2.0", dom.getFirstChild().getAttributes().getNamedItem("version").getNodeValue()); assertXpathEvaluatesTo("1.2.0", "/ServiceExceptionReport/@version", dom); Node root = xpath.getMatchingNodes("/ServiceExceptionReport", dom).item(0); assertNotNull(root); NodeList nodes = dom.getElementsByTagName("ows:ExceptionText"); if (nodes.getLength() > 0) { return nodes.item(0).getNodeValue(); } return null; }
@Test public void testSections() throws Exception { Document dom = getAsDOM(BASEPATH + "?service=csw&version=2.0.2&request=GetCapabilities§ions=ServiceIdentification,ServiceProvider"); // print(dom); checkValidationErrors(dom); // basic check on local name Element e = dom.getDocumentElement(); assertEquals("Capabilities", e.getLocalName()); // basic check on xpath node assertXpathEvaluatesTo("1", "count(/csw:Capabilities)", dom); assertEquals("1", xpath.evaluate("count(//ows:ServiceIdentification)", dom)); assertEquals("1", xpath.evaluate("count(//ows:ServiceProvider)", dom)); assertEquals("0", xpath.evaluate("count(//ows:OperationsMetadata)", dom)); // this one is mandatory, cannot be skipped assertEquals("1", xpath.evaluate("count(//ogc:Filter_Capabilities)", dom)); assertTrue(xpath.getMatchingNodes("//ows:OperationsMetadata/ows:Operation", dom).getLength() == 0); assertEquals("0", xpath.evaluate("count(//ows:Operation)", dom)); }
protected void checkOws11Exception(Document dom) throws Exception { assertEquals("ServiceExceptionReport", dom.getFirstChild().getNodeName()); assertEquals("1.2.0", dom.getFirstChild().getAttributes().getNamedItem("version") .getNodeValue()); assertXpathEvaluatesTo("1.2.0", "/ServiceExceptionReport/@version", dom); Node root = xpath.getMatchingNodes("/ServiceExceptionReport", dom).item(0); assertNotNull(root); }
void assertSchema(Document doc, QName... types) throws Exception { assertEquals("xsd:schema", doc.getDocumentElement().getNodeName()); XMLAssert.assertXpathExists("//xsd:import[@namespace='" + GML.NAMESPACE + "']", doc); for (QName type : types) { String eName = type.getLocalPart(); String tName = eName + "Type"; XMLAssert.assertXpathEvaluatesTo( "1", "count(//xsd:complexType[@name='" + tName + "'])", doc); XMLAssert.assertXpathEvaluatesTo( "1", "count(//xsd:element[@name='" + eName + "'])", doc); } }
@Test public void testGetAllByDataStore() throws Exception { // two stores to play with addPropertyDataStore(true); addGeomlessPropertyDataStore(true); Document dom = getAsDOM(BASEPATH + "/workspaces/gs/datastores/pds/featuretypes.xml"); assertEquals(2, dom.getElementsByTagName("featureType").getLength()); assertXpathEvaluatesTo("1", "count(//featureType/name[text()='pdsa'])", dom); assertXpathEvaluatesTo("1", "count(//featureType/name[text()='pdsb'])", dom); }
@Test public void testDescribeUnknownCoverageKvp() throws Exception { Document dom = getAsDOM( BASEPATH + "?request=DescribeCoverage&service=WCS&version=1.0.0&coverage=plop"); // print(dom); checkOws11Exception(dom); Element element = (Element) dom.getElementsByTagName("ServiceException").item(0); assertEquals("InvalidParameterValue", element.getAttribute("code")); assertEquals("coverage", element.getAttribute("locator")); assertTrue(element.getTextContent().contains("plop")); }
@Test public void testPostBasic() throws Exception { Document dom = postAsDOM(BASEPATH + "?service=csw&version=2.0.2&request=GetCapabilities"); // print(dom); checkValidationErrors(dom); // basic check on local name Element e = dom.getDocumentElement(); assertEquals("Capabilities", e.getLocalName()); // basic check on xpath node assertXpathEvaluatesTo("1", "count(/csw:Capabilities)", dom); assertTrue(xpath.getMatchingNodes("//ows:OperationsMetadata/ows:Operation", dom) .getLength() > 0); assertEquals("5", xpath.evaluate("count(//ows:Operation)", dom)); // basic check on GetCapabilities operation constraint assertEquals( "XML", xpath.evaluate( "//ows:OperationsMetadata/ows:Operation[@name=\"GetCapabilities\"]/ows:Constraint/ows:Value", dom)); }
@Test public void testDescribeMissingVersion() throws Exception { Document dom = getAsDOM( BASEPATH + "?request=DescribeCoverage&service=WCS&coverage=" + getLayerId(TASMANIA_DEM)); // print(dom); checkOws11Exception(dom); Element element = (Element) dom.getElementsByTagName("ServiceException").item(0); assertEquals("MissingParameterValue", element.getAttribute("code")); assertEquals("version", element.getAttribute("locator")); }
@Test public void testSkipMisconfigured() throws Exception { // enable skipping of misconfigured layers GeoServerInfo global = getGeoServer().getGlobal(); global.setResourceErrorHandling(ResourceErrorHandling.SKIP_MISCONFIGURED_LAYERS); getGeoServer().save(global); // manually misconfigure one layer CoverageStoreInfo cvInfo = getCatalog().getCoverageStoreByName(MockData.TASMANIA_DEM.getLocalPart()); cvInfo.setURL("file:///I/AM/NOT/THERE"); getCatalog().save(cvInfo); Document dom = getAsDOM(BASEPATH + "?request=DescribeCoverage&service=WCS&version=1.0.0"); checkValidationErrors(dom, WCS10_DESCRIBECOVERAGE_SCHEMA); int count = getCatalog().getCoverages().size(); assertEquals(count - 1, dom.getElementsByTagName("wcs:CoverageOffering").getLength()); }
public void testEncode() throws Exception { Document dom = encode(GML3MockData.polygon(), GML.Polygon); assertEquals("gml:Polygon", dom.getDocumentElement().getNodeName()); XMLAssert.assertXpathExists("/gml:Polygon/gml:exterior", dom); XMLAssert.assertXpathExists("/gml:Polygon/gml:exterior/gml:LinearRing", dom); } }
@Test public void testGetLocalAsXML() throws Exception { Document dom = getAsDOM(RestBaseController.ROOT_PATH + "/workspaces/sf/settings.xml"); assertEquals("settings", dom.getDocumentElement().getLocalName()); assertXpathEvaluatesTo("sf", "/settings/workspace/name", dom); assertXpathEvaluatesTo("UTF-8", "/settings/charset", dom); assertXpathEvaluatesTo("8", "/settings/numDecimals", dom); assertXpathEvaluatesTo("false", "/settings/verbose", dom); assertXpathEvaluatesTo("false", "/settings/verboseExceptions", dom); assertXpathEvaluatesTo("Andrea Aime", "/settings/contact/contactPerson", dom); }
/** Do some spot checks on the KML generated when an overlay hierarchy is requested. */ @Test public void testSuperOverlayReflection() throws Exception { final String layerName = MockData.BASIC_POLYGONS.getPrefix() + ":" + MockData.BASIC_POLYGONS.getLocalPart(); final String requestUrl = "wms/kml?layers=" + layerName + "&styles=&mode=superoverlay"; Document dom = getAsDOM(requestUrl); // print(dom); assertEquals("kml", dom.getDocumentElement().getLocalName()); assertXpathExists("kml:kml/kml:Document/kml:Folder/kml:NetworkLink/kml:Link/kml:href", dom); assertXpathExists("kml:kml/kml:Document/kml:LookAt/kml:longitude", dom); }
private void runTest(Document dom1, Document dom2, MathTransform tx) throws Exception { Element box = getFirstElementByTagName(dom1.getDocumentElement(), "gml:Box"); Element coordinates = getFirstElementByTagName(box, "gml:coordinates"); double[] d1 = coordinates(coordinates.getFirstChild().getNodeValue()); box = getFirstElementByTagName(dom2.getDocumentElement(), "gml:Box"); coordinates = getFirstElementByTagName(box, "gml:coordinates"); double[] d2 = coordinates(coordinates.getFirstChild().getNodeValue()); double[] d3 = new double[d1.length]; tx.transform(d1, 0, d3, 0, d1.length / 2); for (int i = 0; i < d2.length; i++) { assertEquals(d2[i], d3[i], 0.001); } }