org.custommonkey.xmlunit.Difference Java Examples

The following examples show how to use org.custommonkey.xmlunit.Difference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegexDifferenceListener.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * returns the return value as defined in superclass.
 */
private int checkSpecialValue(Difference inDifference) {
    String testValue = inDifference.getControlNodeDetail().getValue();
    if (StringUtils.equals("${ignore}", testValue)) {
        LOG.debug("accept diff: " + inDifference.getControlNodeDetail().getValue() + " <-->" + inDifference.getTestNodeDetail().getValue());
        return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;

    } else if (testValue.trim().startsWith("${regex=") && testValue.trim().endsWith("}")) {
        String regex = inDifference.getControlNodeDetail().getValue();
        String[] regexArr = regex.split("=", 2);
        if (regexArr.length >= 2) {
            // zonder closing brackets
            boolean isCompliant = Pattern.matches(regexArr[1].substring(0, regexArr[1].length() - 1), inDifference.getTestNodeDetail().getValue());
            LOG.debug("accept diff: Pattern.matches(" + regexArr[1] + ", " + inDifference.getTestNodeDetail().getValue() + ") = " + isCompliant);
            if (isCompliant) {
                return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
            }
        }
    }
    return RETURN_ACCEPT_DIFFERENCE;
}
 
Example #2
Source File: ODataXmlSerializerTest.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
public int differenceFound(Difference difference) {
  final String xpath = "/updated[1]/text()[1]";
  if(difference.getControlNodeDetail().getXpathLocation().endsWith(xpath)) {
    String controlValue = difference.getControlNodeDetail().getValue();
    String testValue = difference.getTestNodeDetail().getValue();
    // Allow a difference of up to 2 seconds.
    try {
      long controlTime = UPDATED_FORMAT.parse(controlValue).getTime();
      long testTime = UPDATED_FORMAT.parse(testValue).getTime();
      long diff = controlTime - testTime;
      if (diff < 0) {
        diff = diff * -1;
      }
      if (diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
        return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
      }
    } catch (ParseException e) {
      throw new RuntimeException("Parse exception for updated value (see difference '" + difference + "').");
    }
  }
  // Yes it is a difference so throw an exception.
  return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
Example #3
Source File: QueryResultsComparator.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 6 votes vote down vote up
public int differenceFound(Difference difference) {
    // ignore <recordTime> presence
    if (difference.equals(DifferenceConstants.CHILD_NODE_NOT_FOUND)
            && "recordTime".equals(difference.getTestNodeDetail().getValue())) {
        return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
    }
    // ignore <recordTime> value
    if (difference.equals(DifferenceConstants.TEXT_VALUE)
            && "recordTime".equals(difference.getTestNodeDetail().getNode().getParentNode().getNodeName())) {
        return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
    }
    // check if <eventTime> equal
    if (difference.equals(DifferenceConstants.TEXT_VALUE)
            && "eventTime".equals(difference.getTestNodeDetail().getNode().getParentNode().getNodeName())) {
        try {
            Calendar testCal = TimeParser.parseAsCalendar(difference.getTestNodeDetail().getValue());
            Calendar controlCal = TimeParser.parseAsCalendar(difference.getControlNodeDetail().getValue());
            return controlCal.getTimeInMillis() == testCal.getTimeInMillis() ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL
                    : RETURN_ACCEPT_DIFFERENCE;
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    return ignore.contains(difference) ? RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL : RETURN_ACCEPT_DIFFERENCE;
}
 
Example #4
Source File: IgnoreWhiteCharsDiffListener.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int differenceFound(Difference diff) {

    if (diff.getId() == DifferenceConstants.TEXT_VALUE.getId()) {
        String control = diff.getControlNodeDetail().getValue();
        if (control != null) {
            control = control.trim();
            if (diff.getTestNodeDetail().getValue() != null
                && control.equals(diff.getTestNodeDetail().getValue().trim())) {
                return
                    DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
            }
        }
    }
    return RETURN_ACCEPT_DIFFERENCE;
}
 
Example #5
Source File: BasicFilter.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean canIgnore (Difference difference)
{
    // Check for redundancy
    if (info.canIgnoreDiff(difference.getDescription())) {
        return true;
    }

    if (canIgnore(difference.getControlNodeDetail().getNode())) {
        return true;
    }

    if (canIgnore(difference.getTestNodeDetail().getNode())) {
        return true;
    }

    return false;
}
 
Example #6
Source File: FloatingPointTolerantDifferenceListener.java    From xmlunit with Apache License 2.0 6 votes vote down vote up
protected int textualDifference(Difference d) {
    String control = d.getControlNodeDetail().getValue();
    String test = d.getTestNodeDetail().getValue();
    if (control != null && test != null) {
        try {
            double controlVal = Double.parseDouble(control);
            double testVal = Double.parseDouble(test);
            return Math.abs(controlVal - testVal) <= tolerance
                ? DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL
                : DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
        } catch (NumberFormatException nfe) {
            // ignore, delegate to nested DifferenceListener
        }
    }
    // no numbers or null, delegate
    return super.textualDifference(d);
}
 
Example #7
Source File: RegexDifferenceListener.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * returns the return value as defined in superclass.
 */
private int checkSpecialValue(Difference inDifference) {
    String testValue = inDifference.getControlNodeDetail().getValue();
    if (StringUtils.equals("${ignore}", testValue)) {
        LOG.debug("accept diff: " + inDifference.getControlNodeDetail().getValue() + " <-->" + inDifference.getTestNodeDetail().getValue());
        return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;

    } else if (testValue.trim().startsWith("${regex=") && testValue.trim().endsWith("}")) {
        String regex = inDifference.getControlNodeDetail().getValue();
        String[] regexArr = regex.split("=", 2);
        if (regexArr.length >= 2) {
            // zonder closing brackets
            boolean isCompliant = Pattern.matches(regexArr[1].substring(0, regexArr[1].length() - 1), inDifference.getTestNodeDetail().getValue());
            LOG.debug("accept diff: Pattern.matches(" + regexArr[1] + ", " + inDifference.getTestNodeDetail().getValue() + ") = " + isCompliant);
            if (isCompliant) {
                return RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
            }
        }
    }
    return RETURN_ACCEPT_DIFFERENCE;
}
 
Example #8
Source File: RegexDifferenceListener.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int differenceFound(Difference difference) {

    final Node controlNode = difference.getControlNodeDetail().getNode();
    final Node testNode = difference.getTestNodeDetail().getNode();
    if (difference.getId() == DifferenceConstants.ATTR_VALUE_ID && isXSIType(controlNode) && isXSIType(testNode)) {
        if (getNameSpaceFromPrefix(controlNode).compareTo(getNameSpaceFromPrefix(testNode)) != 0) {
            return RETURN_ACCEPT_DIFFERENCE;
        }
        String withoutPrefixControl = getNameWithoutPrefix(controlNode);
        String withoutPrefixTest = getNameWithoutPrefix(testNode);

        if (withoutPrefixControl.compareTo(withoutPrefixTest) == 0) {
            return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
        }
    }

    if (difference.getControlNodeDetail().getValue() != null //
        && difference.getControlNodeDetail().getValue().startsWith("${") //
        && difference.getControlNodeDetail().getValue().endsWith("}")) {
        return checkSpecialValue(difference);
    }

    return RETURN_ACCEPT_DIFFERENCE;
}
 
Example #9
Source File: RegexDifferenceListener.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public int differenceFound(Difference difference) {

    final Node controlNode = difference.getControlNodeDetail().getNode();
    final Node testNode = difference.getTestNodeDetail().getNode();
    if (difference.getId() == DifferenceConstants.ATTR_VALUE_ID && isXSIType(controlNode) && isXSIType(testNode)) {
        if (getNameSpaceFromPrefix(controlNode).compareTo(getNameSpaceFromPrefix(testNode)) != 0) {
            return RETURN_ACCEPT_DIFFERENCE;
        }
        String withoutPrefixControl = getNameWithoutPrefix(controlNode);
        String withoutPrefixTest = getNameWithoutPrefix(testNode);

        if (withoutPrefixControl.compareTo(withoutPrefixTest) == 0) {
            return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
        }
    }

    if (difference.getControlNodeDetail().getValue() != null //
        && difference.getControlNodeDetail().getValue().startsWith("${") //
        && difference.getControlNodeDetail().getValue().endsWith("}")) {
        return checkSpecialValue(difference);
    }

    return RETURN_ACCEPT_DIFFERENCE;
}
 
Example #10
Source File: RegexDifferenceListener.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
private int checkSpecialValue(Difference inDifference) {
   String testValue = inDifference.getControlNodeDetail().getValue();
   if (StringUtils.equals("${ignore}", testValue)) {
      LOG.debug("accept diff: " + inDifference.getControlNodeDetail().getValue() + " <-->" + inDifference.getTestNodeDetail().getValue());
      return 2;
   } else {
      if (testValue.trim().startsWith("${regex=") && testValue.trim().endsWith("}")) {
         String regex = inDifference.getControlNodeDetail().getValue();
         String[] regexArr = regex.split("=", 2);
         if (regexArr.length >= 2) {
            boolean isCompliant = Pattern.matches(regexArr[1].substring(0, regexArr[1].length() - 1), inDifference.getTestNodeDetail().getValue());
            LOG.debug("accept diff: Pattern.matches(" + regexArr[1] + ", " + inDifference.getTestNodeDetail().getValue() + ") = " + isCompliant);
            if (isCompliant) {
               return 2;
            }
         }
      }

      return 0;
   }
}
 
Example #11
Source File: RegexDifferenceListener.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public int differenceFound(Difference difference) {
   Node controlNode = difference.getControlNodeDetail().getNode();
   Node testNode = difference.getTestNodeDetail().getNode();
   if (difference.getId() == 3 && this.isXSIType(controlNode) && this.isXSIType(testNode)) {
      if (this.getNameSpaceFromPrefix(controlNode).compareTo(this.getNameSpaceFromPrefix(testNode)) != 0) {
         return 0;
      }

      String withoutPrefixControl = this.getNameWithoutPrefix(controlNode);
      String withoutPrefixTest = this.getNameWithoutPrefix(testNode);
      if (withoutPrefixControl.compareTo(withoutPrefixTest) == 0) {
         return 1;
      }
   }

   return difference.getControlNodeDetail().getValue() != null && difference.getControlNodeDetail().getValue().startsWith("${") && difference.getControlNodeDetail().getValue().endsWith("}") ? this.checkSpecialValue(difference) : 0;
}
 
Example #12
Source File: CustomDifferenceListener.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Checks for logical equivalence of the qualified node names.
 */
private int namespaceDifferenceFound(Difference difference) {
  Node controlNode = difference.getControlNodeDetail().getNode();
  Node testNode = difference.getTestNodeDetail().getNode();
  String controlNs = getNamespaceURI(controlNode);
  String testNs = getNamespaceURI(testNode);
  if (Objects.equal(controlNs, testNs)) {
    if (Objects.equal(controlNode.getLocalName(), testNode.getLocalName())) {
      return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
    }
  }
  return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
 
Example #13
Source File: CustomDifferenceListener.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
@Override
public int differenceFound(Difference difference) {
  switch (difference.getId()) {
    case DifferenceConstants.NAMESPACE_URI_ID:
      return namespaceDifferenceFound(difference);
    case DifferenceConstants.ELEMENT_NUM_ATTRIBUTES_ID:
    case DifferenceConstants.ATTR_NAME_NOT_FOUND_ID:
      return attributeDifferenceFound(difference);
    default:
      return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
  }
}
 
Example #14
Source File: FastaAFPChainConverterTest.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void printDetailedDiff(Diff diff, PrintStream ps) {
	DetailedDiff detDiff = new DetailedDiff(diff);
	for (Object object : detDiff.getAllDifferences()) {
		Difference difference = (Difference) object;
		ps.println(difference);
	}
}
 
Example #15
Source File: TextDifferenceListenerBase.java    From xmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Delegates to the nested DifferenceListener unless the
 * Difference is of type {@link DifferenceConstants#ATTR_VALUE_ID
 * ATTR_VALUE_ID}, {@link DifferenceConstants#CDATA_VALUE_ID
 * CDATA_VALUE_ID}, {@link DifferenceConstants#COMMENT_VALUE_ID
 * COMMENT_VALUE_ID} or {@link DifferenceConstants#TEXT_VALUE_ID
 * TEXT_VALUE_ID} - for those special differences {@link
 * #attributeDifference attributeDifference}, {@link
 * #cdataDifference cdataDifference}, {@link #commentDifference
 * commentDifference} or {@link #textDifference textDifference}
 * are invoked respectively.
 */
public int differenceFound(Difference difference) {
    switch (difference.getId()) {
    case DifferenceConstants.ATTR_VALUE_ID:
        return attributeDifference(difference);
    case DifferenceConstants.CDATA_VALUE_ID:
        return cdataDifference(difference);
    case DifferenceConstants.COMMENT_VALUE_ID:
        return commentDifference(difference);
    case DifferenceConstants.TEXT_VALUE_ID:
        return textDifference(difference);
    }
    return delegateTo.differenceFound(difference);
}
 
Example #16
Source File: CaseInsensitiveDifferenceListener.java    From xmlunit with Apache License 2.0 5 votes vote down vote up
protected int textualDifference(Difference d) {
    String control = d.getControlNodeDetail().getValue();
    if (control != null) {
        control = control.toLowerCase(Locale.US);
        if (d.getTestNodeDetail().getValue() != null
            && control.equals(d.getTestNodeDetail().getValue()
                              .toLowerCase(Locale.US))) {
            return
                DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
        }
    }
    // some string is null, delegate
    return super.textualDifference(d);
}
 
Example #17
Source File: CustomDifferenceListener.java    From googleads-java-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Ignores differences that are only due to missing xsi:type.
 */
private int attributeDifferenceFound(Difference difference) {
  NamedNodeMap controlAttributes = difference.getControlNodeDetail().getNode().getAttributes();
  NamedNodeMap testAttributes = difference.getTestNodeDetail().getNode().getAttributes();
  Map<QName, Node> controlAttributesMap = createAttributesMapExcludingXsiType(controlAttributes);
  Map<QName, Node> testAttributesMap = createAttributesMapExcludingXsiType(testAttributes);
  if (controlAttributesMap.size() != testAttributesMap.size()) {
    return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
  }
  return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}
 
Example #18
Source File: MusicPrinter.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void dump (int id,
                  Difference difference)
{
    print(String.format("%4d ", id));
    print(difference.isRecoverable() ? "REC " : "    ");
    println(difference.toString());

    NodeDetail controlDetail = difference.getControlNodeDetail();
    Node controlNode = controlDetail.getNode();
    String controlValue = stringOf(controlNode);

    if (controlValue != null) {
        println("             ctrl"
                + PositionalXMLReader.getRef(controlNode)
                + " " + controlValue);
    }

    NodeDetail testDetail = difference.getTestNodeDetail();
    Node testNode = testDetail.getNode();
    String testValue = stringOf(testNode);

    if (testValue != null) {
        println("             test"
                + PositionalXMLReader.getRef(testNode)
                + " " + testValue);
    }
}
 
Example #19
Source File: XmlUnitService.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
@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);
        }

        // Returns the empty String if there is no difference left, or the
        // String XML representation
        return returned.mkString();
    } catch (DifferencesException e) {
        LOG.warn("Unable to remove differences", e);
    }

    return null;
}
 
Example #20
Source File: QueryResultsComparator.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 5 votes vote down vote up
MyDifferenceLister() {
    ignore = new LinkedList<Difference>();
    ignore.add(DifferenceConstants.HAS_DOCTYPE_DECLARATION);
    ignore.add(DifferenceConstants.NAMESPACE_PREFIX);
    ignore.add(DifferenceConstants.CHILD_NODELIST_SEQUENCE);
    ignore.add(DifferenceConstants.CHILD_NODELIST_LENGTH);
    ignore.add(DifferenceConstants.ATTR_SEQUENCE);
    ignore.add(DifferenceConstants.COMMENT_VALUE);
}
 
Example #21
Source File: ExtendedJAXBEqualsStrategy.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected boolean equalsInternal(ObjectLocator leftLocator,
		ObjectLocator rightLocator, Node lhs, Node rhs) {
	final Diff diff = new Diff(new DOMSource(lhs), new DOMSource(rhs)) {
		@Override
		public int differenceFound(Difference difference) {
			if (difference.getId() == DifferenceConstants.NAMESPACE_PREFIX_ID) {
				return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
			} else {
				return super.differenceFound(difference);
			}
		}
	};
	return diff.identical();
}
 
Example #22
Source File: IdenticalHtmlMatcher.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Override
public String comparisonMessage() {
	StringBuilder sb = new StringBuilder();
	sb.append("The two HTML documents are not identical.\n");
	sb.append("Here are the differences found:\n");
	for(Object o : diff.getAllDifferences()) {
		Difference d = (Difference) o;
		sb.append("  - ").append(d.toString()).append("\n");
	}
	sb.append("\n");
	return sb.toString();
}
 
Example #23
Source File: XmlAsserter.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public static XmlAsserter.AssertResult assertXml(String expected, String actual) {
   XmlAsserter.AssertResult result = new XmlAsserter.AssertResult();

   try {
      LOG.debug("expected  : " + linearize(expected));
      LOG.debug("actual    : " + linearize(actual));
      Diff diff = new Diff(expected, actual);
      diff.overrideDifferenceListener(listener);
      diff.overrideElementQualifier(qualifier);
      result.setSimilar(diff.similar());
      LOG.debug("Similar : " + result.isSimilar());
      DetailedDiff detDiff = new DetailedDiff(diff);
      List<Difference> differences = detDiff.getAllDifferences();
      Iterator var7 = differences.iterator();

      while(var7.hasNext()) {
         Difference difference = (Difference)var7.next();
         if (!difference.isRecoverable()) {
            LOG.debug(difference.toString() + " expected :" + difference.getControlNodeDetail() + " but was :" + difference.getTestNodeDetail() + "  " + difference.getDescription());
            result.getDifferences().add(difference);
         }
      }
   } catch (Exception var8) {
      LOG.error(var8.getMessage(), var8);
      Assert.fail(var8.getMessage());
   }

   return result;
}
 
Example #24
Source File: SimilarHtmlMatcher.java    From ogham with Apache License 2.0 5 votes vote down vote up
@Override
public String comparisonMessage() {
	StringBuilder sb = new StringBuilder();
	sb.append("The two HTML documents are not similar.\n");
	sb.append("Here are the differences found:\n");
	for(Object o : diff.getAllDifferences()) {
		Difference d = (Difference) o;
		sb.append("  - ").append(d.toString()).append("\n");
	}
	sb.append("\n");
	return sb.toString();
}
 
Example #25
Source File: AssertHtml.java    From ogham with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static void logUnrecoverableDifferences(DetailedDiff diff) {
	for (Difference difference : (List<Difference>) diff.getAllDifferences()) {
		if (!difference.isRecoverable()) {
			LOG.error(difference.toString()); // NOSONAR
		}
	}
}
 
Example #26
Source File: AdeAnalysisOutputCompare.java    From ade with GNU General Public License v3.0 5 votes vote down vote up
/**
 * If a difference is found when comparing xml it will trigger a call to
 * differenceFound. Determine if the difference can be ignored (part of
 * the IGNORED_NODES) or if it's a 'true' difference.
 */
@Override
public int differenceFound(Difference arg0) {
	String elemXpathVal = arg0.getControlNodeDetail()
			.getXpathLocation();
	if (IGNORED_NODES.contains(elemXpathVal)) {
		return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
	}
	System.out.println(" ** Difference Found:");
	System.out.println("\t" + arg0.toString() + "\n");
	return RETURN_ACCEPT_DIFFERENCE;
}
 
Example #27
Source File: DomDifferenceListener.java    From apogen with Apache License 2.0 5 votes vote down vote up
public int differenceFound(Difference difference) {

		Set<String> blackList = new HashSet<String>();
		blackList.add("br");
		blackList.add("style");
		blackList.add("script");

		if (difference.getControlNodeDetail() == null || difference.getControlNodeDetail().getNode() == null
				|| difference.getTestNodeDetail() == null || difference.getTestNodeDetail().getNode() == null) {
			return RETURN_ACCEPT_DIFFERENCE;
		}

		// if (ignoreAttributes.contains(difference.getTestNodeDetail().getNode()
		// .getNodeName())
		// || ignoreAttributes.contains(difference.getControlNodeDetail()
		// .getNode().getNodeName())) {
		// return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
		// }

		if (difference.getId() == DifferenceConstants.TEXT_VALUE_ID) {
			if (blackList.contains(difference.getControlNodeDetail().getNode().getParentNode().getNodeName())) {
				return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
			}
		}

		return RETURN_ACCEPT_DIFFERENCE;
	}
 
Example #28
Source File: UtilsDiff.java    From apogen with Apache License 2.0 5 votes vote down vote up
/**
 * BETA version of APOGEN-DOM-differencing mechanism
 * 
 * @param doc1
 * @param doc2
 * @return list of Differences
 * @throws ParserConfigurationException
 * @throws IOException
 * @throws SAXException
 */
@SuppressWarnings("unchecked")
public static List<Difference> customisedDomDiff(String string, String string2)
		throws ParserConfigurationException, SAXException, IOException {

	org.w3c.dom.Document doc1 = asDocument(string, true);
	org.w3c.dom.Document doc2 = asDocument(string2, true);

	XMLUnit.setControlParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
	XMLUnit.setTestParser("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
	XMLUnit.setSAXParserFactory("org.apache.xerces.jaxp.SAXParserFactoryImpl");

	XMLUnit.setNormalizeWhitespace(true);
	XMLUnit.setIgnoreAttributeOrder(true);
	XMLUnit.setIgnoreWhitespace(true);
	XMLUnit.setIgnoreComments(true);
	XMLUnit.setNormalize(true);
	XMLUnit.setIgnoreDiffBetweenTextAndCDATA(false);

	Diff d = new Diff(doc1, doc2);
	DetailedDiff dd = new DetailedDiff(d);

	dd.overrideDifferenceListener(new DomDifferenceListener());
	dd.overrideElementQualifier(null);

	return dd.getAllDifferences();
}
 
Example #29
Source File: XmlAsserter.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
public static List<Difference> getDifferences(DOMSource expected, DOMSource actual) {
   return assertXml(toString(expected), toString(actual)).getDifferences();
}
 
Example #30
Source File: XmlUnitService.java    From cerberus-source with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getDifferencesFromXml(String left, String right) {
    try {
        // Gets the detailed diff between left and right argument
        Document leftDocument = inputTranslator.translate(left);
        Document rightDocument = inputTranslator.translate(right);
        DetailedDiff diffs = new DetailedDiff(XMLUnit.compareXML(leftDocument, rightDocument));

        // Creates the result structure which will contain difference list
        Differences resultDiff = new Differences();

        // Add each difference to our result structure
        for (Object diff : diffs.getAllDifferences()) {
            if (!(diff instanceof Difference)) {
                LOG.warn("Unable to handle no XMLUnit Difference " + diff);
                continue;
            }
            Difference wellTypedDiff = (Difference) diff;
            String xPathLocation = wellTypedDiff.getControlNodeDetail().getXpathLocation();
            // Null XPath location means additional data from the right
            // structure.
            // Then we retrieve XPath from the right structure.
            if (xPathLocation == null) {
                xPathLocation = wellTypedDiff.getTestNodeDetail().getXpathLocation();
            }
            // If location is still null, then both of left and right
            // differences have been marked as null
            // This case should never happen
            if (xPathLocation == null) {
                LOG.warn("Null left and right differences found");
                xPathLocation = NULL_XPATH;
            }
            resultDiff.addDifference(new org.cerberus.service.xmlunit.Difference(xPathLocation));
        }

        // Finally returns the String representation of our result structure
        return resultDiff.mkString();
    } catch (InputTranslatorException e) {
        LOG.warn("Unable to get differences from XML", e);
    }

    return null;
}