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 }. Arguments to placeholders are by default enclosed in ( and ) and separated by , - whitespace is significant, arguments are not quoted.

    To use custom delimiters (in regular expression), create instance with the PlaceholderDifferenceEvaluator(String, String) or PlaceholderDifferenceEvaluator(String, String, String, String, String) constructors.

    Since:
    2.6.0
    • Field Detail

      • PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
        Pattern used to find the start of a placeholder.
      • PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
        Pattern used to find the end of a placeholder.
      • PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX
        Pattern used to find the start of an argument list.
        Since:
        2.7.0
      • PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX
        Pattern used to find then end of an argument list.
        Since:
        2.7.0
      • PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX

        public static final java.lang.String PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX
        Pattern used to find an argument separator.
        Since:
        2.7.0
      • 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
      • NO_ARGS

        private static final java.lang.String[] NO_ARGS
      • placeholderRegex

        private final java.util.regex.Pattern placeholderRegex
      • argsRegex

        private final java.util.regex.Pattern argsRegex
      • argsSplitter

        private final java.lang.String argsSplitter
    • 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
      • PlaceholderDifferenceEvaluator

        public PlaceholderDifferenceEvaluator​(java.lang.String placeholderOpeningDelimiterRegex,
                                              java.lang.String placeholderClosingDelimiterRegex,
                                              java.lang.String placeholderArgsOpeningDelimiterRegex,
                                              java.lang.String placeholderArgsClosingDelimiterRegex,
                                              java.lang.String placeholderArgsSeparatorRegex)
        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
        placeholderArgsOpeningDelimiterRegex - regular expression for the opening delimiter of the placeholder's argument list, defaults to PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX if the parameter is null or blank
        placeholderArgsClosingDelimiterRegex - regular expression for the closing delimiter of the placeholder's argument list, defaults to PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX if the parameter is null or blank
        placeholderArgsSeparatorRegex - regular expression for the delimiter between arguments inside of the placeholder's argument list, defaults to PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX if the parameter is null or blank
        Since:
        2.7.0
    • 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,
                                          java.lang.String[] args)