10 April 2007 - 1.7 home user-guide eclipse jbossws intellij netbeans maven 1.X/2.X PDF files forums bugs sourceforge






Vote for soapUI at the WSJ Readers' Choice awards in the

'Best Web Services Utility' and

'Best Web Services Testing Tool'

categories

Mock Operations

A MockOperation corresponds to 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
  • Rename - prompts to rename the MockOperation
  • Remove - prompts to remove the MockOperation
  • Online Help - displays this page in an external browser

MockOperation Details Tab

The bottom left details tab for a MockService displays the following properties:
  • WSDL Operation - shows which Interface Operation that is being mocked
  • Dispatch Style - shows how incoming requests to this MockOperation are dispatched.

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)

Request Dispatching

Incoming requests to a MockOperation can be dispatched in one of 4 ways using the dispath 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 dispath 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:

  • context - an instance of MockRunContext that can hold dynamically user-defined properties. The context is service scoped, ie 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 below)
  • mockRequest - an instance of WsdlMockRequest which provides access to request-related objects, including the underlying HttpServletRequest/HttpServletResponse objects
  • mockResponse - an instance of WsdlMockResponse which provides access to the current MockResponse object (for example for dynamic manipulation of attachments)
  • log - a standard log4j Logger that logs to the groovy log tab

The script must return the name of the MockResponse to dispatch to, ie the script shown in the screenshot above always dispatches to a MockResponse named "Response 1"


Next: Mock Responses