Polishing.

See #1203.
This commit is contained in:
Greg L. Turnquist
2023-07-14 14:40:29 -05:00
parent 3f322a8878
commit 1d4e2dc88b
2 changed files with 16 additions and 7 deletions

View File

@@ -16,7 +16,7 @@
package org.springframework.ws.test.support.matcher.xmlunit2;
import static org.springframework.ws.test.support.AssertionErrors.fail;
import static org.springframework.ws.test.support.AssertionErrors.*;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
@@ -33,6 +33,7 @@ import org.xmlunit.diff.Diff;
* Matches {@link Source} payloads.
*
* @author Greg Turnquist
* @author Mikołaj Fejzer
* @since 3.1
*/
public class PayloadDiffMatcher extends DiffMatcher {
@@ -42,22 +43,28 @@ public class PayloadDiffMatcher extends DiffMatcher {
private final TransformerHelper transformerHelper = new TransformerHelper();
public PayloadDiffMatcher(Source expected) {
Assert.notNull(expected, "'expected' must not be null");
this.expected = expected;
}
@Override
protected final Diff createDiff(WebServiceMessage message) {
Source payload = message.getPayloadSource();
if (payload == null) {
fail("Request message does not contain payload");
}
return createDiff(payload);
}
protected Diff createDiff(Source payload) {
Document expectedDocument = createDocumentFromSource(expected);
Document actualDocument = createDocumentFromSource(payload);
return DiffBuilder.compare(expectedDocument) //
.withTest(actualDocument) //
.ignoreWhitespace() //
@@ -66,11 +73,14 @@ public class PayloadDiffMatcher extends DiffMatcher {
}
private Document createDocumentFromSource(Source source) {
try {
DOMResult result = new DOMResult();
transformerHelper.transform(source, result);
return (Document) result.getNode();
} catch (TransformerException ex) {
fail("Could not transform source to DOMResult" + ex.getMessage());
return null;
}

View File

@@ -16,11 +16,8 @@
package org.springframework.ws.test.support.matcher.xmlunit2;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.assertj.core.api.Assertions.*;
import static org.easymock.EasyMock.*;
import javax.xml.soap.MessageFactory;
@@ -37,6 +34,7 @@ public class PayloadDiffMatcherTest {
String xml = "<element xmlns='http://example.com'/>";
WebServiceMessage message = createMock(WebServiceMessage.class);
expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2);
replay(message);
@@ -52,6 +50,7 @@ public class PayloadDiffMatcherTest {
String xml = "<response><success>true</success></response>";
String xmlWithAdditionalWhitespace = "<response> <success>true</success> </response>";
WebServiceMessage message = createMock(WebServiceMessage.class);
expect(message.getPayloadSource()).andReturn(new StringSource(xml)).times(2);
replay(message);
@@ -61,7 +60,6 @@ public class PayloadDiffMatcherTest {
verify(message);
}
@Test
public void nonMatch() {
@@ -69,6 +67,7 @@ public class PayloadDiffMatcherTest {
String actual = "<element1 xmlns='http://example.com'/>";
WebServiceMessage message = createMock(WebServiceMessage.class);
expect(message.getPayloadSource()).andReturn(new StringSource(actual)).times(2);
replay(message);