public static void assertXmlEquals(String expected, String actual) throws Exception { XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(expected, actual); Assert.assertTrue(diff.toString(), diff.similar()); } }
Diff diff = new Diff(control, test, null, new ElementNameAndAttributeQualifier("name")); assertTrue( diff.toString(), diff.similar() );
final String control = "<userActionRequiredCode>0</userActionRequiredCode>"; final String test = "<userActionRequiredCode xsi:nil=\"1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"; Diff myDiff = DiffBuilder.compare(Input.fromString(control)) .withTest(Input.fromString(test)) .build(); System.out.println(myDiff.toString());
private static String getFailMessage(String msg, Diff diff) { StringBuilder sb = new StringBuilder(); if (msg != null && msg.length() > 0) { sb.append(msg).append(", "); } return sb.append(diff.toString()).toString(); }
private static String getFailMessage(String msg, Diff diff) { StringBuffer sb = new StringBuffer(); if (msg != null && msg.length() > 0) { sb.append(msg).append(", "); } return sb.append(diff.toString()).toString(); }
/** * Assert that the result of an XML comparison is or is not identical * @param diff the result of an XML comparison * @param assertion true if asserting that result is identical */ public void assertXMLIdentical(Diff diff, boolean assertion) { XMLAssert.assertXMLIdentical(diff.toString(), diff, assertion); }
/** * Assert that the result of an XML comparison is or is not identical * @param diff the result of an XML comparison * @param assertion true if asserting that result is identical */ public void assertXMLIdentical(Diff diff, boolean assertion) { XMLAssert.assertXMLIdentical(diff.toString(), diff, assertion); }
protected void checkXmlStructure(String xmlunitPage, String pageCode) throws SAXException, IOException { InputStream expectedPageCode = testClass.get().getJavaClass().getResourceAsStream(xmlunitPage); XMLUnit.setNormalizeWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); Diff xmlDiff = new Diff(new InputStreamReader(expectedPageCode), new StringReader(pageCode)); xmlDiff.overrideDifferenceListener(getDifferenceListener()); if (!xmlDiff.similar()) { System.out.println("=== ACTUAL PAGE CODE ==="); System.out.println(pageCode); System.out.println("======== ERROR ========="); System.out.println(xmlDiff.toString()); System.out.println("========================"); fail("XML was not similar:" + xmlDiff.toString()); } }
public static void main(String[] args) throws Exception { String xml1="<Akash><status>COMPLETE</status>" +"<startedTime>23</startedTime></Akash>"; String xml2="<Akash><status>COMPLETE</status><startedTime></startedTime></Akash>"; XMLUnit.setIgnoreWhitespace(true); Diff diff = new Diff(xml1,xml2); diff.overrideElementQualifier(new ElementNameAndTextQualifier()); assertTrue("XML similar " + diff.toString(), diff.similar()); }
public static String diffIgnoreUpdateWithAttributeQualifier(byte[] expected, byte[] actual) throws Exception { Document xmlExpected = getXML(expected); Document xmlActual = getXML(actual); Diff diff = new DiffIgnoreUpdateWithAttributeQualifier(xmlExpected, xmlActual); if (diff.similar()) { return null; } System.err.println("Expected:\r\n" + TestUtils.printPrettyXML(xmlExpected)); System.err.println("Actual:\r\n" + TestUtils.printPrettyXML(xmlActual)); return diff.toString(); }
public static String diffIgnoreUpdateWithAttributeQualifier(String expectedFileName, byte[] actual, Class<?> cls) throws Exception { Document xmlExpected = getXML(expectedFileName, cls); Document xmlActual = getXML(actual); Diff diff = new DiffIgnoreUpdateWithAttributeQualifier(xmlExpected, xmlActual); if (diff.similar()) { return null; } System.err.println("Expected:\r\n" + TestUtils.printPrettyXML(xmlExpected)); System.err.println("Actual:\r\n" + TestUtils.printPrettyXML(xmlActual)); return diff.toString(); } public static String diffIgnoreUpdateWithAttributeQualifier(String expected, String actual) throws Exception {
@Override public final void match(WebServiceMessage message) throws IOException, AssertionError { Diff diff = createDiff(message); assertTrue("Messages are different, " + diff.toString(), diff.similar(), "Payload", message.getPayloadSource()); }
@Override public final void match(WebServiceMessage message) throws IOException, AssertionError { Diff diff = createDiff(message); assertTrue("Messages are different, " + diff.toString(), diff.similar(), "Payload", message.getPayloadSource()); }
@Override public final void match(WebServiceMessage message) throws IOException, AssertionError { Diff diff = createDiff(message); assertTrue("Messages are different, " + diff.toString(), diff.similar(), "Payload", message.getPayloadSource()); }
@Override protected void match(SoapMessage soapMessage) throws IOException, AssertionError { Document actualDocument = soapMessage.getDocument(); Document expectedDocument = createDocumentFromSource(expected); Diff diff = new Diff(expectedDocument, actualDocument); assertTrue("Envelopes are different, " + diff.toString(), diff.similar()); }
@Override protected void match(SoapMessage soapMessage) throws IOException, AssertionError { Document actualDocument = soapMessage.getDocument(); Document expectedDocument = createDocumentFromSource(expected); Diff diff = new Diff(expectedDocument, actualDocument); assertTrue("Envelopes are different, " + diff.toString(), diff.similar()); }
@Override protected void match(SoapMessage soapMessage) throws IOException, AssertionError { Document actualDocument = soapMessage.getDocument(); Document expectedDocument = createDocumentFromSource(expected); Diff diff = new Diff(expectedDocument, actualDocument); assertTrue("Envelopes are different, " + diff.toString(), diff.similar()); }
public void assertSimilarXML(String XML1, String XML2) throws Exception { Diff myDiff = new Diff(XML1, XML2); assertTrue("XML similar " + myDiff.toString(), myDiff.similar()); }
public void assertIdenticalXML(String XML1, String XML2) throws Exception { Diff myDiff = new Diff(XML1, XML2); assertTrue("XML similar " + myDiff.toString(), myDiff.identical()); }
@Test public void testSerializeDeserializeAnyXmlNode() throws Exception { final ByteArrayInputStream is = new ByteArrayInputStream("<xml><data/></xml>".getBytes(Charset.defaultCharset())); final Document parse = UntrustedXML.newDocumentBuilder().parse(is); final AnyXmlNode anyXmlNode = Builders.anyXmlBuilder() .withNodeIdentifier(id("anyXmlNode")) .withValue(new DOMSource(parse)) .build(); final byte[] bytes = SerializationUtils.serializeNormalizedNode(anyXmlNode); final NormalizedNode<?, ?> deserialized = SerializationUtils.deserializeNormalizedNode(bytes); final DOMSource value = (DOMSource) deserialized.getValue(); final Diff diff = XMLUnit.compareXML((Document) anyXmlNode.getValue().getNode(), value.getNode().getOwnerDocument()); Assert.assertTrue(diff.toString(), diff.similar()); }