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;
}
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;
}
Aggregations