Search in sources :

Example 1 with DifferencesException

use of org.cerberus.service.xmlunit.DifferencesException in project cerberus-source by cerberustesting.

the class XmlUnitService method removeDifference.

@Override
public String removeDifference(String pattern, String differences) {
    if (pattern == null || differences == null) {
        LOG.warn("Null argument");
        return null;
    }
    try {
        // Gets the difference list from the differences
        Differences current = Differences.fromString(differences);
        Differences returned = new Differences();
        // Compiles the given pattern
        Pattern compiledPattern = Pattern.compile(pattern);
        for (org.cerberus.service.xmlunit.Difference currentDiff : current.getDifferences()) {
            if (compiledPattern.matcher(currentDiff.getDiff()).matches()) {
                continue;
            }
            returned.addDifference(currentDiff);
        }
        // String XML representation
        return returned.mkString();
    } catch (DifferencesException e) {
        LOG.warn("Unable to remove differences", e);
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) DifferencesException(org.cerberus.service.xmlunit.DifferencesException) Differences(org.cerberus.service.xmlunit.Differences)

Example 2 with DifferencesException

use of org.cerberus.service.xmlunit.DifferencesException in project cerberus-source by cerberustesting.

the class XmlUnitService method isElementEquals.

@Override
public boolean isElementEquals(String lastSOAPResponse, String xpath, String expectedElement) {
    if (lastSOAPResponse == null || xpath == null || expectedElement == null) {
        LOG.warn("Null argument");
        return false;
    }
    try {
        NodeList candidates = XmlUtil.evaluate(lastSOAPResponse, xpath);
        LOG.debug(candidates.toString());
        for (Document candidate : XmlUtil.fromNodeList(candidates)) {
            if (Differences.fromString(getDifferencesFromXml(XmlUtil.toString(candidate), expectedElement)).isEmpty()) {
                return true;
            }
        }
    } catch (XmlUtilException xue) {
        LOG.warn("Unable to check if element equality", xue);
    } catch (DifferencesException de) {
        LOG.warn("Unable to check if element equality", de);
    }
    return false;
}
Also used : DifferencesException(org.cerberus.service.xmlunit.DifferencesException) NodeList(org.w3c.dom.NodeList) XmlUtilException(org.cerberus.util.XmlUtilException) Document(org.w3c.dom.Document)

Aggregations

DifferencesException (org.cerberus.service.xmlunit.DifferencesException)2 Pattern (java.util.regex.Pattern)1 Differences (org.cerberus.service.xmlunit.Differences)1 XmlUtilException (org.cerberus.util.XmlUtilException)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1