Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
SoapUI Cookbook
SoapUI Cookbook

SoapUI Cookbook: Boost your SoapUI capabilities to test RESTful and SOAP APIs with over 65 hands-on recipes

Arrow left icon
Profile Icon Rupert Anderson
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (5 Ratings)
Paperback Feb 2015 328 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Rupert Anderson
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (5 Ratings)
Paperback Feb 2015 328 pages 1st Edition
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €29.99
Paperback
€36.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

SoapUI Cookbook

Chapter 2. Data-driven Testing and Using External Datasources

In this chapter, we will cover the following topics:

  • Creating and checking data with the JDBC Request TestStep
  • Parameterizing SQL queries with the JDBC Request TestStep
  • Setting properties from an external file
  • Importing CSV file data into an in-memory H2 database with Groovy
  • Looping over CSV file data and driving tests with Groovy
  • Querying MongoDB with Groovy
  • Publishing, browsing, and consuming ActiveMQ JMS messages via the REST API

Introduction

This chapter explores how to access and use common types of external data that you are likely to need in SoapUI test scenarios, for example, files, SQL databases, NoSQL databases, and JMS. While there isn't scope to cover every possible type or implementation, the building blocks learned here can be adapted to different situations and used as the basis for later recipes.

In terms of data-driven testing, we'll see how to support the pattern shown in the following image:

Introduction

In terms of options for reading the test data, we'll look only at those for the open source version of SoapUI. The pro version's data-driven features, for example, DataSource, DataSink, and DataLoop TestSteps are designed to be straightforward to use and receive adequate coverage in the online help (see http://www.soapui.org/Data-Driven-Testing/functional-tests.html), whereas achieving similar results in the open source version generally requires a little more initial setup, creativity, and...

Creating and checking data with the JDBC Request TestStep

If you need a quick way to access and check external SQL-based data, the JDBC Request TestStep is a good place to start. The pro version of the JDBC Request TestStep adds ease-of-use functionality, which is useful for less technical users, but by no means essential if you have a reasonable grasp of SQL and aren't afraid to enter a JDBC connection string (URL). We'll concentrate on using the open source version here.

Getting ready

As the example for this recipe, we'll access a MySQL database, but any JDBC data source would work, although the SQL syntax may vary. To use the JDBC Request TestStep, the main things we'll need are:

  • The database or access to it: If you don't already have MySQL, then download the latest version from http://dev.mysql.com/downloads/mysql/. The installation instructions for each platform are also provided there.
  • The JDBC driver: Please download the MySQL connector from http://dev.mysql...

Parameterizing SQL queries with the JDBC Request TestStep

This recipe builds directly on the last one to show how the JDBC Request TestStep can be used to execute parameterized SQL queries based on property values from outside the TestStep. This can be useful, as it allows the JDBC Request TestStep to query and check data based on properties set from the results of other TestSteps, for example, executing a query using an ID obtained from a web service response.

How to do it...

First, we add a new parameter with a fixed value to the JDBC Request TestStep and use it as the criteria for a simple select query. Then, we change the JDBC Request TestStep parameter to take its value from the value of a TestCase property. Perform the following steps:

  1. Edit the JDBC Request TestStep from the previous recipe and add a new parameter called invoiceIdParam with a value of 2.
  2. Then, modify the SQL Query value to add a where clause to specify that the invoice id field must be equal to the value of invoiceIdParam...

Setting properties from an external file

It can be a good idea to maintain your properties externally to your SoapUI project. This can help make your projects more flexible when switching between target environments, especially when running SoapUI from scripts (see Chapter 5, Automation and Scripting). In this recipe, we will see how to do this using the Properties TestStep.

Getting ready

I have added a sample properties file called test-properties.txt, which contains the following code:

environmentName=Dev Test
invoiceEndpoint=http://localhost:9000
userName=test
password=password

There is a completed sample project called PropertiesProject in the Chapter 2 samples.

How to do it...

First, we create a new empty project, TestSuite and TestCase. Then, we add a Property TestStep to read the properties from the test-properties.txt file using a project property to store the file's path. Finally, we write a Groovy TestStep to use property expansions to access the loaded property values from the...

Importing CSV file data into an in-memory H2 database with Groovy

There are times when you just need a quick database loaded with test data and don't want to persist, set up, or install anything. Well, this is where the in-memory mode of the H2 database engine can come in handy (http://www.h2database.com/)!

Getting ready

Before using the H2 database, we need to download its JAR and add it to SoapUI's classpath. You can get the latest H2 JAR from http://mvnrepository.com/artifact/com.h2database/h2/ (I took version 1.4.181). Then, add it to <SoapUI Installation Directory>/java/app/bin/ext/.

You'll also need some headed CSV data. Amazingly, the script might be able to handle any valid CSV structure (see http://www.h2database.com/html/functions.html#csvread). We'll use a simple invoice example invoices_with_headers.csv that can be found in the chapter 2 samples.

I have provided a completed SoapUI project GroovyInMemoryDB-soapui-project.xml in the Chapter2 samples.

How...

Looping over CSV file data and driving tests with Groovy

Whether it is for loading test data or writing reports, using external data files can be a key part of automated testing. Typically, you might need to read test data from a file and loop over some test steps until there is no more data. In this recipe, we see how this can be achieved easily using several reusable Groovy TestSteps.

Getting ready

For example, let's say we have a small CSV file of invoice data that we want to use to drive our tests:

1,comp1,100.0,2014-12-01 00:00:00
2,comp2,200.0,2014-12-02 00:00:00
3,comp3,300.0,2014-12-03 00:00:00

You can find this data in <chapter2 samples>/invoice.csv.

We will read each line and extract the values into properties, for example, to do something useful, for example, populating a web service request.

I have provided a completed SoapUI project GroovyFiles-soapui-project.xml in the Chapter2 samples.

How to do it...

I'm going to break this down into three separate Groovy TestSteps...

Introduction


This chapter explores how to access and use common types of external data that you are likely to need in SoapUI test scenarios, for example, files, SQL databases, NoSQL databases, and JMS. While there isn't scope to cover every possible type or implementation, the building blocks learned here can be adapted to different situations and used as the basis for later recipes.

In terms of data-driven testing, we'll see how to support the pattern shown in the following image:

In terms of options for reading the test data, we'll look only at those for the open source version of SoapUI. The pro version's data-driven features, for example, DataSource, DataSink, and DataLoop TestSteps are designed to be straightforward to use and receive adequate coverage in the online help (see http://www.soapui.org/Data-Driven-Testing/functional-tests.html), whereas achieving similar results in the open source version generally requires a little more initial setup, creativity, and often a higher level...

Creating and checking data with the JDBC Request TestStep


If you need a quick way to access and check external SQL-based data, the JDBC Request TestStep is a good place to start. The pro version of the JDBC Request TestStep adds ease-of-use functionality, which is useful for less technical users, but by no means essential if you have a reasonable grasp of SQL and aren't afraid to enter a JDBC connection string (URL). We'll concentrate on using the open source version here.

Getting ready

As the example for this recipe, we'll access a MySQL database, but any JDBC data source would work, although the SQL syntax may vary. To use the JDBC Request TestStep, the main things we'll need are:

Left arrow icon Right arrow icon
Download code icon Download Code

Description

This book is aimed at developers and technical testers who are looking for a quick way to take their SoapUI skills and understanding to the next level. Even if you are new to SoapUI but have basic Java skills and a reasonable grasp of RESTFul and Soap web services, then you should have no problem making use of this book.

Who is this book for?

This book is aimed at developers and technical testers who are looking for a quick way to take their SoapUI skills and understanding to the next level. Even if you are new to SoapUI but have basic Java skills and a reasonable grasp of RESTFul and Soap web services, then you should have no problem making use of this book.

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 27, 2015
Length: 328 pages
Edition : 1st
Language : English
ISBN-13 : 9781784394219
Category :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 27, 2015
Length: 328 pages
Edition : 1st
Language : English
ISBN-13 : 9781784394219
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 108.97
Web Services Testing with soapUI
€41.99
Mastering SoapUI
€29.99
SoapUI Cookbook
€36.99
Total 108.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. Testing and Developing Web Service Stubs With SoapUI Chevron down icon Chevron up icon
2. Data-driven Testing and Using External Datasources Chevron down icon Chevron up icon
3. Developing and Deploying Dynamic REST and SOAP Mocks Chevron down icon Chevron up icon
4. Web Service Test Scenarios Chevron down icon Chevron up icon
5. Automation and Scripting Chevron down icon Chevron up icon
6. Reporting Chevron down icon Chevron up icon
7. Testing Secured Web Services Chevron down icon Chevron up icon
8. Testing AWS and OAuth 2 Secured Cloud Services Chevron down icon Chevron up icon
9. Data-driven Load Testing With Custom Datasources Chevron down icon Chevron up icon
10. Using Plugins Chevron down icon Chevron up icon
11. Taking SoapUI Further Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(5 Ratings)
5 star 60%
4 star 20%
3 star 0%
2 star 0%
1 star 20%
Amazon Customer May 09, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book...Nicely explained the topics...Novice can also start reading ... very useful for experienced professionals also..Writer has done marvellous job..
Amazon Verified review Amazon
Sassy_n_glam Apr 28, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book. Give great insight about SoapUI advanced usage. Must buy for whoever wants to learn SoapUi in an easier and interesting manner.
Amazon Verified review Amazon
Larry Dalton May 27, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent
Amazon Verified review Amazon
Nick Talpos Oct 09, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Great book. I was looking for REST services. I found the perfect examples to get me going on my project with a very tight deadline. It was worth the money. It has much more than you find on the internet.
Amazon Verified review Amazon
Dubinam Mar 15, 2017
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Books is not updated with the SoapUi tool configurations. I bought the kindle version. I am not able to copy the code part to run it on the tool. The books mentions chapter samples , I dont see these in the kindle book. I cannot move further on practicing if I cannot see the samples and try out the codes. Am disappointed that the kindle version is not updated and is a waste of money.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.