public int differenceFound(Difference diff) { String nodeName = diff.getTestNodeDetail().getNode().getNodeName(); if (nodeName.equals("conditionExpression") || nodeName.equals("language")) { logger.info(diff.toString()); return RETURN_ACCEPT_DIFFERENCE; } return RETURN_IGNORE_DIFFERENCE_NODES_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()); } }
/** * If a difference is found when comparing xml it will trigger a call to * differenceFound. Determine if the difference can be ignored (part of * the IGNORED_NODES) or if it's a 'true' difference. */ @Override public int differenceFound(Difference arg0) { String elemXpathVal = arg0.getControlNodeDetail() .getXpathLocation(); if (IGNORED_NODES.contains(elemXpathVal)) { return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; } System.out.println(" ** Difference Found:"); System.out.println("\t" + arg0.toString() + "\n"); return RETURN_ACCEPT_DIFFERENCE; }
public int differenceFound(Difference diff) { String nodeName = diff.getTestNodeDetail().getNode().getNodeName(); if (nodeName.equals("conditionExpression") || nodeName.equals("language")) { logger.info(diff.toString()); return RETURN_ACCEPT_DIFFERENCE; } return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL; }