Created
June 20, 2018 14:21
-
-
Save ledoyen/22fbe8a4a6e0e378935f84faae40f2e8 to your computer and use it in GitHub Desktop.
XML comparison with wildcards using XMLUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val diff = DiffBuilder.compare(expected).withTest(actual) | |
.withNodeMatcher(DefaultNodeMatcher(ElementSelectors.byNameAndAllAttributes, ElementSelectors.byName)) | |
.ignoreWhitespace() | |
.ignoreComments() | |
.withDifferenceEvaluator(DifferenceEvaluators.chain(DifferenceEvaluators.Default, XmlWildcardDifferenceEvaluator())) | |
.checkForSimilar() | |
.build() | |
assertThat(diff.differences).isEmpty() | |
class XmlWildcardDifferenceEvaluator : DifferenceEvaluator { | |
override fun evaluate(comparison: Comparison?, outcome: ComparisonResult): ComparisonResult { | |
var wildcardOutcome = outcome | |
if (wildcardOutcome == ComparisonResult.DIFFERENT) { | |
if(ComparisonType.TEXT_VALUE == comparison?.type || ComparisonType.ATTR_VALUE == comparison?.type) { | |
if("*" == comparison.controlDetails.value) { | |
wildcardOutcome = ComparisonResult.SIMILAR | |
} | |
} | |
} | |
return wildcardOutcome | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment