public boolean validate(Document value) { if (value == null) return false; try { Document expectedValue = getValue(); logger.debug("Expected XML Value: {},\nActual XML Value: {}", xmlUtilities.getDocumentAsString(expectedValue).trim() , xmlUtilities.getDocumentAsString(value).trim()); DetailedDiff difference = new DetailedDiff(new Diff(expectedValue, value)); if (!difference.similar()) logger.warn("Differences exist between two documents: {}", difference.getAllDifferences()); else logger.debug("No differences exist for input"); return difference.similar(); } catch (Exception e) { throw new RuntimeException(e); } }
public void testRoundTrip() throws Exception { StringWriter sw = new StringWriter(); InputStream original = getClass().getClassLoader().getResourceAsStream("testmodel_data.xml"); XMLUnit.setIgnoreWhitespace(true); Collection<FastPathObject> unmarshalled = (Collection<FastPathObject>) binding.unmarshal(original); setIds(unmarshalled); binding.marshal(unmarshalled, sw); // System.out.println(sw.toString()); String expected = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("testmodel_data.xml")); Diff diff = new Diff(expected, sw.toString()); DetailedDiff detail = new DetailedDiff(diff); detail.overrideElementQualifier(new ElementNameAndAttributeQualifier()); assertTrue(detail.getAllDifferences().toString() + ": Original: " + expected + ", Generated: " + sw.toString(), detail.similar()); }