amrinh
12 years agoNew Contributor
Is it possible to call mockRequest via a groovy test step?
Is it possible to call mockRequest via a groovy test step?
I want to know is it possible to call mockRequest variable inside a groovy teststep?
I have the following groovy script:
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?
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?