Forum Discussion

Brandon_C's avatar
Brandon_C
Occasional Contributor
15 years ago

Validation of incoming SOAP Request to a mock endpoint

Hello -

Is it possible to run assertions against a incoming request to a mock service running in soapUI?

What we need is the ability to run a suite that posts a message to a external service.  Then that external service sends a SOAP message to our MOCK service in soapUI.  The contents of that incoming request to the mock service needs to be validated against a schema or known good solution message. 

Right now, I can not see in the tool how I am able to get the incoming request to the mock service via api or otherwise.  Any help is appreciated in advance.  Thanks!

2 Replies

  • omrzljak's avatar
    omrzljak
    Occasional Contributor
    Hello
    Just use SCRIPT as Dispatch in MockOperation and add following in your script:
    // START SCRIPT
    def wsdlcontext = new com.eviware.soapui.impl.wsdl.support.wsdl.WsdlContext("file:\\D:\mypath\mywsdl.wsdl");
    def validator = new com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator(wsdlcontext);
    def msgExchange = new com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockRequestMessageExchange(mockRequest, mockOperation);
    def errors = validator.assertRequest(msgExchange, false);
    if (errors.length > 0 )
    return "Response 2"
    // END SCRIPT

    Change url in line 1 to point to your wsdl and define "Response 2" mock response with soap fault in it reporting validation error.
  • Thanks for hint !
    Here is generic XML schema validation groovy script for MockService "OnRequest Script":


    def wsdlcontext = context.mockService.getMockedInterfaces()[0].getDefinitionContext()
    def validator = new com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator(wsdlcontext);

    def operation = mockRequest.soapAction.substring(mockRequest.soapAction.lastIndexOf('/') +1)
    log.info context.mockService.toString() + "::" + operation
    def wsdlMockOperation = context.mockService.getMockOperationByName(operation)

    def msgExchange = new com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockRequestMessageExchange(mockRequest, wsdlMockOperation);
    def errors = validator.assertRequest(msgExchange, false);

    if (errors.length > 0 ) {
    throw new Exception("VALIDATION ERRORS: " + errors.collect(){ '\n' + it })
    }