@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()); }
@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())); } }
/** * Compare XML documents provided by two Reader classes * @param control Control document * @param test Document to test * @return Diff object describing differences in documents * @throws SAXException * @throws IOException */ public Diff compareXML(String control, Reader test) throws SAXException, IOException { return XMLUnit.compareXML(control, test); }
/** * Compare two XML documents provided as strings * @param control Control document * @param test Document to test * @return Diff object describing differences in documents * @throws SAXException * @throws IOException */ public Diff compareXML(String control, String test) throws SAXException, IOException { return XMLUnit.compareXML(control, test); }
/** * Compare two XML documents provided as strings * @param control Control document * @param test Document to test * @return Diff object describing differences in documents */ public Diff compareXML(Document control, Document test) { return XMLUnit.compareXML(control, test); }
/** * Compare XML documents provided by two InputSource classes * @param control Control document * @param test Document to test * @return Diff object describing differences in documents * @throws SAXException * @throws IOException */ public Diff compareXML(InputSource control, InputSource test) throws SAXException, IOException { return XMLUnit.compareXML(control, test); }
/** * Compare XML documents provided by two Reader classes * @param control Control document * @param test Document to test * @return Diff object describing differences in documents * @throws SAXException * @throws IOException */ public Diff compareXML(Reader control, Reader test) throws SAXException, IOException { return XMLUnit.compareXML(control, test); }
/** * Compare two XML documents provided as strings * @param control Control document * @param test Document to test * @return Diff object describing differences in documents */ public Diff compareXML(Document control, Document test) { return XMLUnit.compareXML(control, test); }
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()); } }
/** * Compare XML documents provided by two Reader classes * @param control Control document * @param test Document to test * @return Diff object describing differences in documents * @throws SAXException * @throws IOException */ public Diff compareXML(String control, Reader test) throws SAXException, IOException { return XMLUnit.compareXML(new StringReader(control), test); }
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); } }
protected void assertThatXmlHaveNoDifferences(final String xmlPrettyFormatExpected, final String xmlPrettyFormatExported) throws SAXException, IOException { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreAttributeOrder(true); final DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(xmlPrettyFormatExported, xmlPrettyFormatExpected)); final List<?> allDifferences = diff.getAllDifferences(); assertThat(allDifferences).as("should have no differences between:\n%s\n and:\n%s\n", xmlPrettyFormatExpected, xmlPrettyFormatExported).isEmpty(); }
@SuppressWarnings("unchecked") private static DetailedDiff getDiff(StringWriter objectXML, StringBuilder exampleXML) throws SAXException, IOException { DetailedDiff myDiff = new DetailedDiff(XMLUnit.compareXML(exampleXML.toString(), objectXML.toString())); List<Difference> allDifferences = myDiff.getAllDifferences(); if (allDifferences.size() > 0) { for (Difference d : allDifferences) { System.err.println(d); } } return myDiff; }
public static void assertSimilarXml(String expected, String result) throws Exception { XMLUnit.setIgnoreWhitespace(true); Diff diff = compareXML(result, expected); if (!diff.similar()) { System.out.println("Expected xml is:\n"); System.out.println(prettyPrint(expected)); System.out.println("########################################\n"); System.out.println("But got:\n"); System.out.println(prettyPrint(result)); } assertThat(diff.similar(), is(true)); }
@Test public void zapSimple() throws IOException, SAXException { String zapResult = transformer.zap(source("/xquery/string.xml"), "/xquery/string-q1.xq"); assertTrue(XMLUnit.compareXML(result("/xquery/string-q1.xml"), zapResult).similar()); }
@Test public void zapMainFunction() throws IOException, SAXException { String zapResult = transformer.zap(source("/xquery/string.xml"), "/xquery/string-q4.xq"); assertTrue(XMLUnit.compareXML(result("/xquery/string.xml"), zapResult).similar()); }
@Test public void zapClasspathResolver() throws IOException, SAXException { String zapResult = transformer.zap(source("/xquery/string.xml"), "/xquery/string-q5.xq"); assertTrue(XMLUnit.compareXML(result("/xquery/string.xml"), zapResult).similar()); }
@Test public void zapParametrisedConstructorNoParams() throws IOException, SAXException, XQException { XqjTransmogrifier<String> localTransformer = new XqjTransmogrifier<>(String.class); String zapResult = localTransformer.zap(source("/xquery/string.xml"), "/xquery/string-q5.xq"); assertTrue(XMLUnit.compareXML(result("/xquery/string.xml"), zapResult).similar()); }