use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.
the class AccessPointMonitorConfigTest method generateXML.
@Test
public void generateXML() throws Exception {
// Marshal the test object to an XML string
StringWriter objectXML = new StringWriter();
JaxbUtils.marshal(apmc, objectXML);
// Read the example XML from src/test/resources
StringBuffer exampleXML = new StringBuffer();
File apmConfig = new File(ClassLoader.getSystemResource("access-point-monitor-configuration.xml").getFile());
assertTrue("access-point-monitor-configuration.xml is readable", apmConfig.canRead());
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(apmConfig), "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());
}
use of org.custommonkey.xmlunit.DetailedDiff in project jPOS by jpos.
the class XMLPackagerTest method testPack.
@Test
public void testPack() throws IOException, ISOException, SAXException {
isoMsg.setMTI("0800");
isoMsg.set(7, "7654321");
isoMsg.set(11, "12345678");
isoMsg.set(12, "20110224112759");
isoMsg.set(24, "");
byte[] data = isoMsg.pack();
// System.out.println(new String(data));
String expected = "<isomsg><!-- org.jpos.iso.packager.XMLPackager --><field id=\"0\" value=\"0800\"/>" + "<field id=\"7\" value=\"7654321\"/><field id=\"11\" value=\"12345678\"/>" + "<field id=\"12\" value=\"20110224112759\"/><field id=\"24\" value=\"\"/></isomsg>";
XMLUnit.setIgnoreWhitespace(true);
// XMLAssert.assertXMLEqual(expected, new String(data));
DetailedDiff myDiff = new DetailedDiff(XMLUnit.compareXML(expected, new String(data)));
List allDifferences = myDiff.getAllDifferences();
assertEquals(myDiff.toString(), 0, allDifferences.size());
}
use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.
the class TcaDataCollectionConfigTest method getDiff.
/**
* Gets the diff.
*
* @param objectXML the object XML
* @param exampleXML the example XML
* @return the detailed diff
* @throws SAXException the sAX exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@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;
}
use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.
the class XmlTest method getDifferences.
public static List<Difference> getDifferences(final String xmlA, final String xmlB, final Predicate<String> ignoreNamespace, final Predicate<String> ignorePrefix, final Predicate<Difference> ignoreDifference) {
DetailedDiff myDiff;
try {
myDiff = new DetailedDiff(XMLUnit.compareXML(xmlA, xmlB));
} catch (final Exception e) {
throw new RuntimeException(e);
}
final List<Difference> retDifferences = new ArrayList<>();
@SuppressWarnings("unchecked") final List<Difference> allDifferences = myDiff.getAllDifferences();
if (allDifferences.size() > 0) {
DIFFERENCES: for (final Difference d : allDifferences) {
final NodeDetail controlNodeDetail = d.getControlNodeDetail();
final String control = controlNodeDetail.getValue();
final NodeDetail testNodeDetail = d.getTestNodeDetail();
final String test = testNodeDetail.getValue();
if (d.getDescription().equals("namespace URI")) {
if (control != null && !"null".equals(control)) {
if (ignoreNamespace.test(control.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
if (test != null && !"null".equals(test)) {
if (ignoreNamespace.test(test.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
} else if (d.getDescription().equals("namespace prefix")) {
if (control != null && !"null".equals(control)) {
if (ignorePrefix.test(control.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
if (test != null && !"null".equals(test)) {
if (ignorePrefix.test(test.toLowerCase())) {
LOG.trace("Ignoring {}: {}", d.getDescription(), d);
continue DIFFERENCES;
}
}
} else if (d.getDescription().equals("xsi:schemaLocation attribute")) {
LOG.debug("Schema location '{}' does not match. Ignoring.", controlNodeDetail.getValue() == null ? testNodeDetail.getValue() : controlNodeDetail.getValue());
continue DIFFERENCES;
}
if (ignoreDifference.test(d)) {
LOG.debug("ignoreDifference matched. Ignoring difference: {}: {}", d.getDescription(), d);
continue DIFFERENCES;
} else {
LOG.warn("Found difference: {}: {}", d.getDescription(), d);
retDifferences.add(d);
}
}
}
return retDifferences;
}
use of org.custommonkey.xmlunit.DetailedDiff in project opennms by OpenNMS.
the class JdbcDataCollectionConfigTest method getDiff.
@SuppressWarnings("unchecked")
private 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;
}
Aggregations