@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()); }
@Test public void testOneWord() throws SynthesisException, ParserConfigurationException, SAXException, IOException, ParseException, MaryConfigurationException { String lemma = "7"; mary.setOutputType(MaryDataType.WORDS.name()); Document doc = mary.generateXML(lemma); String words = "<maryxml xmlns=\"http://mary.dfki.de/2002/MaryXML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"0.5\"><p><s><t>" + lemma + "</t></s></p></maryxml>"; Document expectedDoc = DomUtils.parseDocument(words); module.expand(expectedDoc); Diff diff = XMLUnit.compareXML(expectedDoc, doc); // issue where LocalMaryInterface#generateXML and DomUtils#parseDocument dont build the document in same order Assert.assertFalse(diff.identical()); }
assertTrue("Original and generated output is not the same.", diff.identical());
assertTrue("Original and generated output is not the same.", diff.identical());
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()); } } }
/** * Receives to {@link String} representation of two XML files and verify that they are semantically equivalent * * @param expected the reference content * @param actual the actual content * @throws Exception if comparison fails */ public static void compareXML(String expected, String actual) throws Exception { XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.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()); } }
String refXmlPaht = "../test1.xml"; String testXmlPaht = "../test2.xml"; Document doc1 = TransformXML.convertXmlToDom(refXmlPaht); Document doc2 = TransformXML.convertXmlToDom(testXmlPaht); Diff myDiff = new Diff(doc1, doc2); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreAttributeOrder(true); assertXMLEqual("pieces of XML are not similar ", myDiff, true); assertTrue("but are they identical? " + myDiff, myDiff.identical());
Diff diff = new Diff(sourceXml, compareXml); if (diff.identical()) { // whatever you want to do }
@Override protected boolean equalsInternal(ObjectLocator leftLocator, ObjectLocator rightLocator, Node lhs, Node rhs) { final Diff diff = new Diff(new DOMSource(lhs), new DOMSource(rhs)) { @Override public int differenceFound(Difference difference) { if (difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) { return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } else { return super.differenceFound(difference); } } }; return diff.identical(); }
String control = "<prefix1:element xmlns:prefix1=\"namespace\" prefix1:attribute=\"x\">Some text</prefix1:element>"; String test = "<prefix2:element xmlns:prefix2=\"namespace\" prefix2:attribute=\"x\">Some text</prefix2:element>"; try { Diff diff = XMLUnit.compareXML( control, test ); assertTrue( "Similar", diff.similar() ); assertTrue( "Identical", diff.identical() ); } catch ( Exception e ) { fail( e.getMessage() ); }
public void testIdentical() throws Exception { String myControlXML = "<struct><int>3</int><boolean>false</boolean></struct>"; String myTestXML = "<struct><boolean>false</boolean><int>3</int></struct>"; Diff myDiff = new Diff(myControlXML, myTestXML); assertTrue("pieces of XML are similar " + myDiff, myDiff.similar()); assertTrue("but are they identical? " + myDiff, myDiff.identical()); }
public static boolean isIdenticalNormalizedWithoutValues(String expected, String current) { String expectedProcessed = normalizeAndRemoveValues(expected); String currentProcessed = normalizeAndRemoveValues(current); try { return XMLUnit.compareXML(expectedProcessed, currentProcessed).identical(); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Assert that the result of an XML comparison is or is not identical * @param msg Message to display if assertion fails * @param diff the result of an XML comparison * @param assertion true if asserting that result is identical */ public static void assertXMLIdentical(String msg, Diff diff, boolean assertion) { if (assertion != diff.identical()) { fail(getFailMessage(msg, diff)); } }
/** * Assert that the result of an XML comparison is or is not identical * @param msg Message to display if assertion fails * @param diff the result of an XML comparison * @param assertion true if asserting that result is identical */ public static void assertXMLIdentical(String msg, Diff diff, boolean assertion) { if (assertion != diff.identical()) { fail(getFailMessage(msg, diff)); } }
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()); }
@Override protected boolean matchesSafely(String item) { try { Diff diff = XMLUnit.compareXML(xml, item); return diff.identical(); } catch (IOException e) { throw new RuntimeAssertionFailure("Failed to compare XML", e); } catch (SAXException e) { throw new RuntimeAssertionFailure("Failed to compare XML", e); } }
@Override protected boolean matchesSafely(String item) { try { Diff diff = XMLUnit.compareXML(xml, item); return diff.identical(); } catch (IOException e) { throw new RuntimeAssertionFailure("Failed to compare XML", e); } catch (SAXException e) { throw new RuntimeAssertionFailure("Failed to compare XML", e); } }
public void assertIdenticalXML(String XML1, String XML2) throws Exception { Diff myDiff = new Diff(XML1, XML2); assertTrue("XML similar " + myDiff.toString(), myDiff.identical()); }
@Override public boolean matchesSafely(Source source) { String test = convertToString(source); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setNormalize(true); XMLUnit.setNormalizeWhitespace(true); try { return new Diff(control, test).identical(); } catch (SAXException e) { return false; } catch (IOException e) { return false; } }
@Override protected boolean checkEqualValues(Field field) { if (getValue().equals(field.getValue())) { return true; } else { try { XMLUnit.setIgnoreWhitespace(true); return XMLUnit.compareXML((String) getValue(), (String) field.getValue()).identical(); } catch (Exception e) { return false; } } } }