07 November 2008 - 2.5-beta2 |
A MockOperation is a simulation of an operation in one of the current projects interfaces and will dispatch incoming requests if they match the operations SOAP Action and arguments. A MockOperation contains a variable number of MockResponses that contain actual response messages to be returned to a caller. Dispatching of requests to a specific MockResponse can be done in a number of ways as described below.
Right clicking a MockOperation node in the navigator or MockService editor shows a popup menu
with the following actions:
| ![]() |
The bottom left details tab for a MockOperation displays the following properties:
| ![]() |
This action prompts to change the Operation mocked by this MockOperation with the following dialog:
The dialog options are as follows:
Double-clicking a MockOperation in the navigator opens the MockOperation editor as seen below. From the top down the editor has the following parts:
A Toolbar with the following options:
The list of MockResponse currently configured for this MockOperation. Right-clicking show the MockResponses' available actions, double clicking opens the MockResponse editor
A Dispatch Toolbar and configuration are below whose content depends on the selected dispatch style (see below)
Incoming requests to a MockOperation can be dispatched in one of 4 ways using the dispatch combo box:
Both the XPath and Script dispatch methods allow specification of a default response to be returned if there is no matching response for the XPath or script expression. When selecting XPath or Script, a corresponding editor is shown below the dispatch toolbar where the XPath expression or Groovy script can be entered and tested. When running soapUI Pro, the XPath editor also includes a button for the XPath Selector.
Using Groovy scripts as a controller to dispatch incoming is a very flexible way of creating MockOperations. The script has access to the following variables:
The script has access to the following objects:
log
- a standard log4j Logger for logging arbitrary information to the Groovy logcontext
- an instance of
MockRunContext
that can hold dynamically user-defined properties. The context is service scoped, i.e. shared between
all MockOperations/MockResponses for a MockService during its lifetime. Since this object implements the Map
interface
it can be accessed using Groovy?s built-in collection support (see example screenshot above)requestContext
- an instance of
MockRunContext
that can hold dynamically user-defined properties. The context is request scoped, i.e. is only available during this
request and not shared with other MockOperations. Use this to pass values from the dispatch script to the handling
MockResponse. Since this object implements the Map
interface
it can be accessed using Groovy?s built-in collection support (see example screenshot above)MockRequest
- an instance of
WsdlMockRequest
which provides access to request-related objects, including the underlying HttpServletRequest/HttpServletResponse objectsMockOperation
- an instance of
WsdlMockOperation
which provides access to the current MockOperation objectThe script must return the name of the MockResponse to dispatch to, i.e. the script shown in the screenshot above always dispatches to a MockResponse named "Response 1"