Book Image

SoapUI Cookbook

By : Rupert Anderson
Book Image

SoapUI Cookbook

By: Rupert Anderson

Overview of this book

Table of Contents (19 chapters)
SoapUI Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Selecting mock responses using Groovy


Moving on from basic single response mocks, it is often necessary to provide different mock responses depending on the request data. SoapUI offers some simple ways to do this; SOAP mocks offer dispatch types of RANDOM, SEQUENCE, XPATH, QUERY_MATCH, and SCRIPT. REST mocks currently only have the SEQUENCE and SCRIPT dispatch types. However, once mastered, SCRIPT is, by far, the most useful and flexible dispatch type. For details on the other dispatch types, see http://www.soapui.org/Service-Mocking/simulating-complex-behaviour.html.

To illustrate the use of the SCRIPT dispatch type, you're going to learn how content negotiation can be achieved in a REST mock. Often, RESTful web services provide what is called content negotiation to optionally produce either JSON, XML, or potentially other response formats depending on the request properties. This is very easy to do with SoapUI REST mocks.

Getting ready

The two main ways to do content negotiation are by using...