xml placeholder is not ignoring child nodes present under parent node.
This issue we faced while API Test Automation design. In our web service testing we trigger the API request (north bound) and checks the downstream request formed by application code. We use mocked backend using wiremock. Wiremock has capability equalToXml which support the matching of incoming request and expected request and thus test is validated.
Issue is while xml comparison using ${xmlunit.ignore} placeholder we are able to ignore the values from single node but not able to ignore anything entirely present under a particular node if that node has child nodes.
This would help in xml comparisons when some part in request is unknown or under development or its dynamic and of no interest for comparison etc. Issues was raised on wiremock project #1741 but later found that wiremock is using xmlunit as dependency.
Example:
<device>
<deviceType>Mobile</deviceType>
<IMEI>12345678912345</IMEI>
<deviceName>My Samsung</deviceName>
</device>
Above incoming request will match with
<device>
<deviceType>Mobile</deviceType>
<IMEI>${xmlunit.ignore}</IMEI>
<deviceName>${xmlunit.ignore}</deviceName>
</device>
/*****************************************************************/
But incoming request
<device>
<deviceType>Mobile</deviceType>
<deviceDetails>
<IMEI>12345678912345</IMEI>
<deviceName>My Samsung</deviceName>
</deviceDetails>
</device>
OR
<device>
<deviceType>Mobile</deviceType>
<deviceDetails>
<IMEI>12345678912345</IMEI>
<deviceName>My Samsung</deviceName>
<deviceSerialNumber>XYZ-123</deviceSerialNumber>
</deviceDetails>
</device>
does not match with
<device>
<deviceType>Mobile</deviceType>
<deviceDetails>${xmlunit.ignore}</deviceDetails>
</device>
The placeholder DSL currently applies to nested text content and to attributes values only. It would certainly be possible to also apply to other structures but the API and likely the DSL needs to be adjusted.
For you use case I can envison adding an extra namespace with attributes like
<deviceDetails xmlns:placeholders="https://www.xmlunit.org/placeholders" placeholders:ignore="recursive"/>
or something like this.
This is a non-trivial change and it may break backwards compatibility - which I personally can live with given that we still label the module as experimental. I'll add the "help wanted" label here as this feature will sure be implemented faster if if doesn't need to wait for me.
Thanks. But how this can be validated after implementation, I hope wiremock people can use it to create standalone jar even marked under experimental. We are using standalone wiremock jar and not custom implementation. Sorry I am not much aware about process since from testing background.
I don't know anything about the build process used by the wiremock people.
It most probably will work about this way: somebody implements the needed enhancement here, I will create a new XMLUnit release, the wiremock team decides they want to upgrade the version of XMLUnit they use and do so and then they create a new version of wiremock with the updated dependency. It may be possible to update XMLUnit without upgrading wiremock in your setup, but I wouldn't know how.
Realistically "somebody implements the needed enhancement here" likely takes the longest time of the steps I outlined.
Thanks. This will be helpful. I will track wiremock changes via wiremock issue once xmlunit is available with changes.
Hi, Any tentative timeline when this will be fixed?
It is somewhere on my TODO list, but that tends to grow rather than shrink :-)
Like I said "this feature will sure be implemented faster if if doesn't need to wait for me". I can't realistically promise any timeline.
Hi, @bodewig and @Devendra-Gawde, I have implemented the above proposed logic in the mentioned Draft MR, can you guys have a look and advise?
Certainly there are much more on this to make it as a proper MR, but the high level idea stay.
Thanks for your efforts. Actually I left the company previous year Feb, where I was facing this issue and project too where we were using wiremock and having that setup. But I hope somebody will benifit this who was facing similar issue.
I'm coming back to this way too late, I know.
I don't want to add any code to the core library for anything used inside the placeholders. Or rather I wouldn't want any special logic for magic attribute names inside of the difference engine. Adding new APIs in core that can be used by the placeholders project would be fine, though.