Assert that two XML documents are NOT similar
@param err Message to be displayed on assertion failure
@param control XML to be compared against
@param test XML to be tested
485410
public static void assertXMLNotEqual(String err, Document control,
                                         Document test) {
        Diff diff = new Diff(control, test);
        assertXMLEqual(err, diff, false);
    }
228943
public static void assertXpathValuesEqual(String controlXpath,
                                              String testXpath,
                                              InputSource document)
        throws SAXException, IOException, XpathException {
        assertXpathValuesEqual(controlXpath, testXpath,
                               XMLUnit.buildControlDocument(document));
    }
1324065
protected void writeResult(String testName, String resultXml) throws IOException {
        String finalPath = getXmlFileName(testName);
        Writer fw = null;
        try {
            fw = new BufferedWriter(
                    new OutputStreamWriter(
                        new FileOutputStream(finalPath),
                        "UTF-8"));
            fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            fw.write(resultXml);
        } finally {
            if (fw != null) {
                fw.close();
            }
        }
    }
209619
public static void assertXpathEvaluatesTo(String expectedValue,
                                              String xpathExpression,
                                              Document inDocument)
        throws XpathException {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        assertEquals(expectedValue,
                     simpleXpathEngine.evaluate(xpathExpression, inDocument));
    }
519136
protected void compareComment(Comment control, Comment test,
                                  DifferenceListener listener) throws DifferenceFoundException {
        if (!XMLUnit.getIgnoreComments()) {
            compareCharacterData(control, test, listener, COMMENT_VALUE);
        }
    }
660134
private DeferredComparison compareAttributeExplicitness(final Attr control,
                                                            final XPathContext controlContext,
                                                            final Attr test,
                                                            final XPathContext testContext) {
        return new DeferredComparison() {
            @Override
            public ComparisonState apply() {
                return compare(new Comparison(ComparisonType.ATTR_VALUE_EXPLICITLY_SPECIFIED,
                                              control, getXPath(controlContext),
                                              control.getSpecified(), getParentXPath(controlContext),
                                              test, getXPath(testContext),
                                              test.getSpecified(), getParentXPath(testContext)));
            }
        };
    }
1244510
protected void compareText(Text control, Text test,
                               DifferenceListener listener)
        throws DifferenceFoundException {
        compareText((CharacterData) control, (CharacterData) test, listener);
    }
75840
protected void validateMessageContent(Message receivedMessage, Message controlMessage, XmlMessageValidationContext validationContext,
            TestContext context) {
        if (controlMessage == null || controlMessage.getPayload() == null) {
            log.debug("Skip message payload validation as no control message was defined");
            return;
        }

        if (!(controlMessage.getPayload() instanceof String)) {
            throw new IllegalArgumentException(
                    "DomXmlMessageValidator does only support message payload of type String, " +
                    "but was " + controlMessage.getPayload().getClass());
        }

        String controlMessagePayload = controlMessage.getPayload(String.class);

        if (receivedMessage.getPayload() == null || !StringUtils.hasText(receivedMessage.getPayload(String.class))) {
            Assert.isTrue(!StringUtils.hasText(controlMessagePayload),
                    "Unable to validate message payload - received message payload was empty, control message payload is not");
            return;
        } else if (!StringUtils.hasText(controlMessagePayload)) {
            return;
        }

        log.debug("Start XML tree validation ...");

        Document received = XMLUtils.parseMessagePayload(receivedMessage.getPayload(String.class));
        Document source = XMLUtils.parseMessagePayload(controlMessagePayload);

        XMLUtils.stripWhitespaceNodes(received);
        XMLUtils.stripWhitespaceNodes(source);

        if (log.isDebugEnabled()) {
            log.debug("Received message:\n" + XMLUtils.serialize(received));
            log.debug("Control message:\n" + XMLUtils.serialize(source));
        }

        validateXmlTree(received, source, validationContext, namespaceContextBuilder.buildContext(
                receivedMessage, validationContext.getNamespaces()), context);
    }
112131
private ComparisonState compareNodeLists(Iterable<Node> controlSeq,
                                             final XPathContext controlContext,
                                             Iterable<Node> testSeq,
                                             final XPathContext testContext) {
        ComparisonState chain = new OngoingComparisonState();

        Iterable<Map.Entry<Node, Node>> matches =
            getNodeMatcher().match(controlSeq, testSeq);
        List<Node> controlList = Linqy.asList(controlSeq);
        List<Node> testList = Linqy.asList(testSeq);
        Set<Node> seen = new HashSet<Node>();
        for (Map.Entry<Node, Node> pair : matches) {
            final Node control = pair.getKey();
            seen.add(control);
            final Node test = pair.getValue();
            seen.add(test);
            int controlIndex = controlList.indexOf(control);
            int testIndex = testList.indexOf(test);

            controlContext.navigateToChild(controlIndex);
            testContext.navigateToChild(testIndex);
            try {
                chain =
                    chain.andThen(new Comparison(ComparisonType.CHILD_NODELIST_SEQUENCE,
                                                 control, getXPath(controlContext),
                                                 Integer.valueOf(controlIndex), getParentXPath(controlContext),
                                                 test, getXPath(testContext),
                                                 Integer.valueOf(testIndex), getParentXPath(testContext)))
                    .andThen(new DeferredComparison() {
                            @Override
                            public ComparisonState apply() {
                                return compareNodes(control, controlContext,
                                                    test, testContext);
                            }
                        });
            } finally {
                testContext.navigateToParent();
                controlContext.navigateToParent();
            }
        }

        return chain.andThen(new UnmatchedControlNodes(controlList, controlContext, seen, testContext))
            .andThen(new UnmatchedTestNodes(testList, testContext, seen, controlContext));
    }
969476
public static void assertXpathNotExists(String xPathExpression, 
                                            Document inDocument)
        throws XpathException {
        XpathEngine simpleXpathEngine = XMLUnit.newXpathEngine();
        NodeList nodeList = simpleXpathEngine.getMatchingNodes(
                                                               xPathExpression, inDocument);
        int matches = nodeList.getLength();
        assertEquals("Should be zero matches for Xpath " + 
                     xPathExpression, 0, matches);
    }
338210
public static void assertNotEqual(Object a, Object b) {
        assertNotEqual(a, b, a + " should not equal to " + b);
    }
114363
protected void compareDocument(Document control, Document test, 
                                   DifferenceListener listener, ElementQualifier elementQualifier) 
        throws DifferenceFoundException {
        DocumentType controlDoctype = control.getDoctype();
        DocumentType testDoctype = test.getDoctype();
        compare(getNullOrNotNull(controlDoctype), 
                getNullOrNotNull(testDoctype), 
                controlDoctype, testDoctype, listener, 
                HAS_DOCTYPE_DECLARATION);
        if (controlDoctype!=null && testDoctype!=null) {
            compareNode(controlDoctype, testDoctype, listener, elementQualifier);
        }
    }
834121
private DeferredComparison compareDeclarations(final Document control,
                                                   final XPathContext controlContext,
                                                   final Document test,
                                                   final XPathContext testContext) {
        return new DeferredComparison() {
            @Override
            public ComparisonState apply() {
                return
                    compare(new Comparison(ComparisonType.XML_VERSION,
                                           control, getXPath(controlContext),
                                           control.getXmlVersion(), getParentXPath(controlContext),
                                           test, getXPath(testContext),
                                           test.getXmlVersion(), getParentXPath(testContext)))
                    .andThen(new Comparison(ComparisonType.XML_STANDALONE,
                                            control, getXPath(controlContext),
                                            control.getXmlStandalone(), getParentXPath(controlContext),
                                            test, getXPath(testContext),
                                            test.getXmlStandalone(), getParentXPath(testContext)))
                    .andThen(new Comparison(ComparisonType.XML_ENCODING,
                                            control, getXPath(controlContext),
                                            control.getXmlEncoding(), getParentXPath(controlContext),
                                            test, getXPath(testContext),
                                            test.getXmlEncoding(), getParentXPath(testContext)));
            }
        };
    }
643847
public static void validateNotEqual(Object t1, Object t2, String errorMsg) throws ValidateException {
		if (equal(t1, t2)) {
			throw new ValidateException(errorMsg);
		}
	}
560770
private AssertionError createAssertionError() {
		// convert both sides to strings
		String expected = TreeQuery.toString(expectedDef, expectedRoot, expectedToString);
		String actual = TreeQuery.toString(actualDef, actualRoot, actualToString);
		// try to create a junit ComparisonFailure
		for (String exceptionType : Arrays.asList(
				"org.junit.ComparisonFailure",
				"junit.framework.ComparisonFailure")) {
			try {
				return createComparisonFailure(exceptionType, expected, actual);
			} catch (Exception e) {}
		}
		// we'll have to settle for a plain-jane AssertionError
		return new AssertionError("Expected:\n" + expected + "\n\nActual:\n" + actual);
	}
309562
private ComparisonState compareXsiType(Attr controlAttr,
                                           XPathContext controlContext,
                                           Attr testAttr,
                                           XPathContext testContext) {
        boolean mustChangeControlContext = controlAttr != null;
        boolean mustChangeTestContext = testAttr != null;
        if (!mustChangeControlContext && !mustChangeTestContext) {
            return new OngoingComparisonState();
        }
        boolean attributePresentOnBothSides = mustChangeControlContext
            && mustChangeTestContext;

        try {
            QName controlAttrName = null;
            if (mustChangeControlContext) {
                controlAttrName = Nodes.getQName(controlAttr);
                controlContext.addAttribute(controlAttrName);
                controlContext.navigateToAttribute(controlAttrName);
            }
            QName testAttrName = null;
            if (mustChangeTestContext) {
                testAttrName = Nodes.getQName(testAttr);
                testContext.addAttribute(testAttrName);
                testContext.navigateToAttribute(testAttrName);
            }
            return
                compare(new Comparison(ComparisonType.ATTR_NAME_LOOKUP,
                                       controlAttr, getXPath(controlContext),
                                       controlAttrName, getParentXPath(controlContext),
                                       testAttr, getXPath(testContext),
                                       testAttrName, getParentXPath(testContext)))
                .andIfTrueThen(attributePresentOnBothSides,
                               compareAttributeExplicitness(controlAttr, controlContext,
                                                            testAttr, testContext))
                .andIfTrueThen(attributePresentOnBothSides,
                               new Comparison(ComparisonType.ATTR_VALUE,
                                              controlAttr, getXPath(controlContext),
                                              valueAsQName(controlAttr), getParentXPath(controlContext),
                                              testAttr, getXPath(testContext),
                                              valueAsQName(testAttr), getParentXPath(testContext)));
        } finally {
            if (mustChangeControlContext) {
                controlContext.navigateToParent();
            }
            if (mustChangeTestContext) {
                testContext.navigateToParent();
            }
        }
    }
99748
public static void assertXMLNotEqual(String control, String test)
        throws SAXException, IOException {
        assertXMLNotEqual(null, control, test);
    }