0

开始使用 SoapUI,但不知道如何使用 Groovy 处理 Soap 响应。目前我的项目在 NetBeans 中打开,调试后将被复制粘贴到 SoapUI (eviware) 我的问题是:

def Input = """ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body>
      <ns2:getSalesAuditsResponse xmlns:ns2="http://apidto.dto.t2.wsapi.ng.com/">
         <return>
            <code>0909019000004830</code>
            <realOpenAmount>12</realOpenAmount>
            <dueDate>2009-07-11T00:00:00+03:00</dueDate>
         </return>
         <return>
            <code>0909119000006260</code>
            <realOpenAmount>55.75</realOpenAmount>
            <dueDate>2007-02-11T00:00:00+02:00</dueDate>
         </return>
      </ns2:getSalesAuditsResponse>    </S:Body> </S:Envelope>
    """

如何找到具有特定到期日期的“返回”节点?我可以假设,它可能在下一个:

def document = new groovy.util.XmlSlurper().parseText(Input);
def sa = document.depthFirst().findAll { it.@dueDate=="2007-02-01T00:00:00+02:00" }

但是在这种情况下 sa 是 [] 。毕竟如何删除原始 XML 中找到的节点?

我正在尝试使用 XMLHolder,但不知道如何在 SoapUI 中确实存在的 Netbeans“上下文”变量中对其进行初始化。

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(???context???) def dataHolder = groovyUtils.getXmlHolder( Input ) def data = dataHolder.getDomNode("//return[dueDate="2007-02- 11T00:00:00+02:00"]")

最后一个更普遍的问题:是否可以在 NetBeans 中调试 groovy 脚本并稍后在 SoapUI 3.0.1 中使用它?或者无法根据 groovy_for_SoapUI 的需要获取代码自动完成和文档?

非常感谢

4

1 回答 1

0

it.@dueDate 引用的是“dueDate”属性,而不是节点。其次,您正在代码中寻找“2007-02-01...”,我猜应该是“2007-02-11...”以匹配输入 XML 中的实际节点。

所以,这确实有效:

def Input = """ <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
      <S:Body>
        <ns2:getSalesAuditsResponse xmlns:ns2="http://apidto.dto.t2.wsapi.ng.com/">
           <return>
              <code>0909019000004830</code>
              <realOpenAmount>12</realOpenAmount>
              <dueDate>2009-07-11T00:00:00+03:00</dueDate>
           </return>
           <return>
              <code>0909119000006260</code>
              <realOpenAmount>55.75</realOpenAmount>
              <dueDate>2007-02-11T00:00:00+02:00</dueDate>
           </return>
       </ns2:getSalesAuditsResponse>
     </S:Body>
    </S:Envelope>
    """
def document = new groovy.util.XmlSlurper().parseText(Input);
def sa = document.depthFirst().findAll {it.dueDate == "2007-02-11T00:00:00+02:00"}

如果我打算修改 XML,我想我最终会使用标准 MarkupBuilder 或 StreamingMarkupBuilder 以我想要的形式输出新的 XML。

于 2009-09-22T17:26:04.850 回答