-
Notifications
You must be signed in to change notification settings - Fork 311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed behavior for PayloadDiffMatcher #1203
Comments
Also upgrade XMLUnit to the 2.x version, using its AssertJ integration.
I suggest to put back |
Possible duplicate of #1193. See if Spring WS |
Hello, I have the same issue after migrating from Spring Boot 2.7.7 (Spring WS 3.1.4) to Spring Boot 2.7.8 (Spring WS 3.1.5). Here is my test setup : import org.custommonkey.xmlunit.XMLUnit;
import static org.springframework.ws.test.client.RequestMatchers.payload;
@SpringBootTest(...)
class MyTest {
static {
XMLUnit.setIgnoreWhitespace(true);
}
@Test
void test() {
MockWebServiceServer mockWSServer = MockWebServiceServer.createServer(...);
Source expectedRequestPayload = new ResourceSource(new ClassPathResource("request.xml"));
Source responsePayload = new ResourceSource(new ClassPathResource("response.xml"));
mockWSServer.expect(payload(expectedRequestPayload)).andRespond(withPayload(responsePayload));
// ...
}
}
I do not find any equivalent to Do you please have any suggestions ? Thank you in advance |
We are using
|
@marconak-itera Works like a charm 👍 ! |
@gregturn, the new XmlUnit 2 implementation of 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 45721351..bb276fff 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
@@ -59,6 +59,7 @@ public class PayloadDiffMatcher extends DiffMatcher {
Document expectedDocument = createDocumentFromSource(expected);
Document actualDocument = createDocumentFromSource(payload);
return DiffBuilder.compare(expectedDocument) //
+ .ignoreWhitespace() //
.withTest(actualDocument) //
.checkForSimilar() //
.build(); |
@gregturn sorry for the long answer. I check version 3.1.5, but behavior for |
Can you provide a detailed test case illustrating the issue? That would help pinpoint the issue. |
Test case that illustrating this issue: Endpoint package ru.razornd.ws;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import org.springframework.xml.transform.StringSource;
import javax.xml.transform.Source;
@Endpoint
public class TestEndpoint {
@PayloadRoot(localPart = "Request")
@ResponsePayload
public Source example() {
return new StringSource("""
<response>
<success>true</success>
</response>
""");
}
} Test class package ru.razornd.ws;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest;
import org.springframework.ws.test.server.MockWebServiceClient;
import org.springframework.xml.transform.StringSource;
import static org.springframework.ws.test.server.RequestCreators.withPayload;
import static org.springframework.ws.test.server.ResponseMatchers.payload;
@WebServiceServerTest(endpoints = TestEndpoint.class)
class TestEndpointTest {
@Autowired
MockWebServiceClient client;
@Test
void example() {
client.sendRequest(withPayload(new StringSource("<Request><Example>42</Example></Request>")))
.andExpect(payload(new StringSource("<response><success>true</success></response>")));
}
} if you run this test against version 3.0.10.RELEASE spring-ws-test it will succeed. But if you raise the version (for example, to 3.1.1), then an error will begin to appear that the messages are different.
That is, in other words, before version 3.1.1 you ignored spaces, and after that you started to take them into account when comparing messages. |
I've opened pull request with fix and minimal test case - without ".ignoreWhitespace() " it fails with "Messages are different, Expected child nodelist length '3' but was '1' ". |
Merged to |
Backported to |
You changed the behavior for PayloadDiffMatcher by removing the static initialization block from DiffMatcher. Whitespaces are no longer ignored when checking a payload. Changes in current commit
The text was updated successfully, but these errors were encountered: