1

I have two xml requests as below, just wanted to get the response. Response1 if request body contains node A, B, C and does not contains D. Response2 if A,B, C, D all contains in request.

Can someone please help me on this.

Also it would be helpful if someone can help me to get good articles on request matching using body pattern or what are the different options available for body pattern.

Thanks in Advance!!

I have tried contains and priority, but that didn't help.

Req1:

<TestService>
    <A> test </A>
    <B> testB</B>
    <C> testC </C>
    <XYZ> test </XYZ>
</TestService>

Req2:

<TestService>
    <A> test </A>
    <B> testB</B>
    <C> testC </C>
    <XYZQ> test test</XYZQ>
   <D> testD</D>
</TestService>
howie
  • 2,587
  • 3
  • 27
  • 43
techavi053
  • 11
  • 2
  • Please stop destroying XML ecosystem with regexes... Just use a DTD or a XSD schema to very your XML grammar. https://stackoverflow.com/questions/1544200/what-is-difference-between-xml-schema-and-dtd – Allan Mar 26 '19 at 06:13

1 Answers1

0

In WireMock it would likely end up in 2 rules, one for each scenario:

Rule for when the tag is there:

{
"request": {
 "method": "ANY",
 "url": "/xmltag",
 "bodyPatterns" : [ {
   "matchesXPath" : "/TestService[count(//D) = 1]"
 } ]  
},
"response": {
 "status": 200,
 "body": "<root><tag>D</tag></root>"
}
}

then another for when there is no D tag:

{
"request": {
 "method": "ANY",
 "url": "/xmltag",
 "bodyPatterns" : [ {
   "matchesXPath" : "/TestService[count(//D) = 0]"
 } ]  
},
"response": {
 "status": 200,
 "body": "<root><tag>No D found</tag></root>"
}
}
A. Kootstra
  • 6,827
  • 3
  • 20
  • 43