gpt4 book ai didi

java - Xpath 验证wiremock 匹配XPath 表达式

转载 作者:行者123 更新时间:2023-11-30 06:27:55 27 4
gpt4 key购买 nike

我正在使用 Wiremocks 创建案例,并生成响应模拟。

我有一个像这样的 XML 请求:

<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>

我只需验证 xw:input/xw:element1 = 0100xw:input/xw:element2 = 741 并且我需要 xw:global节点有任何东西。 xw:global 的唯一条件不为空。 (该节点可以是 <xw:global></xw:global> )。

这是我的 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>"
}
}

问题是:如何验证节点 xw:global 不为空或不为空?

我尝试过使用 matchesXPath 但我没有运气:

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

谢谢。

最佳答案

我不熟悉wiremock,但您可能想尝试以下XPath:

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

上面的 XPath 检查是否有任何 xw:gen :

  • [xw:input[xw:element1=\"0100\"and xw:element2=\"741\"]] :有子元素​​ xw:input符合您提到的标准
  • [xw:global/*] :并且有子元素 xw:global 至少包含一个任意名称的其他元素

关于java - Xpath 验证wiremock 匹配XPath 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46737488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com