Search in sources :

Example 31 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project camunda-dmn-model by camunda.

the class DmnModelTest method assertModelEqualsFile.

protected void assertModelEqualsFile(String expectedPath) throws Exception {
    File actualFile = tmpFolder.newFile();
    Dmn.writeModelToFile(actualFile, modelInstance);
    File expectedFile = ReflectUtil.getResourceAsFile(expectedPath);
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
    Document actualDocument = docBuilder.parse(actualFile);
    Document expectedDocument = docBuilder.parse(expectedFile);
    Diff diff = new Diff(expectedDocument, actualDocument);
    if (!diff.similar()) {
        diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
        DetailedDiff detailedDiff = new DetailedDiff(diff);
        String failMsg = "XML differs:\n" + detailedDiff.getAllDifferences() + "\n\nActual XML:\n" + Dmn.convertToString(modelInstance);
        fail(failMsg);
    }
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) RecursiveElementNameAndTextQualifier(org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier) Document(org.w3c.dom.Document) File(java.io.File)

Example 32 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.

the class XmlUtilTest method testFromURL.

@Test
public void testFromURL() throws XmlUtilException {
    Document expected = XmlUtil.newDocument();
    Element element = expected.createElement("root");
    expected.appendChild(element);
    Element child = expected.createElement("child");
    child.appendChild(expected.createTextNode("a"));
    element.appendChild(child);
    Document actual = XmlUtil.fromURL(getClass().getResource("input.xml"));
    DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expected, actual));
    Assert.assertTrue(diff.toString(), diff.similar());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.

the class DifferencesTest method testToDocumentWhenExistingDifference.

@Test
public void testToDocumentWhenExistingDifference() throws DifferencesException, XmlUtilException {
    Document actual = differences.toDocument();
    Document expected = XmlUtil.newDocument();
    Element root = expected.createElement(Differences.DIFFERENCES_NODE);
    expected.appendChild(root);
    DetailedDiff result = new DetailedDiff(XMLUnit.compareXML(expected, actual));
    Assert.assertTrue("Differences can be correctly transforms as Document when there is no differences", result.similar());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 34 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.

the class XmlUnitServiceTest method testRemoveDifferenceWhenNoDifferenceMatch.

@Test
public void testRemoveDifferenceWhenNoDifferenceMatch() throws XmlUtilException, SAXException, IOException {
    differences.addDifference(new Difference("/root[1]/a[1]"));
    differences.addDifference(new Difference("/root[1]/b[1]"));
    String actual = xmlUnitService.removeDifference("toto", differences.mkString());
    String expected = "<differences><difference>/root[1]/a[1]</difference><difference>/root[1]/b[1]</difference></differences>";
    DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expected, actual));
    Assert.assertTrue(diff.toString(), diff.similar());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 35 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project cerberus-source by cerberustesting.

the class XmlUnitServiceTest method testRemoveDifferenceWhenDifferenceMatch.

@Test
public void testRemoveDifferenceWhenDifferenceMatch() throws XmlUtilException, SAXException, IOException {
    differences.addDifference(new Difference("/root[1]/a[1]"));
    differences.addDifference(new Difference("/root[1]/a[2]"));
    differences.addDifference(new Difference("/root[1]/b[1]"));
    String actual = xmlUnitService.removeDifference("/root\\[1\\]/a\\[[1-2]\\]", differences.mkString());
    String expected = "<differences><difference>/root[1]/b[1]</difference></differences>";
    DetailedDiff diff = new DetailedDiff(XMLUnit.compareXML(expected, actual));
    Assert.assertTrue(diff.toString(), diff.similar());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

DetailedDiff (org.custommonkey.xmlunit.DetailedDiff)39 Diff (org.custommonkey.xmlunit.Diff)16 Difference (org.custommonkey.xmlunit.Difference)16 Test (org.junit.Test)16 Document (org.w3c.dom.Document)7 File (java.io.File)6 List (java.util.List)6 IOException (java.io.IOException)5 StringWriter (java.io.StringWriter)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Element (org.w3c.dom.Element)5 BufferedInputStream (java.io.BufferedInputStream)4 BufferedReader (java.io.BufferedReader)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 AssertionFailedError (junit.framework.AssertionFailedError)4