/** * Assert that a specific XPath exists in some given XML * @param xPathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ public static void assertXpathExists(String xPathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); NodeList nodeList = simpleXpathEngine.getMatchingNodes( xPathExpression, inDocument); int matches = nodeList.getLength(); assertTrue("Expecting to find matches for Xpath " + xPathExpression, matches > 0); }
/** * Assert that a specific XPath exists in some given XML * @param inXpathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ public static void assertXpathExists(String xPathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); NodeList nodeList = simpleXpathEngine.getMatchingNodes( xPathExpression, inDocument); int matches = nodeList.getLength(); assertTrue("Expecting to find matches for Xpath " + xPathExpression, matches > 0); }
@Test public void testDTDLocation() throws Exception { final String expected = "!DOCTYPE WMS_DescribeLayerResponse SYSTEM \"http://geoserver.org/schemas/wms/1.1.1/WMS_DescribeLayerResponse.dtd\""; transformer = new DescribeLayerTransformer("http://geoserver.org"); StringWriter writer = new StringWriter(); transformer.transform(request, writer); assertTrue(writer.getBuffer().indexOf(expected) > 0); }
@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 testDescribeUnknownCoverageXml() throws Exception { List<Exception> errors = new ArrayList<Exception>(); String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + // "<wcs:DescribeCoverage service=\"WCS\" " + // "xmlns:ows=\"http://www.opengis.net/ows/1.1\"\r\n" + // " xmlns:wcs=\"http://www.opengis.net/wcs\"\r\n" + // " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \r\n" + // " version=\"1.0.0\" >\r\n" + // " <wcs:Coverage>plop</wcs:Coverage>\r\n" + // "</wcs:DescribeCoverage>"; Document dom = postAsDOM(BASEPATH, request, errors); // 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 testXMLReaderInvalid() throws Exception { // create a schema invalid request String capRequest = getResourceAsString("GetCapabilities.xml"); capRequest = capRequest.replace("ows:Sections", "ows:foo"); try { CSWXmlReader reader = new CSWXmlReader("GetCapabilities", "2.0.2", new CSWConfiguration()); reader.read(null, new StringReader(capRequest), (Map) null); fail("the parsing should have failed, the document is invalid"); } catch (ServiceException e) { // it is a validation exception right? assertTrue(e.getCause() instanceof SAXParseException); SAXParseException cause = (SAXParseException) e.getCause(); assertTrue(cause.getMessage().contains("ows:foo")); } }
assertTrue(offsets[0] < 0); assertTrue(offsets[1] > 0); assertTrue(offsets[2] > 0); assertTrue(offsets[3] > 0);
offsets[i] = Double.parseDouble(offsetStrsHigh[i - 2]); assertTrue(offsets[0] > 0); assertEquals(0.0, offsets[1]); assertEquals(0.0, offsets[2]); assertTrue(offsets[3] < 0);
offsets[i] = Double.parseDouble(offsetStrsHigh[i - 2]); assertTrue(offsets[0] > 0); assertEquals(0.0, offsets[1]); assertEquals(0.0, offsets[2]); assertTrue(offsets[3] < 0);
@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)); }
assertTrue(filter instanceof Not); Filter negated = ((Not) filter).getFilter(); assertTrue(negated instanceof PropertyIsEqualTo); PropertyName pname = (PropertyName) ((PropertyIsEqualTo) negated).getExpression1(); assertEquals("dc:title", pname.getPropertyName());
@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)); }
@Test public void testGetBasic() throws Exception { Document dom = getAsDOM(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)); // check we have csw:AnyText among the queriables assertXpathEvaluatesTo("1", "count(//ows:Operation[@name='GetRecords']/ows:Constraint[@name='SupportedDublinCoreQueryables' and ows:Value = 'csw:AnyText'])", dom); // check we have dc:subject among the domain property names assertXpathEvaluatesTo("1", "count(//ows:Operation[@name='GetDomain']/ows:Parameter[@name='PropertyName' and ows:Value = 'dc:title'])", dom); }
@Test public void testPreconditions() throws TransformerException { try { new DescribeLayerTransformer(null); Assert.fail("expected NPE on null base url"); } catch (NullPointerException e) { Assert.assertTrue(true); } transformer = new DescribeLayerTransformer("http://geoserver.org"); try { transformer.transform(null); Assert.fail("expected IAE on null request"); } catch (TransformerException e) { Assert.assertTrue(e.getCause() instanceof IllegalArgumentException); } try { transformer.transform(new Object()); fail("expected IAE on argument non a DescribeLayerRequest instance"); } catch (TransformerException e) { assertTrue(e.getCause() instanceof IllegalArgumentException); } }