Search in sources :

Example 1 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.

the class AccessPointMonitorConfigTest method getDiff.

@SuppressWarnings("unchecked")
private DetailedDiff getDiff(StringWriter objectXML, StringBuffer 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;
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Difference(org.custommonkey.xmlunit.Difference)

Example 2 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.

the class TcaDataCollectionConfigTest method generateXML.

/**
 * Generate XML.
 *
 * @throws Exception the exception
 */
@Test
public void generateXML() throws Exception {
    // Marshal the test object to an XML string
    StringWriter objectXML = new StringWriter();
    marshaller.marshal(tcadcc, objectXML);
    // Read the example XML from src/test/resources
    StringBuffer exampleXML = new StringBuffer();
    File tcaCollectionConfig = getSourceFile();
    assertTrue(TcaDataCollectionConfig.TCA_DATACOLLECTION_CONFIG_FILE + " is readable", tcaCollectionConfig.canRead());
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(tcaCollectionConfig), StandardCharsets.UTF_8));
    String line;
    while (true) {
        line = reader.readLine();
        if (line == null) {
            reader.close();
            break;
        }
        exampleXML.append(line).append("\n");
    }
    System.err.println("========================================================================");
    System.err.println("Object XML:");
    System.err.println("========================================================================");
    System.err.print(objectXML.toString());
    System.err.println("========================================================================");
    System.err.println("Example XML:");
    System.err.println("========================================================================");
    System.err.print(exampleXML.toString());
    DetailedDiff myDiff = getDiff(objectXML, exampleXML);
    assertEquals("number of XMLUnit differences between the example XML and the mock object XML is 0", 0, myDiff.getAllDifferences().size());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.

the class JdbcDataCollectionConfigTest method generateXML.

@Test
public void generateXML() throws Exception {
    // Marshal the test object to an XML string
    StringWriter objectXML = new StringWriter();
    JaxbUtils.marshal(jdcc, objectXML);
    // Read the example XML from src/test/resources
    final StringBuilder exampleXML = new StringBuilder();
    File jdbcCollectionConfig = new File(ClassLoader.getSystemResource("jdbc-datacollection-config.xml").getFile());
    assertTrue("jdbc-datacollection-config.xml is readable", jdbcCollectionConfig.canRead());
    BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(jdbcCollectionConfig), StandardCharsets.UTF_8));
    String line;
    while (true) {
        line = reader.readLine();
        if (line == null) {
            reader.close();
            break;
        }
        exampleXML.append(line).append("\n");
    }
    System.err.println("========================================================================");
    System.err.println("Object XML:");
    System.err.println("========================================================================");
    System.err.print(objectXML.toString());
    System.err.println("========================================================================");
    System.err.println("Example XML:");
    System.err.println("========================================================================");
    System.err.print(exampleXML.toString());
    DetailedDiff myDiff = getDiff(objectXML, exampleXML);
    assertEquals("number of XMLUnit differences between the example XML and the mock object XML is 0", 0, myDiff.getAllDifferences().size());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.

the class PersistenceSerializationTest method getDiff.

@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;
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Difference(org.custommonkey.xmlunit.Difference)

Example 5 with DetailedDiff

use of org.custommonkey.xmlunit.DetailedDiff in project UVMS-ActivityModule-APP by UnionVMS.

the class ActivityEntityToModelMapperTest method testMapToFLUXFAReportMessage.

@Test
@Parameters(method = "resources")
public void testMapToFLUXFAReportMessage(String resource) throws Exception {
    FLUXFAReportMessage fluxfaReportMessage = sourceToEntity(resource);
    FluxFaReportMessageEntity entity = incomingFAReportMapper.mapToFluxFaReportMessage(fluxfaReportMessage, FaReportSourceEnum.MANUAL, new FluxFaReportMessageEntity());
    FLUXFAReportMessage target = modelMapper.mapToFLUXFAReportMessage(new ArrayList<>(entity.getFaReportDocuments()));
    String controlSource = JAXBUtils.marshallJaxBObjectToString(getFirstElement(fluxfaReportMessage));
    String testSource = JAXBUtils.marshallJaxBObjectToString(getFirstElement(target));
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreAttributeOrder(true);
    DetailedDiff diff = new DetailedDiff(new org.custommonkey.xmlunit.Diff(clearEmptyTags(controlSource), clearEmptyTags(testSource)));
    diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
    assertTrue("XML are similar " + diff, diff.similar());
}
Also used : DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) FLUXFAReportMessage(un.unece.uncefact.data.standard.fluxfareportmessage._3.FLUXFAReportMessage) RecursiveElementNameAndTextQualifier(org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier) FluxFaReportMessageEntity(eu.europa.ec.fisheries.ers.fa.entities.FluxFaReportMessageEntity) Parameters(junitparams.Parameters) Test(org.junit.Test)

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