Refine search
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); } }
Diff diff = new Diff(original, result); sequenceDoesNotMatter.add("endEvent"); sequenceDoesNotMatter.add("bpmndi:BPMNShape"); diff.overrideDifferenceListener(new DifferenceListener() { diff.overrideElementQualifier(new ElementNameAndAttributeQualifier()); assertTrue("Original and generated output is not the same.", diff.identical());
Diff diff = new Diff(original, result); diff.overrideDifferenceListener(new DifferenceListener() { assertTrue("Original and generated output is not the same.", diff.identical());
public void testIdenticalAndSimilar() throws Exception { String controlXML = "<account><id>3A-00</id><name>acme</name></account>"; String testXML = "<account><name>acme</name><id>3A-00</id></account>"; Diff diff = new Diff(controlXML, testXML); assertTrue(diff.similar()); assertFalse(diff.identical()); }
/** * Assert that two XML documents are similar * @param err Message to be displayed on assertion failure * @param control XML to be compared against * @param test XML to be tested */ public static void assertXMLEqual(String err, Document control, Document test) { Diff diff = new Diff(control, test); assertXMLEqual(err, diff, true); }
private static void doAssertXmlEquals(String expectedXml, String actualXml) throws Exception { Diff diff = new Diff(expectedXml, actualXml); diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); if (!diff.similar()) { fail(String.format("\nExpected the following XML\n" + formatXml(expectedXml) + "\nbut actual XML was\n\n" + formatXml(actualXml))); } }
public void testCompareToSkeletonXML() throws Exception { String myControlXML = "<location><street-address>22 any street</street-address><postcode>XY00 99Z</postcode></location>"; String myTestXML = "<location><street-address>20 east cheap</street-address><postcode>EC3M 1EB</postcode></location>"; DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); Diff myDiff = new Diff(myControlXML, myTestXML); myDiff.overrideDifferenceListener(myDifferenceListener); assertTrue("test XML matches control skeleton XML " + myDiff, myDiff.similar()); }
public static void main(String[] args) throws Exception { String xml1="<Akash><status>COMPLETE</status>" +"<startedTime>23</startedTime></Akash>"; String xml2="<Akash><status>COMPLETE</status><startedTime></startedTime></Akash>"; XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(xml1,xml2); diff.overrideElementQualifier(new ElementNameAndTextQualifier()); assertTrue("XML similar " + diff.toString(), diff.similar()); }
InputSource inputSource1 = new InputSource(fileStream1); InputSource inputSource2 = new InputSource(fileStream2); Diff diff = new Diff(inputSource1, inputSource2); diff.overrideDifferenceListener(new IgnoreAttributeDifference()); System.out.println("identical: " + diff.identical()); System.out.println("similar : " + diff.similar());
protected void checkXmlStructure(String xmlunitPage, String pageCode) throws SAXException, IOException { InputStream expectedPageCode = testClass.get().getJavaClass().getResourceAsStream(xmlunitPage); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); Diff xmlDiff = new Diff(new InputStreamReader(expectedPageCode), new StringReader(pageCode)); xmlDiff.overrideDifferenceListener(getDifferenceListener()); if (!xmlDiff.similar()) { System.out.println("=== ACTUAL PAGE CODE ==="); System.out.println(pageCode); System.out.println("======== ERROR ========="); System.out.println(xmlDiff.toString()); System.out.println("========================"); fail("XML was not similar:" + xmlDiff.toString()); } }
throws SAXException, IOException { Diff myDiff = new Diff(control, test); myDiff.overrideDifferenceListener(new DifferenceListener() { @Override public int differenceFound(Difference difference) { Diff innerDiff = new Diff( difference.getControlNodeDetail().getValue(), difference.getTestNodeDetail().getValue()); assertXMLEqual(myDiff, true);
public static boolean compareXMLs(String xmlSource, String xmlCompareWith) throws Exception { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setNormalizeWhitespace(true); Diff myDiff = new Diff(xmlSource, xmlCompareWith); myDiff.similar() }
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setCompareUnmatched(false); Diff diff = new Diff(expectedPayload, xmlPayload); diff.overrideElementQualifier(new ElementNameQualifier() { @Override public boolean qualifyForComparison(Element control, Element test) { diff.overrideDifferenceListener(new DifferenceListener() { @Override public void skippedComparison(Node control, Node test) { XMLAssert.assertXMLEqual(null, diff, true); } catch (Error e) { System.out.println("--- START FAILED XML PAYLOAD ---");
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()); } } }
@Override protected void validate() { try { URL u = new URL(url); InputStream urlStream = u.openStream(); String actual = FileUtil.readToString(urlStream); String e = replaceVariableContent(expected); String a = replaceVariableContent(actual); //DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); //myDiff.overrideDifferenceListener(myDifferenceListener); Diff myDiff = new Diff(e, a); assertTrue("check http results XML identical " + myDiff, myDiff.identical()); //assertEquals("Check http results", e, a); } catch (Exception e) { fail("Failed to connect or download \n" + e); } } }.await(20);
public static boolean isEquivalent(InputStream is1, InputStream is2) { try { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreWhitespace(true); Diff diff = XMLUnit.compareXML(new InputStreamReader(is1), new InputStreamReader(is2)); diff.overrideDifferenceListener(new IgnoreIrrelevantNodesDifferenceListener() { @Override protected boolean isIrrelevantChildNode(Node node) { return false; } @Override protected boolean isIrrelevantAttribute(Attr att) { return (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(att.getNamespaceURI())) || (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI.equals(att .getNamespaceURI())); } }); if (!diff.identical()) { System.err.println(new DetailedDiff(diff)); } return diff.identical(); } catch (SAXException se) { throw new UncheckedException(se); } catch (IOException ioe) { throw new UncheckedException(ioe); } }
@Test(dataProvider = "DocData") public void testSpellout(String tokenised, String expected) throws Exception { Document tokenisedDoc; Document expectedDoc; String tokens = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\" xml:lang=\"fr\"><p><s><t>" + tokenised + "</t></s></p></maryxml>"; tokenisedDoc = DomUtils.parseDocument(tokens); String words = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\" xml:lang=\"fr\"><p><s><mtu orig=\"" + tokenised + "\"><t>" + expected + "</t></mtu></s></p></maryxml>"; expectedDoc = DomUtils.parseDocument(words); module.checkForNumbers(tokenisedDoc); Diff diff = XMLUnit.compareXML(expectedDoc, tokenisedDoc); Assert.assertTrue(diff.identical()); }