Package org.xmlunit.placeholder
Class PlaceholderDifferenceEvaluator
- java.lang.Object
-
- org.xmlunit.placeholder.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 belowDiff 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)
orPlaceholderDifferenceEvaluator(String, String, String, String, String)
constructors.- Since:
- 2.6.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Pattern
argsRegex
private java.lang.String
argsSplitter
private static java.util.Map<java.lang.String,PlaceholderHandler>
KNOWN_HANDLERS
private static java.lang.String[]
NO_ARGS
static java.lang.String
PLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX
Pattern used to find then end of an argument list.static java.lang.String
PLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX
Pattern used to find the start of an argument list.static java.lang.String
PLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX
Pattern used to find an argument separator.static java.lang.String
PLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
Pattern used to find the end of a placeholder.static java.lang.String
PLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
Pattern used to find the start of a placeholder.private static java.lang.String
PLACEHOLDER_PREFIX_REGEX
private java.util.regex.Pattern
placeholderRegex
-
Constructor Summary
Constructors Constructor Description PlaceholderDifferenceEvaluator()
Creates a PlaceholderDifferenceEvaluator with default delimitersPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
andPLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
.PlaceholderDifferenceEvaluator(java.lang.String placeholderOpeningDelimiterRegex, java.lang.String placeholderClosingDelimiterRegex)
Creates a PlaceholderDifferenceEvaluator with custom delimiters.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.
-
Method Summary
-
-
-
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()
Creates a PlaceholderDifferenceEvaluator with default delimitersPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
andPLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
.
-
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 toPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
if the parameter is null or blankplaceholderClosingDelimiterRegex
- regular expression for the closing delimiter of placeholder, defaults toPLACEHOLDER_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 toPLACEHOLDER_DEFAULT_OPENING_DELIMITER_REGEX
if the parameter is null or blankplaceholderClosingDelimiterRegex
- regular expression for the closing delimiter of placeholder, defaults toPLACEHOLDER_DEFAULT_CLOSING_DELIMITER_REGEX
if the parameter is null or blankplaceholderArgsOpeningDelimiterRegex
- regular expression for the opening delimiter of the placeholder's argument list, defaults toPLACEHOLDER_DEFAULT_ARGS_OPENING_DELIMITER_REGEX
if the parameter is null or blankplaceholderArgsClosingDelimiterRegex
- regular expression for the closing delimiter of the placeholder's argument list, defaults toPLACEHOLDER_DEFAULT_ARGS_CLOSING_DELIMITER_REGEX
if the parameter is null or blankplaceholderArgsSeparatorRegex
- regular expression for the delimiter between arguments inside of the placeholder's argument list, defaults toPLACEHOLDER_DEFAULT_ARGS_SEPARATOR_REGEX
if the parameter is null or blank- Since:
- 2.7.0
-
-
Method Detail
-
evaluate
public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome)
Description copied from interface:DifferenceEvaluator
May alter the outcome of a comparison.- Specified by:
evaluate
in interfaceDifferenceEvaluator
- Parameters:
comparison
- the comparisonoutcome
- the current outcome of the comparison- Returns:
- the new result of the comparison.
-
isMissingTextNodeDifference
private boolean isMissingTextNodeDifference(Comparison comparison)
-
controlHasOneTextChildAndTestHasNone
private boolean controlHasOneTextChildAndTestHasNone(Comparison comparison)
-
cantFindControlTextChildInTest
private boolean cantFindControlTextChildInTest(Comparison comparison)
-
evaluateMissingTextNodeConsideringPlaceholders
private ComparisonResult evaluateMissingTextNodeConsideringPlaceholders(Comparison comparison, ComparisonResult outcome)
-
isTextCDATAMismatch
private boolean isTextCDATAMismatch(Comparison comparison)
-
isTextLikeNode
private boolean isTextLikeNode(org.w3c.dom.Node node)
-
isMissingAttributeDifference
private boolean isMissingAttributeDifference(Comparison comparison)
-
evaluateMissingAttributeConsideringPlaceholders
private ComparisonResult evaluateMissingAttributeConsideringPlaceholders(Comparison comparison, ComparisonResult outcome)
-
evaluateAttributeListLengthConsideringPlaceholders
private ComparisonResult evaluateAttributeListLengthConsideringPlaceholders(Comparison comparison, ComparisonResult outcome)
-
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)
-
-