2017-10-13 13 views
1

私はWiremocksでケースを作成していますが、私はレスポンスモックを生成しています。XpathバリデーションのワイヤモックマッチXPath式

私はこのようなXML要求を持っている:入力/ XW:要素1 = 0100、XW:入力/ XW:要素2 = 741とI

<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ことを検証する必要があります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>" 
    } 
} 

質問です:グローバル空いていないかnullではない:私はノードXWがあることを検証することができますか?

私はこのmatchesXPathと試みたが、私は幸運持っていなかった。

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

ありがとうございました。

+0

スタブ定義に名前空間を指定しましたか?そうでなければ、XPath式でそれらを使用することはできません。 – Tom

+0

はい。私は名前空間を指定しました。ありがとう。 – dani77

答えて

1

私はwiremockに慣れていないんだけど、あなたは次のXPath試してみたいことがあります。子供がいる:

  • [xw:input[xw:element1=\"0100\" and xw:element2=\"741\"]]:という任意のxw:genがある場合は、チェックの上

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

    XPathをあなたが言及した基準を持つxw:input要素

  • [xw:global/*]:少なくとも1つの他の要素を含む子要素xw:global f任意の名前
+0

こんにちは@ har07。私の場合、ノードxw:globalはになります。この検証には '[count(xw:globalObj)> 0]'を使います。しかし、あなたの反応はとても役に立ちました。ありがとうございました!! – dani77