07 November 2008 - 2.5-beta2 user guide blog eclipse intellij netbeans maven PDF files forums bugs sourceforge eviware.com


Eviware Logo

Web Service Mock Operations

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.

MockOperation Actions

Right clicking a MockOperation node in the navigator or MockService editor shows a popup menu with the following actions:
  • Open MockOperation Editor - opens the MockOperation Editor, see below
  • Open Request - prompts to open an existing request for the operation being mocked with the endpoint set to the MockServices endpoint. This is the preferred way of quickly testing a MockService from within soapUI after the MockService has been started.
  • New MockResponse - prompts to add a new MockResponse to the MockOperation
  • Change Operation - prompts to change the Interface Operation mocked by this MockOperation (see below)
  • Rename - prompts to rename the MockOperation
  • Remove - prompts to remove the MockOperation
  • Online Help - displays this page in an external browser
Web Service Mocks - MockOperation Actions

MockOperation Details Tab

The bottom left details tab for a MockOperation displays the following properties:
  • Name : the name of the MockOperation
  • Description : an arbitrary description of the MockOperation, displayed as a tool tip over the MockOperations' node in the Navigator.
  • WSDL Operation - shows which Interface Operation that is being mocked
  • Dispatch Style - shows how incoming requests to this MockOperation are dispatched.

Change Operation

This action prompts to change the Operation mocked by this MockOperation with the following dialog:

The dialog options are as follows:

  • Name - changes the name of the MockOperation
  • Interface - the interface containing the operation to be mocked
  • Operation - the operation to be mocked
  • Recreate Responses - recreates all MockResponses contained in the MockOperation from the new operations schema.
  • Create Optional - creates optional content when recreating responses
  • Keep Existing - tries to keep existing element/attribute values when recreating responses (will only work for elements/attributes with same namespace/position in document

The MockOperation Editor

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:

  • Add MockResponse - Prompts to add a new MockResponse to the MockOperation
  • Open Request - prompts to open an existing request for the operation being mocked as described above
  • interface - The Interface containing the operation to be mocked
  • Operation - The operation to be mocked
  • Help - Opens this page in a browser

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)

Change MockOperation

Request Dispatching

Incoming requests to a MockOperation can be dispatched in one of 4 ways using the dispatch combo box:

  • Sequence - dispatches to the configured responses in sequence, starting from the beginning when the last has been reached.
  • Random - dispatches randomly between existing MockResponses
  • XPath - dispatches based on a specified XPath expression that will be used to select the name of the MockResponse step to dispatch to.
  • Script - allows a Groovy script for dispatching based on any arbitrary criteria

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.

Groovy Script Dispatching

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 log
  • context - 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 objects
  • MockOperation - an instance of WsdlMockOperation which provides access to the current MockOperation object

The 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"


Next: Simulated Web Service Responses - Mock Responses