【问题标题】:SoapUI Mock. How to select response relying on tag value in requestSoapUI 模拟。如何根据请求中的标签值选择响应
【发布时间】:2017-07-14 15:17:01
【问题描述】:

我的 SOAP 请求如下所示:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gd="http://test.com/gds-mvmnt">
    <env:Header/>
    <env:Body>
        <ns1:getContainer env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
            <code xsi:type="xsd:string">PCK26397841</code>
            <messageId xsi:type="xsd:string"/>
        </ns1:getContainer>
    </env:Body>
    </env:Envelope>

我需要创建基于代码标签值选择响应的模拟。 无需修改响应。响应按原样添加到模拟中。只需要这样的逻辑:如果代码 A 然后响应 1,如果代码 B 然后响应 2 等等。 请帮助我编写基本的 groovy 脚本。

【问题讨论】:

  • 请检查解决方案,看看这是否是您所关注的。
  • 您有机会尝试解决方案吗?

标签: groovy mocking soapui groovyscriptengine


【解决方案1】:

这可以通过写简单的Script Dispatch来实现。

方法如下:

  • 检查请求是否为空
  • 定义一个由代码及其相应响应名称组成的映射
  • 从模拟请求中提取代码并根据上面的映射发送相应的响应
  • 希望你知道定义多个响应和脚本调度方法

这是脚本:

//Define desired code and response name
def responseMap = [A: 'Response1', B: 'Response2']

//Check if the request is not empty
assert mockRequest.requestContent, 'Request is empty'

//Extract the code
def code = new XmlSlurper().parseText(mockRequest.requestContent).'**'.find{it.name() == 'code'}?.text()

//Return the respective response
return responseMap[code]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    相关资源
    最近更新 更多