3

I am creating cases with Wiremocks and I am generating a response mock.

I have a XML request like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xw="http://example.com">
    <soapenv:Header/>
    <soapenv:Body>
        <xw:gen>
            <xw:input>
                <xw:element1>0100</xw:element1>
                <xw:element2>741</xw:element2>
                <xw:element3>JAVA</xw:element3>
                <xw:element4>123</xw:element4>
            </xw:input>
            <xw:global>
                <xw:obj1>
                    <xw:attr1>john</xw:attr1>
                    <xw:attr2>doe</xw:attr2>
                </xw:obj1>
            </xw:global>
        </xw:gen>
    </soapenv:Body>
</soapenv:Envelope>

I only have to validate that xw:input/xw:element1 = 0100, xw:input/xw:element2 = 741 and I need that the xw:global node has anything. The only condition for xw:global is not empty. (This node can be <xw:global></xw:global>).

This is my mock in json:

{
    "request" : {
        "url" : "/myweb/myrequest.asmx",
        "headers": {
            "SOAPAction": {
                "equalTo": "\"http://example.com/gen\""
            }
        },
        "bodyPatterns" : [ {
            "matchesXPath": "//xw:input[xw:element1=\"0100\" and xw:element2=\"741\" ]",
            "xPathNamespaces" : {
                "xw" : "http://example.com"
            }
        }]
    },
    "response" : {
        "status" : 200,
        "headers": {
            "Content-Type": "text/xml;charset=UTF-8"
        },
        "body" : "<Abody>"
    }
}

The question is: how I can validate that the node xw:global is not empty or is not null?

I tried with this matchesXPath but I didn't have lucky:

"matchesXPath": "//xw:input[xw:element1=\"0100\" and xw:element2=\"741\" ] and count(//xw:global) > 0".

Thanks.

dani77
  • 199
  • 2
  • 5
  • 26

1 Answers1

2

I'm not familiar with wiremock, but you may want to try the following XPath :

"//xw:gen[xw:input[xw:element1=\"0100\" and xw:element2=\"741\"]][xw:global/*]"

The XPath above check if there is any xw:gen that :

  • [xw:input[xw:element1=\"0100\" and xw:element2=\"741\"]] : have child element xw:input with the criteria you mentioned
  • [xw:global/*] : and have child element xw:global containing, at least, one other element of any name
har07
  • 88,338
  • 12
  • 84
  • 137
  • Hi @har07. In my case the node xw:global can be and I used this validation: `[count(xw:globalObj)>0]`. But your response has been very useful. Thank you!! – dani77 Oct 17 '17 at 13:49