ProductivityAndFun Download Trial - Free 14 day evaluation

Mock Services - 4) Customizing a MockResponse

PDF Print E-mail
User Rating:  / 96
Rate this article: PoorBest 

4) Customizing a MockResponse

Let's continue by making the created MockResponse a bit more dynamic by changing the dispatch and by Groovy scripting.

  1. First we'll create a second MockResponse.
    Create a new MockResponse
  2. Give it a Groovy Name
    Groovy MockResponse
  3. Let's write a script for the response. Click the Script tab in the Response and enter the following Groovy Script,
    context.setProperty( "rate", Math.random() )
    It will look like this:
    script in MockResponse
    This script sets a property called rate to a random number. As you might have noticed we do not use the property rate anywhere, so let's add it.
  4. In the ConversionRateResult element enter the following:
    ${rate}
    This is called a Property expansion and it's a very powerful feature in SoapUI. By inserting a property expansion in any element you can then fill the element programatically. Basically it tells SoapUI to use the current value of property rate.
    PropertyTransfer set
  5. Now that we have written a script and the results will be inserted into the response, awesome!

Next Steps

That's it for now, but there is a lot of related material here on the soapui.org website, for example


Go to Article Page: Go to Previous Page 1 2 3 4 5