Skip to content
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

xml placeholder is not ignoring child nodes present under parent node. #250

Open
Devendra-Gawde opened this issue Jan 17, 2022 · 6 comments

Comments

@Devendra-Gawde
Copy link

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>
@bodewig
Copy link
Member

bodewig commented Jan 18, 2022

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.

@Devendra-Gawde
Copy link
Author

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.

@bodewig
Copy link
Member

bodewig commented Jan 21, 2022

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.

@Devendra-Gawde
Copy link
Author

Thanks. This will be helpful. I will track wiremock changes via wiremock issue once xmlunit is available with changes.

@Devendra-Gawde
Copy link
Author

Hi,
Any tentative timeline when this will be fixed?

@bodewig
Copy link
Member

bodewig commented Apr 3, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants