/** * Assert that a specific XPath does NOT exist in some given XML * @param inXpathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ public static void assertXpathNotExists(String xPathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); NodeList nodeList = simpleXpathEngine.getMatchingNodes( xPathExpression, inDocument); int matches = nodeList.getLength(); assertEquals("Should be zero matches for Xpath " + xPathExpression, 0, matches); }
/** * Assert that a Validator instance returns <code>isValid() == true</code> * @param validator */ public static void assertXMLValid(Validator validator) { assertEquals(validator.toString(), true, validator.isValid()); }
/** * Assert that a Validator instance returns <code>isValid() == true</code> * @param validator */ public static void assertXMLValid(Validator validator) { assertEquals(validator.toString(), true, validator.isValid()); }
/** * Assert that a specific XPath does NOT exist in some given XML * @param xPathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ public static void assertXpathNotExists(String xPathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); NodeList nodeList = simpleXpathEngine.getMatchingNodes( xPathExpression, inDocument); int matches = nodeList.getLength(); assertEquals("Should be zero matches for Xpath " + xPathExpression, 0, matches); }
/** * Assert the value of an Xpath expression in an DOM Document * @param expectedValue * @param xpathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ public static void assertXpathEvaluatesTo(String expectedValue, String xpathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); assertEquals(expectedValue, simpleXpathEngine.evaluate(xpathExpression, inDocument)); }
/** * Assert the value of an Xpath expression in an DOM Document * @param expectedValue * @param xpathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ public static void assertXpathEvaluatesTo(String expectedValue, String xpathExpression, Document inDocument) throws XpathException { XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine(); assertEquals(expectedValue, simpleXpathEngine.evaluate(xpathExpression, inDocument)); }
private void assertGetRecordByIdValid(GetRecordByIdType dr) { assertEquals("CSW", dr.getService()); assertEquals("2.0.2", dr.getVersion()); assertEquals(ElementSetType.SUMMARY, dr.getElementSetName().getValue()); assertEquals("REC-10", dr.getId().get(0).toString()); assertEquals("REC-11", dr.getId().get(1).toString()); assertEquals("REC-12", dr.getId().get(2).toString()); }
/** * Assert that the evaluation of two Xpaths in two documents are equal * @param xpathOne * @param xpathTwo * @param document * @see XpathEngine */ public static void assertXpathValuesEqual(String controlXpath, Document controlDocument, String testXpath, Document testDocument) throws XpathException { XpathEngine xpath = XMLUnit.newXpathEngine(); assertEquals(xpath.evaluate(controlXpath, controlDocument), xpath.evaluate(testXpath, testDocument)); }
@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 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 the root element name and version attribute. * * <p>This test does not set a requested layer to the request and {@link * DescribeLayerTransformer} does not care since checking the mandatory arguments shall be done * prior to using the transformer, so it'll return an empty root element in this case. */ @Test public void testRootElement() throws Exception { transformer = new DescribeLayerTransformer("http://geoserver.org"); Document dom = WMSTestSupport.transform(request, transformer); Element root = dom.getDocumentElement(); assertEquals("WMS_DescribeLayerResponse", root.getNodeName()); assertEquals("1.1.1", root.getAttribute("version")); }
@Test public void testJSON() throws Exception { Map map = new HashMap(); map.put("name", "bomb"); map.put("price", 12.99); ByteArrayOutputStream bout = new ByteArrayOutputStream(); new MapJSONPPIO().encode(map, bout); JSON json = JSONSerializer.toJSON(new String(bout.toByteArray())); JSONObject obj = (JSONObject) json; assertEquals("bomb", obj.getString("name")); assertEquals(12.99, obj.getDouble("price"), 0.1); }
@Test public void testKVPParameter() throws Exception { Map<String, Object> raw = new HashMap<String, Object>(); raw.put("service", "CSW"); raw.put("version", "2.0.2"); raw.put("request", "GetDomain"); raw.put("parameterName", "GetRecords.resultType"); GetDomainKvpRequestReader reader = new GetDomainKvpRequestReader(); Object request = reader.createRequest(); GetDomainType gd = (GetDomainType) reader.read(request, parseKvp(raw), raw); assertEquals("CSW", gd.getService()); assertEquals("2.0.2", gd.getVersion()); assertEquals("GetRecords.resultType", gd.getParameterName()); }
@Test public void testKVPProperty() throws Exception { Map<String, Object> raw = new HashMap<String, Object>(); raw.put("service", "CSW"); raw.put("version", "2.0.2"); raw.put("request", "GetDomain"); raw.put("propertyName", "dc:title"); GetDomainKvpRequestReader reader = new GetDomainKvpRequestReader(); Object request = reader.createRequest(); GetDomainType gd = (GetDomainType) reader.read(request, parseKvp(raw), raw); assertEquals("CSW", gd.getService()); assertEquals("2.0.2", gd.getVersion()); assertEquals("dc:title", gd.getPropertyName()); }
@Test public void testXML() throws Exception { Map map = new HashMap(); map.put("name", "bomb"); map.put("price", 12.99); MapXMLPPIO ppio = new MapXMLPPIO(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ppio.encode(map, bout); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); Document dom = dom(bin); assertEquals("map", dom.getDocumentElement().getLocalName()); assertXpathEvaluatesTo("bomb", "/map/name", dom); assertXpathEvaluatesTo("12.99", "/map/price", dom); }
@Test public void testDescribeAll() throws Exception { Document dom = getAsDOM(BASEPATH + "?request=DescribeCoverage&service=WCS&version=1.0.0"); // print(dom); // the response is compliant checkValidationErrors(dom, WCS10_DESCRIBECOVERAGE_SCHEMA); // check all coverages have been described int count = getCatalog().getCoverages().size(); assertEquals(count, dom.getElementsByTagName("wcs:CoverageOffering").getLength()); }
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); } }
@Test public void testXMLReaderProperty() throws Exception { CSWXmlReader reader = new CSWXmlReader("GetDomain", "2.0.2", new CSWConfiguration()); GetDomainType gd = (GetDomainType) reader.read(null, getResourceAsReader("GetDomainProperty.xml"), (Map) null); assertEquals("CSW", gd.getService()); assertEquals("2.0.2", gd.getVersion()); assertEquals("dc:title", gd.getPropertyName()); }
@Test public void testXMLReaderParameter() throws Exception { CSWXmlReader reader = new CSWXmlReader("GetDomain", "2.0.2", new CSWConfiguration()); GetDomainType gd = (GetDomainType) reader.read(null, getResourceAsReader("GetDomainParameter.xml"), (Map) null); assertEquals("CSW", gd.getService()); assertEquals("2.0.2", gd.getVersion()); assertEquals("GetRecords.resultType", gd.getParameterName()); }
private void assertGMLTimestamp(String timeStamp) throws Exception { assertNotNull(timeStamp); Calendar cal = new XmlConverterFactory() .createConverter(String.class, Calendar.class, null).convert(timeStamp, Calendar.class); assertNotNull(cal); assertEquals(TimeZone.getTimeZone("GMT"), cal.getTimeZone()); }