Tải bản đầy đủ (.pdf) (332 trang)

Web Services Testing with soapUI ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.97 MB, 332 trang )

www.it-ebooks.info
Web Services Testing
with soapUI
Build high quality service-oriented solutions by
learning easy and efcient web services testing
with this practical, hands-on guide
Charitha Kankanamge
BIRMINGHAM - MUMBAI
www.it-ebooks.info
Web Services Testing with soapUI
Copyright © 2012 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
First published: October 2012
Production Reference: 1191012
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84951-566-5
www.packtpub.com


Cover Image by Asher Wishkerman ()
www.it-ebooks.info
Credits
Author
Charitha Kankanamge
Reviewers
Evanthika Amarasiri
Bindu Laxminarayan
Ajay Pawar
Acquisition Editor
Kartikey Pandey
Lead Technical Editors
Hithesh Uchil
Azharuddin Sheikh
Technical Editors
Vrinda Amberkar
Ankita Meshram
Prashant Salvi
Project Coordinators
Sai Gamare
Shraddha Vora
Proofreader
Maria Gould
Indexer
Monica Ajmera Mehta
Graphics
Valentina D'Silva
Aditi Gajjar
Production Coordinator
Prachali Bhiwandkar

Cover Work
Prachali Bhiwandkar
www.it-ebooks.info
About the Author
Charitha Kankanamge is Manager, Quality Assurance and Senior Technical
Lead at WSO2 with more than 9 years of experience in Software Quality Assurance.
Charitha is specialized in SOA and middleware testing. He lead the WSO2 QA
team since 2007. He is also a committer of the Apache Software Foundation
contributing to Apache web services project. Charitha is interested in researching
new technologies in software-testing space as well as new trends in agile and
exploratory testing processes.
Prior to joining WSO2, Charitha has worked at Virtusa inc. for 3 years where he
was involved in multiple on-site and off-shore project assignments. In his rare
ofine moments, he enjoys playing guitar and watching movies.
Charitha has been involved in reviewing two books, Apache Jmeter, Emilly H.
Halili and Quick Start Apache Axis2, Deepal Jayasinghe both being published by
Packt Publishing.
Charitha can be reached through his blog:

www.it-ebooks.info
Acknowledgement
Making a book reality takes many dedicated people, and it is my great pleasure to
acknowledge their contributions.
First, I'd like to thank Packt Publishers, in particular, Kartikey Pandey – Senior
Acquisition Editor, who proposed me to write this book. I'm grateful for all the
help I got from the editorial staff at Packt Publishers in reviewing this book,
specially Hithesh Uchil – Lead Technical Editor and Sai Gamare who coordinated
the progress of writing, by ensuring that I stayed on track.
This book has beneted from a great set of technical reviewers. I'd like to thank
each of them for volunteering their time reviewing drafts of this book and providing

valuable feedback. Specially, my colleague at WSO2 QA team, Evanthika Amarasiri
who carried out in-depth quality assurance process in all chapters by executing
each sample.
I sincerely thank my wife, Thushari for her patience, support, and understanding
throughout the writing process. Many thanks to my beloved parents who raised me,
made me the person who I am today by providing their insightful guidance in all
aspects of my life.
Though I'm unable to name individually, I would like to extend my heartfelt
gratitude to many colleagues at WSO2, who never hesitated to give their support to
the fullest extent, whenever I requested help on various subject matters. I must thank
Dr. Sanjiva Weerawarana, Founder, Chairman and CEO of WSO2, Inc. whose vision
inspires me and guides me to accomplish my career aspirations.
Finally, a big thank goes to the developers and contributors of Smartbear software
for making soapUI the world's best open source web services testing tool.
www.it-ebooks.info
About the Reviewers
Evanthika Amarasiri joined 99X Techonology (former Eurocenter DDC Ltd.) in
2000 as a trainee QA Engineer. She has become competent in testing applications
based on Java, C++, VB and .NET, Lotus Notes, and in mobile application testing
(Symbian and J2ME). While she was working there, she studied for her B.Sc.
in Information Systems at the Informatics Institute of Technology, Sri Lanka,
which was afliated to the Manchester Metropolitan University, UK. She left 99X
Technology in 2006 and joined WSO2 Lanka (Pvt) Limited (in the same year) as a
Software Engineer - Quality Assurance. From 2006 to date, she has worked with
several leading middleware products of WSO2. During her stay at WSO2 she has
gained experience and knowledge on different kinds of web technologies, operating
systems, databases, application servers, and many QA testing tools. She has also
gained extensive experience in functional, usability, performance testing, as well
as QA test planning. By contributing to the Apache Synapse, which is a free and
open source software project, she has become a committer for the same. Currently

she is working as a Quality Assurance Technical Lead and is also a member of the
Management Committee in the Integration Technology team of WSO2.
I would like to thank my loving husband and my mother for all
the support given while reviewing this book. Also, a special thank
goes to my team mates for all the valuable inputs given, to make the
review process a success. My sincere gratitude goes to Charitha, the
author of the book, for selecting me as a reviewer for his book. He is
a great teacher/leader who has inspired us with his work. Without
his guidance and support, I would not have made this far in my
career. I wish him all the best for his future endeavors.
www.it-ebooks.info
Bindu Laxminarayan is an expert in Software Testing and Quality Assurance
with expertise in Test Automation Framework Design and Development. Over
the last 7 years, she has worked on various testing tools including but not limited
to SOAPUI, Jmeter and selenium on RESTful and SOAP Web Services. She is
currently working on Test Automation of Cloud Web Services and design patterns
in Automated Testing. Over the last two years she has presented at work on
StarEast Conference.
Ajay Pawar is an IBM middleware consultant having more than a decade of
experience. He is Director at ePower Consultancy Services UK. Ltd.
He started his career working on technologies such as Java, Java Swing, Java
EE, and then extended his experience in SOA world. He is an expert in IBM
middleware tools such as WebSphere Process Server (WPS), WebSphere
Integration Developer (WID), WebSphere MQ (WMQ), and Websphere Service
Registry and Repository (WSRR). He has also good air for web services testing.
He is procient in soapUI tool and he used it extensively for manual as well as
automation testing.
I would like to thank my wife Hema, sweet daughter Aarohi, and a
cute baby Vihaan for their constant support.
www.it-ebooks.info

www.PacktPub.com
Support les, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support les and downloads related
to your book.
Did you know that Packt offers eBook versions of every book published, with PDF
and ePub les available? You can upgrade to the eBook version at
www.PacktPub.
com
and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at for more details.
At
www.PacktPub.com, you can also read a collection of free technical articles,
sign up for a range of free newsletters and receive exclusive discounts and offers
on Packt books and eBooks.

Do you need instant solutions to your IT questions? PacktLib is Packt's online
digital book library. Here, you can access, read and search across Packt's entire
library of books.
Why Subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print and bookmark content
• On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view nine entirely free books. Simply use your login credentials
for immediate access.
www.it-ebooks.info
www.it-ebooks.info
www.it-ebooks.info
This book is dedicated to my parents, who have raised me to be the person I am today

and my beloved wife Thushari and my loving kids, Risith and Nethul.
www.it-ebooks.info
www.it-ebooks.info
Table of Contents
Preface 1
Chapter 1: Web Services Testing and soapUI 7
SOA and web services 8
Service-oriented solutions 8
Case study 8
Building blocks of SOA 9
Simple Object Access Protocol 11
Alternatives to SOAP 13
REST 13
Java Script Object Notation 14
Web Services Description Language 14
Message exchanging patterns 16
SOAP Faults 17
Approaches of testing web services 18
Unit testing of web services 19
Functional testing 19
Tool assisted testing 19
Using client APIs provided by service container middleware 19
Integration testing of web services 20
Performance testing of web services 20
The common challenges of Web services testing 20
Use of external web services 21
Implications of using complex standards and protocols 21
Headless nature of web services 21
What is soapUI? 22
Capabilities of soapUI 23

Installing soapUI 24
System requirements 24
www.it-ebooks.info
Table of Contents
[ ii ]
Installing soapUI on Linux 25
soapUI installation on Windows 27
Installing soapUI on MacOS 28
A glance at soapUI user interface 28
Summary 30
Chapter 2: The Sample Project 31
The problem domain 33
Project pre-requisites 34
Java 34
Apache Ant 34
MySQL 34
Setting up Apache Axis2 34
Setting up project source directories 35
Designing the web services 36
Creating the database 36
Implementing the web services 37
Web services fault handling 43
Managing database operations 45
Completing the web service implementation classes 47
Deploying web services 48
Summary 53
Chapter 3: First Steps with soapUI and Projects 55
Understanding the web services denition 55
Schema 56
portType 57

binding 58
Service 59
Creating a soapUI project 60
Invoking the guest management web service 64
A detailed look at SOAP requests and responses 67
Generating SOAP Faults 70
Summary 72
Chapter 4: Working with Your First TestSuite 73
A sample test scenario 73
Creating a TestSuite 74
Adding TestCases 78
addRoom TestCase 79
getRoomDetails TestCase 81
deleteRoom TestCase 81
www.it-ebooks.info
Table of Contents
[ iii ]
Running the rst TestSuite 81
Adding test assertions 84
Not SOAP Fault assertion 84
XPath Match assertion 86
The Contains assertion 88
Adding properties to soapUI tests 89
Reading property values from a le 90
Transferring property values between TestSteps 91
Summary 97
Chapter 5: Load and Performance Testing with soapUI 99
Non-functional testing of web services 100
Performance testing 101
Planning for web service performance testing 102

Using soapUI for performance testing 103
Working with load tests in soapUI 103
Limit of a load test 104
Threads in a soapUI load test 105
Load test strategies of soapUI 106
Simple load strategy 106
Burst load strategy 107
Thread load strategy 108
Variance strategy 109
A closer look at the load test report and statistics of soapUI 110
Using load test assertions in soapUI 112
The Max Errors assertion 113
The Step Average assertion 114
Step TPS assertion 115
The Step Maximum assertion 115
The Step Status assertion 116
LoadTest options 117
Summary 117
Chapter 6: Web Service Simulation with soapUI 119
Mocking in software testing 119
Mocking in web services testing 120
Mock services and contract-rst web service development 120
Simulating services that are not accessible 121
Dealing with test environmental restrictions 121
Mock services with soapUI 122
The structure of soapUI MockService 123
MockService details 125
MockOperation details 126
Dispatching styles of MockOperation 127
MockResponse details 129

www.it-ebooks.info
Table of Contents
[ iv ]
soapUI mock services in action 129
Static responses – the basic scenario 130
Using dynamic responses 131
Summary 138
Chapter 7: Advanced Functional Testing with soapUI 139
Introduction to web services extensions 140
What is WS-Addressing 141
What is WS-Security 143
WS-Policy 143
WS-SecurityPolicy 143
WS-Trust 144
WS-SecureConversation 144
Conguring Apache Axis2 for WS-Addressing and WS-Security 144
WS-Addressing in Apache Axis2 145
WS-Security in Apache Axis2 145
Testing the WS-Addressing with soapUI 146
Validating the WS-Addressing responses 149
Testing WS-Security with soapUI 150
Web service authentication 150
Securing GuestManagementService 151
Testing the secured GuestManagementService with soapUI 156
Project level WS-Security congurations in soapUI 159
Testing asymmetric binding policy with soapUI 161
Asymmetric binding 161
Signing SOAP messages 162
Securing RoomManagementService 165
Testing secured RoomManagementService with soapUI 169

Validating WS-Security responses 175
Summary 176
Chapter 8: Getting Started with REST Testing 177
Introduction to REST 178
Represent everything with URIs 178
Using standard HTTP methods 179
Linking resources together 179
Multiple representations of resources 180
Stateless communication 180
Testing RESTful APIs using soapUI 180
REST Services in soapUI 182
Request and response representation 188
Using POST or PUT requests in soapUI REST services 189
Reading POST message content from a le 191
Inserting the HTTP Basic Authentication header to requests 193
www.it-ebooks.info
Table of Contents
[ v ]
REST parameters 194
Query parameters 194
Template parameters 194
Matrix parameters 196
Header parameters 196
Functional testing of REST services 197
WADL 198
Summary 200
Chapter 9: Testing Databases with soapUI 201
Testing data in isolation 202
Setting up soapUI to connect to the database 203
JDBC Request TestStep 203

JDBC Request properties 206
JDBC test assertions 207
Stored procedures with JDBC Request TestStep 208
Accessing soapUI properties from SQL query 209
Summary 213
Chapter 10: JMS Testing with soapUI 215
Introduction to JMS 215
Setting up Apache ActiveMQ 216
JMS integration in soapUI 217
Working with JMS messaging in soapUI 222
Validating JMS responses 226
Verifying end-to-end JMS message delivery using the sample project 228
Conguring JMS in Apache Axis2 228
Conguring a session in HermesJMS 231
Adding a JMS endpoint in soapUI 233
Summary 233
Chapter 11: Extending soapUI with Scripting 235
Introduction to Groovy scripting language 236
What is Groovy? 236
HelloWorld with Groovy 237
Variable and object declaration in Groovy 238
Control structures in Groovy 239
Class and method declarations in Groovy 240
Groovy scripting in soapUI 241
The context object 242
The testRunner variable 245
www.it-ebooks.info
Table of Contents
[ vi ]
soapUI ModelItems 248

Setup and TearDown scripts in soapUI 250
Load Script at soapUI project level 252
Request and response handling using Scripts 254
Script assertion 255
Summary 256
Chapter 12: Automated Testing with soapUI 257
Test automation 258
Why is test automation essential in SOA? 258
Continuous Integration (CI) 260
soapUI JUnit integration 261
soapUI command line executions 266
Invoking a soapUI command line functional test runner 267
Invoking test runners from the soapUI graphical user interface 270
Maven soapUI plugin 273
Summary 280
Chapter 13: Miscellaneous Topics 281
soapUI IDE plugins 282
soapUI Eclipse plugin 282
soapUI IntelliJ IDEA plug-in 284
WS-I validation using soapUI 285
soapUI integration with external web services' frameworks 288
Sending attachments with SOAP messages using soapUI 292
Deploying an MTOM-enabled web service 294
Using soapUI to send an attachment to the web service 294
Summary 299
Index 301
www.it-ebooks.info
Preface
This book is all about using soapUI for functional and performance testing of
service-oriented solutions. soapUI can be used to test various aspects of a

service-oriented solution without merely playing the role of a web service
invocation tool. We will follow a simple tutorial-style approach throughout
the book in which we will explore all key features provided by soapUI based
on a sample web services project. This book is ideally designed to guide readers
to get more detailed insight on soapUI by doing a lot of hands-on exercises.
What this book covers
Chapter 1, Web Services Testing and soapUI, introduces soapUI by giving an overview
of its history, features, and installation of soapUI in your computer. We will begin
our journey towards learning soapUI by discussing some key characteristics of SOA,
Web services and Web services testing in general.
Chapter 2, The Sample Project, introduces the sample web services project which will be
used as the target application for functional and performance testing in the remaining
chapters of the book. In this chapter, we will build a simple web services based
application using Apache Axis2 open source web services framework. The primary
objective of building this sample application is to use it in all demonstrations of soapUI
features. As we will not discuss any topics related to soapUI or web services testing
in general in this chapter, you may skip the details and download the sample web
services project from
/>Chapter 3, First Steps with soapUI and Projects, serves as a guide for getting started with
soapUI projects. Based on one of the web services that we built as part of the sample
web services project in Chapter 2, The Sample Project, we will discuss the schema and
WSDL of the web service in detail. We will use soapUI to invoke the operations of
sample web service and discuss the SOAP requests, responses, and faults.
www.it-ebooks.info
Preface
[ 2 ]
Chapter 4, Working with Your First TestSuite, demonstrates the basic constructs of a
soapUI project—TestSuites, TestCases, and TestSteps—which prepares you for the
next chapters of the book. We will also look into the validation of responses using
assertions and soapUI properties.

Chapter 5, Load and Performance Testing with soapUI, covers the steps that you
would have to follow when using soapUI as a load and performance testing
tool. We will demonstrate the load test strategies provided by soapUI and the
load test specic assertions.
Chapter 6,Web Services Simulation with soapUI, briey describes how web services can
be simulated using soapUI. We will demonstrate the usage of soapUI mock services
model and static as well as dynamic mock responses.
Chapter 7, Advanced Functional Testing with soapUI, introduces the testing aspects of
web services extensions such as WS-Security and WS-Addressing. We will use an
improved version of the sample web services project which we built in Chapter 2,
The Sample Project for the demonstrations in this chapter.
Chapter 8, Getting Started with REST Testing, introduces the concepts related to
RESTful web services and how soapUI can be utilized in RESTful services testing.
We will demonstrate the use of soapUI in RESTful services testing by using a
publicly hosted sample web application.
Chapter 9, Testing Databases with soapUI, briey describes the direct database query
invocations of soapUI. In this chapter, we will discuss the database testing features
provided by soapUI such as JDBC requests and assertions.
Chapter 10, JMS Testing with soapUI, demonstrates the use of JMS in soapUI. By
exposing one of the sample web services over JMS transport, we will explore
the JMS testing capabilities provided by soapUI.
Chapter 11, Extending soapUI with Scripting, introduces the scripting facilities given
by soapUI in order to extend the default behavior of soapUI tests. We will look into
the use of soapUI API methods through Groovy scripts inside our tests.
Chapter 12, Automated Testing with soapUI, demonstrates various automated testing
approaches with soapUI. In this chapter, we will discuss the integration of soapUI
tests with build tools such as Apache Maven.
Chapter 13, Miscellaneous Topics, introduces some useful tools integrated with soapUI
such as WS-I validation tool and the utilities provided by external web services
framework such as Apache Axis2. This chapter also demonstrates the use of soapUI

when testing services by sending attachments.
www.it-ebooks.info
Preface
[ 3 ]
What you need for this book
We will make use of quite a lot of open source software to run the code samples in
this book. Firstly, you should install soapUI 4.0.1 or later version as explained in
Chapter 1, Web Services Testing and soapUI. You would require MySQL and Apache
Axis2-1.6.1 or later version to run the sample web services. You will also need
Apache Ant to build the sample web services project. Apache Rampart, Apache
Maven, Apache ActiveMQ, and Apache Wink open source libraries are required
for some demonstrations as explained in the respective chapters.
Who this book is for
If you are a part of a team that builds service-oriented solutions or makes use of web
services in your project, and your primary involvement is testing such a solution,
then this book is the ideal reference for you. This book will help you to understand
the common challenges of SOA testing and how soapUI can be utilized effective
manner in testing your applications.
This book would also be a good reference for developers and QA engineers who do
researches and evaluations on various commercial and open source web services
testing tools. If you are an experienced software professional or a novice tester, you
will quickly be able to learn the most important features of soapUI by following the
simple step-by-step instructions given in this book.
Conventions
In this book, you will nd a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.
Code words in text are shown as follows: "The
<s:Body> element carries the actual
message payload."

A block of code is set as follows:
CREATE TABLE IF NOT EXISTS ROOM_T(
room_number INT NOT NULL,
room_type VARCHAR(100) NOT NULL,
room_size varchar(100) NOT NULL,
PRIMARY KEY(room_number));
Any command-line input or output is written as follows:
create database HOTEL_RESERVATION_DB;
www.it-ebooks.info
Preface
[ 4 ]
New terms and important words are shown in bold. Words that you see on the
screen, in menus or dialog boxes for example, appear in the text like this: "You can
check the Create a desktop icon checkbox to create an icon on the desktop so can
you can easily launch soapUI".
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.
To send us general feedback, simply send an e-mail to
,
and mention the book title via the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on
www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.

Downloading the example code
You can download the example code les for all Packt books you have purchased
from your account at . If you purchased this book
elsewhere, you can visit and register to have
the les e-mailed directly to you.
www.it-ebooks.info
Preface
[ 5 ]
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you nd a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you nd any errata, please report them by visiting ktpub.
com/support
, selecting your book, clicking on the errata submission form link, and
entering the details of your errata. Once your errata are veried, your submission
will be accepted and the errata will be uploaded on our website, or added to any list
of existing errata, under the Errata section of that title. Any existing errata can be
viewed by selecting your title from />Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
Please contact us at
with a link to the suspected
pirated material.
We appreciate your help in protecting our authors, and our ability to bring you
valuable content.

Questions
You can contact us at if you are having a problem with
any aspect of the book, and we will do our best to address it.
www.it-ebooks.info
www.it-ebooks.info

×