0
votes

I am using soapui for testing a REST application. I want to know is it possible to call mockRequest variable inside a groovy teststep?

I have the following groovy script:

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

}

Actually I want to achieve a result such that whenever a message is received on MockService then appropriate response should be sent. Also, I want to save some data from the request message received. This functionality is different for each test case hence I need to do it in groovy test step instead of onRequest tab of mockService.

Does anyone has any suggestion?

1

1 Answers

0
votes

To customize your Mock Service's response have a look at soapUI's guide on the same. You will have access to the request received by the Mock Service in the script section of the service.

My question though is, if you are using a mock service why do you want to save anything from the request received?