2017-10-13 7 views
1

전 Wiremocks로 사례를 만들고 응답 모의를 생성하고 있습니다.Xpath 유효성 검사 wiremock matchesXPath expressions

는 I 이런 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> 

는 I에서만 유효 할 그런 XW : 입/XW :에서 element1 = 0100, XW : 입/XW :이 element2 = 741 및 I 그 xw : 글로벌 노드가 필요합니다. 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:gen[xw:input[xw:element1=\"0100\" and xw:element2=\"741\"]][xw:global/*]" 

그 어떤 xw:gen가 있는지 확인 위의 XPath :

  • [xw:input[xw:element1=\"0100\" and xw:element2=\"741\"]] : 아이를 언급 한 기준에 따라 xw:input을 입력하십시오.
  • [xw:global/*] : 적어도 하나의 다른 요소가 포함 된 자식 요소 xw:global이 있습니다. o f 임의의 이름
+0

안녕하세요 @ har07. 내 경우, 노드 xw : global은 일 수 있으며이 유효성 검사를 사용했습니다 :'[count (xw : globalObj)> 0]'. 그러나 귀하의 답변은 매우 유용합니다. 고맙습니다!! – dani77