From 72ef3ad5eaede9fd04407516cd67b5891648e5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Fejzer?= Date: Wed, 7 Jun 2023 17:02:48 +0200 Subject: [PATCH] Configure PayloadDiffMatcher to ignore whitespace by default. Resolves #1203. --- .../matcher/xmlunit2/PayloadDiffMatcher.java | 1 + .../matcher/xmlunit2/PayloadDiffMatcherTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/spring-ws-test/src/main/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcher.java b/spring-ws-test/src/main/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcher.java index 457213511..dd2fb8933 100644 --- a/spring-ws-test/src/main/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcher.java +++ b/spring-ws-test/src/main/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcher.java @@ -60,6 +60,7 @@ protected Diff createDiff(Source payload) { Document actualDocument = createDocumentFromSource(payload); return DiffBuilder.compare(expectedDocument) // .withTest(actualDocument) // + .ignoreWhitespace() // .checkForSimilar() // .build(); } diff --git a/spring-ws-test/src/test/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcherTest.java b/spring-ws-test/src/test/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcherTest.java index 8d285aa7b..7726327f2 100644 --- a/spring-ws-test/src/test/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcherTest.java +++ b/spring-ws-test/src/test/java/org/springframework/ws/test/support/matcher/xmlunit2/PayloadDiffMatcherTest.java @@ -46,6 +46,22 @@ public void match() { verify(message); } + @Test + public void matchIgnoringWhitespace() { + + String xml = "true"; + String xmlWithAdditionalWhitespace = " true "; + WebServiceMessage message = createMock(WebServiceMessage.class); + expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2); + replay(message); + + PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource(xmlWithAdditionalWhitespace)); + matcher.match(message); + + verify(message); + } + + @Test public void nonMatch() {