26 September 2007 - 1.7.6 | home user-guide eclipse jbossws intellij netbeans maven 1.X/2.X PDF files forums bugs sourceforge

Home
Getting Started
User Guide

- Overview
  - Tabbed Desktop
  - License Management
  - Preferences
  - XPath Selection
  - Script Library
- Workspaces
- Projects
- Interfaces
  - Interface Viewer
- Operations
- Working with Requests
  - Form Editor
  - Overview View
  - Outline Editor
  - Message Inspectors
  - Attachments/Inline Files
- Functional Testing
  - Getting Started
  - TestSuites
  - TestCases
    - Test Requests
      - Assertions
      - Editor Wizards
    - Property Transfers
    - Conditional Gotos
    - Groovy Scripts
      - Examples
      - GroovyUtils
    - Properties Step
    - Delay Step
    - Mock Response
    - DataSource
    - DataSource Loop
  - Property Expansion
- Load Testing
  - Getting Started
  - Limit & Strategies
  - Execution
  - Assertions
  - Diagrams
  - JMeter comparison
- Mocking
  - Getting Started
  - Mock Services
  - Mock Operations
  - Mock Responses
- Usage Scenarios
  - Data-Driven Testing
  - Template-Driven Testing
  - Interactive Testing
  - Surveillance Testing
- Tool Integrations
  - Code Generation
  - WSDL Generation
  - WS-I Tools
  - Apache Tcp-Mon
- CommandLine Tools
  - TestCaseRunner
  - LoadTestRunner
  - MockServiceRunner
  - ToolRunner
- Keyboard shortcuts

IDE/Tool Plugins
Search soapUI site
Project Documentation

- About soapUI
- Project Info
- Project Reports

## 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 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 |

### 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 tooltip 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 MockRespones 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)

### 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:

- `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, 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 above)
- `requestContext` - an instance of MockRunContext that can hold dynamically user-defined properties. The context is request scoped, ie 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, ie the script shown in the screenshot above always dispatches to a MockResponse named "Response 1"

Next: Mock Responses