soapui teststep中的mockRequest变量用法

时间:2014-04-09 06:20:39

标签: groovy soapui

我正在使用soapui来测试REST应用程序。我想知道是否可以在groovy teststep中调用mockRequest变量?

我有以下groovy脚本:

import com.eviware.soapui.impl.wsdl.mock.WsdlMockResult;

def queryString = mockRequest.getHttpRequest().getQueryString()
def httpResponse = mockRequest.httpResponse
//log.info "HTTP Response is: "+httpResponse
def mediaType = mockRequest.getHttpRequest().getHeader("Content-Type")  
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

//This variable is used to get the soapui project path
def path = groovyUtils.projectPath + "/mockResponse/"

if (mockRequest.getMethod() == "POST" && mediaType=="application/xml"){
    def notifyRequest = mockRequest.requestContent
    def notifyXml = new XmlSlurper().parseText(notifyRequest)

    String representation = notifyXml.representation

    def decoded = new String(representation.decodeBase64())
    log.info "The decoded data received is: "+decoded

    new File("E:\\some_folder\\mockResponse\\1.xml").withWriter{ it << decoded } 

    WsdlMockResult mockResult = new WsdlMockResult(mockRequest)
     def Response = mockRequest.httpResponse
     httpResponse.setContentLength(0)
     Response.status = 200
     return mockResult

}

实际上我想要达到这样的结果:每当在MockService上收到消息时,都应该发送适当的响应。另外,我想从收到的请求消息中保存一些数据。这个功能对于每个测试用例都是不同的,因此我需要在groovy测试步骤而不是mockService的onRequest选项卡中进行。

有没有人有任何建议?

1 个答案:

答案 0 :(得分:0)

要自定义您的模拟服务的响应,请查看soapUI's guide on the same。您可以访问服务的脚本部分中的模拟服务收到的请求。

我的问题是,如果您使用模拟服务,为什么要保存收到的请求中的任何内容?