Class PlaceholderDifferenceEvaluator

  • All Implemented Interfaces:
    DifferenceEvaluator

    public class PlaceholderDifferenceEvaluator
    extends java.lang.Object
    implements DifferenceEvaluator
    This class is used to add placeholder feature to XML comparison.

    This class and the whole module are considered experimental and any API may change between releases of XMLUnit.

    To use it, just add it with DiffBuilder like below

     Diff diff = DiffBuilder.compare(control).withTest(test).withDifferenceEvaluator(new PlaceholderDifferenceEvaluator()).build();
     

    Supported scenarios are demonstrated in the unit tests (PlaceholderDifferenceEvaluatorTest).

    Default delimiters for placeholder are ${ and }. To use custom delimiters (in regular expression), create instance with the PlaceholderDifferenceEvaluator(String placeholderOpeningDelimiterRegex, String placeholderClosingDelimiterRegex) constructor.

    Since:
    2.6.0
    • Field Detail

      • PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
      • PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
      • PLACEHOLDER_PREFIX_REGEX

        private static final java.lang.String PLACEHOLDER_PREFIX_REGEX
      • KNOWN_HANDLERS

        private static final java.util.Map<java.lang.String,​PlaceholderHandler> KNOWN_HANDLERS
      • placeholderRegex

        private final java.util.regex.Pattern placeholderRegex
    • Constructor Detail

      • PlaceholderDifferenceEvaluator

        public PlaceholderDifferenceEvaluator​(java.lang.String placeholderOpeningDelimiterRegex,
                                              java.lang.String placeholderClosingDelimiterRegex)
        Creates a PlaceholderDifferenceEvaluator with custom delimiters.
        Parameters:
        placeholderOpeningDelimiterRegex - regular expression for the opening delimiter of placeholder, defaults to PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX if the parameter is null or blank
        placeholderClosingDelimiterRegex - regular expression for the closing delimiter of placeholder, defaults to PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX if the parameter is null or blank
    • Method Detail

      • isMissingTextNodeDifference

        private boolean isMissingTextNodeDifference​(Comparison comparison)
      • controlHasOneTextChildAndTestHasNone

        private boolean controlHasOneTextChildAndTestHasNone​(Comparison comparison)
      • cantFindControlTextChildInTest

        private boolean cantFindControlTextChildInTest​(Comparison comparison)
      • isTextCDATAMismatch

        private boolean isTextCDATAMismatch​(Comparison comparison)
      • isTextLikeNode

        private boolean isTextLikeNode​(org.w3c.dom.Node node)
      • isMissingAttributeDifference

        private boolean isMissingAttributeDifference​(Comparison comparison)
      • evaluateConsideringPlaceholders

        private ComparisonResult evaluateConsideringPlaceholders​(java.lang.String controlText,
                                                                 java.lang.String testText,
                                                                 ComparisonResult outcome)
      • isKnown

        private boolean isKnown​(java.lang.String keyword)
      • evaluate

        private ComparisonResult evaluate​(java.lang.String keyword,
                                          java.lang.String testText)