06 August 2007 - 1.7.5 |
soapUI 1.7 introduces the possibility to create mock implementations of operations and entire services with a combination of static response messages combined with groovy scripts, attachments and custom http-headers. This opens for a number of usage scenarios, including:
In the following example we will create a mock implementation of an existing service, tailor the mock response with some groovy and call the mock service from within soapUI. Start by creating a new project for the publicaly available CurrencyConverter at http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
After importing, you should get an interface with one operation and request. Right-click the interface and select the "Generate MockService" menu option:
This opens the following dialog which lets you specify the local port/path for the create service (can of course be changed later..);
Just leave the suggested values, for this and coming dialogs.. When the MockService has been created, you will get a new tree-hierarchy similar to the the initial Interface, but with grayed icons.. The MockService contains a MockOperation corresponding to the operation in the original interface and soapUI has also created one MockResponse for this operation from its schema.. Double click both the MockService and "Response 1" tree nodes to open their corresponding editors, after some moving/resizing arround you should be able to arrive at the following:
The MockService editor (top left) contains a toolbar, a list of all operations for the service and a request/response log which logs all incoming requests that have been handled by the MockService.
The MockResponse editor is very similar to the standard soapUI Request editor (which can/will be confusing at first ;-), only the "focus" has been shifted to the response-tabs of the editor, since this is where the editing of the mock response will be done. The "Incoming Request" tab/view shows the last received request to the operation (usefull for debugging client calls), including attachments nad http-headers.
In the screen above you can see the default response that has been generated by soapUI from the schema. Lets continue by just invoking this mock operation from within soapUI:
Switching back to the MockResponse editor and selecting its "Incoming Request" tab/view, you should be able to see the request that was posted to the MockService and handled by the corresponding MockOperation:
Congratulations! Hopefully all went well and you now have your first MockService up and running.. Feel free to modify the created MockResponse content and resubmitting the request to see that your changes are instantly available (no need to restart the MockService)
Let's continue by making the created mock response a bit more dynamic with a groovy script. Switch to the "Response Script" tab in the MockResponse editor and enter the following:
Go back to the Mock Response tab and change the response body to
Now, when submitting a request to this MockResponse, the script will be evaluated and the generated rate value will be inserted into the outgoing response message;
Ok.. this should get you started with your first mock service.. now you can continue with: