Forum Discussion

keikom1's avatar
keikom1
Occasional Contributor
15 years ago

How to create MockService response using request message

Hi, I think it's too easy question, but I'm a beginner of groovy and I have no idea how to do it. Could you please help me?
If the request message is
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.example.com/xx/sample">
<soapenv:Header/>
<soapenv:Body>
<sam:testMethod>
<ifCommonHeader>
<requestId>abcde</requestId>
<requestTimestamp>20101217093000</requestTimestamp>
<requestProgram>dummy</requestProgram>
</ifCommonHeader>
<messageBody>
<int_sample>0</int_sample>
<str_sample>zzz</str_sample>
<dec_sample>0.0</dec_sample>
</messageBody>
</sam:testMethod>
</soapenv:Body>
</soapenv:Envelope>

I'd like to create response message as below.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sam="http://www.example.com/sample">
<soapenv:Header/>
<soapenv:Body>
<sam:testMethodResponse>
<returnMessage>
<ifCommonHeader>
<requestId>abcde</requestId>
<requestTimestamp>20101217093000</requestTimestamp>
<requestProgram>dummy</requestProgram>
<result>OK</result>
</ifCommonHeader>
</returnMessage>
</sam:testMethodResponse>
</soapenv:Body>
</soapenv:Envelope>

I'd like to copy 'ifCommonHeader' from request message to response and add an element in ifCommonHeader. How can I write a script?

Thanks for your help.
  • I have just started using SoapUI to mock services. But now I need some dynamic behavior and I am totally and completely stuck. I have no clue whatsoever how to accomplish even the simplest task. The documentation is useless when it comes to implementing mock services.

    One of the features I need is transferring values from the mock request to the mock response (dates in this case). I guess it should be possible using 'property expansion' or a Groovy script. But I have no clue how. I just can't find any good examples and/or documentation.
  • eviware support wrote:
    Hi guys,
    We've just added the following to the documentation; http://www.soapui.org/Service-Mocking/c ... vices.html
    This document gives a bunch of examples on different types of scripts related to MockServices. If you are missing anything, please let us know!
    regards,
    /Ole
    eviware.com


    Ahhh...More input! Thank you very much. I will try to find time as soon as possible and play around with the new information. I am 100% convinced that dynamic mocks are going to save us a lot of time and effort. I just have to convince some developers and more importantly managers. For that I need a relatively easy way to create these dynamic mocks.