Ich erstelle Fälle mit Wiremocks und ich erzeuge eine Antwort Mock.Xpath Validierung Wiremock matchesXPath Ausdruck
Ich habe eine XML-Anforderung wie folgt aus:
<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>
ich nur bestätigen, dass xw: Eingabe/xw: element1 = 0100, xw: input/xw: element2 = 741 und ich muss, dass der xw: global Knoten alles hat. Die einzige Bedingung für xw: global ist nicht leer. (Dieser Knoten kann <xw:global></xw:global>
sein).
Das ist mein 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>"
}
}
Die Frage ist: wie ich bestätigen kann, dass der Knoten xw: global nicht leer ist oder nicht null?
ich mit diesem matchesXPath versucht, aber ich nicht das Glück hatte:
"matchesXPath": "//xw:input[xw:element1=\"0100\" and xw:element2=\"741\" ] and count(//xw:global) > 0"
.
Danke.
Haben Sie die Namespaces in der Stubdefinition angegeben? Wenn nicht, können Sie sie nicht im XPath-Ausdruck verwenden. – Tom
Ja. Ich habe die Namensräume angegeben. Vielen Dank. – dani77