Hi! I need some help with request matching for XML...
# help
v
Hi! I need some help with request matching for XML. I have WireMock running as standalone instance on a remote server. We have some SOAP interactions I want to mock and I encountered issue with
equalToXml
matcher not matching tags with same value but in different order. Here is how I create stub:
Copy code
WireMock wm = new WireMock(<remove_host_options>);
    wm.register(post("/testurl")
        .withRequestBody(equalToXml("<body><entry>1</entry><entry>2</entry></body>"))
        .willReturn(aResponse().withBody("OK")));
And this request is not matching:
Copy code
POST /testurl HTTP/1.1
Content-Type: application/xml
Content-Length: 59

<body>
    <entry>2</entry>
    <entry>1</entry>
</body>
Is there a way to tell WireMock to ignore order of same tags? Thanks
l
By default WireMock does ignore the order of child elements. For example, both these xml snippets would match:
Copy code
<my-elements>
   <one />
   <two />
   <three />
</my-elements>
Copy code
<my-elements>
   <two />
   <three />
   <one />
</my-elements>
However, in your case I don't think this would make much difference because the data within the elements means they are technically different elements. You could tweak the comparison bing made by passing in options to the
exemptedComparisons
method. Perhaps the
TEXT_VALUE
option would work so the comparison doesn't take into account the values within the
entry
elements. Perhaps not ideal but it might be enough?
v
Unfortunately, I need matching of text within elements so this won't work. For time being I forked wiremock and made slight change to make it work
@Lee Turner do you plan to include this feature in the main build?
l
Do you want to put a PR together and we can take a look
v
sure, I can create a PR tomorrow
🙌 1