public void setUp() throws Exception { super.setUp(); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); setErrorMessage(null); }
public PomAssert(String content) { this.content = content; this.eng = XMLUnit.newXpathEngine(); Map<String, String> context = new LinkedHashMap<>(); context.put("pom", "http://maven.apache.org/POM/4.0.0"); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(context); this.eng.setNamespaceContext(namespaceContext); try { this.doc = XMLUnit.buildControlDocument(content); } catch (Exception ex) { throw new IllegalArgumentException("Cannot parse XML", ex); } this.parentPom = parseParent(); parseProperties(); parseDependencies(); parseBoms(); parseRepositories(); }
@Override protected void setUp() throws Exception { super.setUp(); Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("test", TEST.TestFeature.getNamespaceURI()); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); }
@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 testWorkspaceQualified() throws Exception { Document dom = dom(get("cite/wms?request=getCapabilities&version=1.1.1"), true); Element e = dom.getDocumentElement(); assertEquals("WMT_MS_Capabilities", e.getLocalName()); XpathEngine xpath = XMLUnit.newXpathEngine(); assertEquals( 0, xpath.getMatchingNodes("//Layer/Name[starts-with(., 'cite')]", dom).getLength()); assertTrue( xpath.getMatchingNodes("//Layer/Name[not(starts-with(., 'cite'))]", dom).getLength() > 0); NodeList nodes = xpath.getMatchingNodes("//Layer//OnlineResource", dom); assertTrue(nodes.getLength() > 0); for (int i = 0; i < nodes.getLength(); i++) { e = (Element) nodes.item(i); String attribute = e.getAttribute("xlink:href"); assertTrue(attribute.contains("geoserver/cite/wms")); } }
@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); }
public void testEncodeSimple() throws Exception { LineString curve = new CurvedGeometryFactory(0.1) .createCurvedGeometry( new LiteCoordinateSequence( new double[] {1, 1, 2, 2, 3, 1, 5, 5, 7, 3})); Document dom = encode(curve, GML.curveProperty); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String basePath = "/gml:curveProperty/gml:Curve/gml:segments/gml:ArcString"; assertEquals( 1, xpath.getMatchingNodes(basePath + "[@interpolation='circularArc3Points']", dom) .getLength()); assertEquals("1 1 2 2 3 1 5 5 7 3", xpath.evaluate(basePath + "/gml:posList", dom)); }
public void testAnonymousCapabilities() throws Exception { Document doc = getAsDOM("wms?request=GetCapabilities&version=1.1.0"); // print(doc); // check we have the sf layers, but not the cite ones not the cdf ones XpathEngine engine = XMLUnit.newXpathEngine(); assertTrue(engine.getMatchingNodes("//Layer/Name[starts-with(text(), 'sf:')]", doc) .getLength() > 1); assertEquals(0, engine.getMatchingNodes("//Layer/Name[starts-with(text(), 'cite:')]", doc) .getLength()); assertEquals(0, engine.getMatchingNodes("//Layer/Name[starts-with(text(), 'cdf:')]", doc) .getLength()); }
/** * 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); }
public void testReferenceOutputKVP() throws Exception { String request = "wps?service=WPS&version=1.0.0&request=Execute&Identifier=gs:BufferFeatureCollection" + "&DataInputs=" + urlEncode("features=" + readFileIntoString("states-FeatureCollection.xml") + "@mimetype=application/wfs-collection-1.1;distance=10") + "&ResponseDocument=" + urlEncode("result=@asReference=true"); Document d = getAsDOM(request); // print(d); // check we got a valid response with the document as a reference checkValidationErrors(d); assertEquals( "wps:ExecuteResponse", d.getDocumentElement().getNodeName() ); assertXpathExists("/wps:ExecuteResponse/wps:Status/wps:ProcessSucceeded", d); assertXpathExists("/wps:ExecuteResponse/wps:ProcessOutputs/wps:Output/wps:Reference", d); XpathEngine xpath = XMLUnit.newXpathEngine(); String fullLocation = xpath.evaluate("/wps:ExecuteResponse/wps:ProcessOutputs/wps:Output/wps:Reference/@href", d); String resourceLocation = fullLocation.substring(fullLocation.indexOf('?') - 3); MockHttpServletResponse response = getAsServletResponse(resourceLocation); assertEquals("text/xml; subtype=wfs-collection/1.0", response.getContentType()); d = dom(new ByteArrayInputStream( response.getOutputStreamContent().getBytes())); assertXpathExists("wfs:FeatureCollection", d); }
@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.*")); }
@Override public void setUp() throws Exception { super.setUp(); XMLUnit.setIgnoreComments( true ); XMLUnit.setIgnoreWhitespace( true ); XMLUnit.setIgnoreAttributeOrder( true ); XMLUnit.setNormalizeWhitespace( true ); XMLUnit.setNormalize( true ); }
@Override protected void oneTimeSetUp() throws Exception { super.oneTimeSetUp(); Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("html", "http://www.w3.org/1999/xhtml"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); xp = XMLUnit.newXpathEngine(); }
public void testEncodePointWithDecimals() throws Exception { Geometry geometry = new WKTReader().read("POINT(1.234 5.678)"); Document dom = encode(geometry, GML.geometryMember); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); assertEquals("1.23 5.68", xpath.evaluate("/gml:geometryMember/gml:Point/gml:pos", dom)); } }
private void compareXML(String expected, String actual) throws Exception { setNormalizeWhitespace(true); setIgnoreWhitespace(true); setIgnoreComments(true); setIgnoreAttributeOrder(false); Diff diff = XMLUnit.compareXML(expected, actual); if (!(diff.similar() && diff.identical())) { System.out.println(actual); DetailedDiff detDiff = new DetailedDiff(diff); @SuppressWarnings("rawtypes") List differences = detDiff.getAllDifferences(); StringBuilder diffLines = new StringBuilder(); for (Object object : differences) { Difference difference = (Difference) object; diffLines.append(difference.toString() + '\n'); } throw new IllegalArgumentException("Actual XML differs from expected: \n" + diffLines.toString()); } } }
private void configureXmlUnit() { XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setCompareUnmatched(false); XMLUnit.setIgnoreAttributeOrder(true); }
@Override public boolean matches(Object item) { XpathEngine engine = XMLUnit.newXpathEngine(); engine.setNamespaceContext(namespaceContext); try { List<Node> nodes = nodeCollection(engine.getMatchingNodes(xPath, (Document) item)); return matcher.matches(nodes); } catch (XpathException e) { return false; } }
@Test public void generate() throws Exception { GeneratedResource resource = resourceFactory.generateResource(extensionModel).get(); assertThat(resource.getPath(), equalTo(RESOURCE_NAME)); XMLUnit.setIgnoreWhitespace(true); String expected = IOUtils.toString(currentThread().getContextClassLoader().getResource(RESOURCE_NAME).openStream()); XMLUnit.compareXML(expected, new String(resource.getContent())); } }
public static void initXmlUnit() { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setNormalize(true); }
private String submitMonkey(String id) throws Exception, XpathException { String request = "wps?service=WPS&version=1.0.0&request=Execute&Identifier=gs:Monkey&storeExecuteResponse=true&status=true&DataInputs=" + urlEncode("id=" + id); Document dom = getAsDOM(request); assertXpathExists("//wps:ProcessAccepted", dom); XpathEngine xpath = XMLUnit.newXpathEngine(); String fullStatusLocation = xpath.evaluate("//wps:ExecuteResponse/@statusLocation", dom); String statusLocation = fullStatusLocation.substring(fullStatusLocation.indexOf('?') - 3); return statusLocation; }