Skip to content

Commit

Permalink
Fix failing soapEnvelopeDiffMatcher
Browse files Browse the repository at this point in the history
The SoapEnvelopeDiffMatcher was untested at the MockWebServiceServer level. Upgrading to xmlunit2 fixed the issue.

Related: spring-projects#1193
  • Loading branch information
AlbericMartel committed Dec 8, 2022
1 parent dda1a3a commit a9de143
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 44 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
<wss4j.version>2.4.1</wss4j.version>
<xmlsec.version>3.0.1</xmlsec.version>
<xml-schema-core.version>2.2.2</xml-schema-core.version>
<xmlunit1.version>1.6</xmlunit1.version>
<xmlunit.version>2.7.0</xmlunit.version>
<xmlunit2.version>2.9.0</xmlunit2.version>
<xom.version>1.3.7</xom.version>
<spring-asciidoctor-backends.version>0.0.3</spring-asciidoctor-backends.version>
</properties>
Expand Down Expand Up @@ -219,7 +218,7 @@
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<version>${xmlunit.version}</version>
<version>${xmlunit2.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
8 changes: 4 additions & 4 deletions spring-ws-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
</dependency>

<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>${xmlunit1.version}</version>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>${xmlunit2.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -76,4 +76,4 @@
</profile>
</profiles>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static org.springframework.ws.test.support.AssertionErrors.*;

import org.custommonkey.xmlunit.Diff;
import org.springframework.ws.WebServiceMessage;
import org.xmlunit.diff.Diff;

/**
* Implementation of {@link WebServiceMessageMatcher} based on XMLUnit's {@link Diff}.
Expand All @@ -33,7 +33,7 @@ public abstract class DiffMatcher implements WebServiceMessageMatcher {
public final void match(WebServiceMessage message) throws AssertionError {

Diff diff = createDiff(message);
assertTrue("Messages are different, " + diff.toString(), diff.similar(), "Payload", message.getPayloadSource());
assertTrue("Messages are different, " + diff.toString(), !diff.hasDifferences(), "Payload", message.getPayloadSource());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;

import org.custommonkey.xmlunit.Diff;
import org.springframework.util.Assert;
import org.springframework.ws.WebServiceMessage;
import org.springframework.xml.transform.TransformerHelper;
import org.w3c.dom.Document;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;

/**
* Matches {@link Source} payloads.
Expand Down Expand Up @@ -58,7 +59,10 @@ protected final Diff createDiff(WebServiceMessage message) {
protected Diff createDiff(Source payload) {
Document expectedDocument = createDocumentFromSource(expected);
Document actualDocument = createDocumentFromSource(payload);
return new Diff(expectedDocument, actualDocument);
return DiffBuilder.compare(expectedDocument)
.withTest(actualDocument)
.checkForSimilar()
.build();
}

private Document createDocumentFromSource(Source source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMResult;

import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.springframework.util.Assert;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.xml.transform.TransformerHelper;
import org.w3c.dom.Document;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Diff;

/**
* Matches {@link Source} SOAP envelopes.
Expand All @@ -43,10 +43,6 @@ public class SoapEnvelopeDiffMatcher extends AbstractSoapMessageMatcher {

private final TransformerHelper transformerHelper = new TransformerHelper();

static {
XMLUnit.setIgnoreWhitespace(true);
}

public SoapEnvelopeDiffMatcher(Source expected) {

Assert.notNull(expected, "'expected' must not be null");
Expand All @@ -58,8 +54,12 @@ protected void match(SoapMessage soapMessage) throws IOException, AssertionError

Document actualDocument = soapMessage.getDocument();
Document expectedDocument = createDocumentFromSource(expected);
Diff diff = new Diff(expectedDocument, actualDocument);
assertTrue("Envelopes are different, " + diff.toString(), diff.similar());
Diff diff = DiffBuilder.compare(expectedDocument)
.ignoreWhitespace()
.withTest(actualDocument)
.checkForSimilar()
.build();
assertTrue("Envelopes are different, " + diff.toString(), !diff.hasDifferences());
}

private Document createDocumentFromSource(Source source) {
Expand Down
Loading

0 comments on commit a9de143

Please sign in to comment.