Introduction to Web Services and Testing
In this age, information exchange is of prime importance and web services provide for this message exchange from application to application. Web services serve as vital constituents for service oriented solutions and are extensively used in enterprise applications.
SOA and Web Services
A web service is the method of communication between two devices over the internet or World Wide Web.
Service Oriented Architecture is an approach to build enterprise solutions using loosely coupled and reusable components.
The building blocks of SOA are web services, mediation and composition.
The individual units of business logic in SOA are the web services. They communicate with other programs and applications by sending messages. The web service is hosted in a service container which is the middleware in SOA.
The business logic is hosted in the container and is accessible through the service interface as seen in the diagram above.
In mediation, the received message undergoes transformation as necessary. Then this transformed message is fed to the system. The SOA middleware for message mediation is a broker, the usual one being Enterprise service bus.
Composition refers to use of several web services together to facilitate a business functionality.
SOAP and WSDL
The Web Service Description language or the WSDL is an interface description language based on XML. It describes the functionality offered by the web service.
Simple Object Access Protocol or SOAP is a language independent, platform independent communication protocol for exchanging messages over the internet. This too is based on the standard XML.
Introduction to soapUI
Now what is soapUI? As the name suggests, this tool provides the UI or user interface to test the web services and soap requests/response. This is an open source tool with a pro version available for advanced features. For now, let us restrict ourselves with the open source version. soapUI is capable of performing both functional and non-functional tests on the web service. Further details on soapUI can be found at http://www.soapui.org.
Downloading and Installing soapUI
soapUI for Windows, Mac or Linux can be downloaded from http://sourceforge.net/projects/soapui/files/.
Installing soapUI is quite straight forward and simple. Install it with the general recommended settings for now.
Trying your Hands on soapUI on Windows
Now, as you have installed soapUI on your system, let's get started with a very simple project to give you a brief understanding on how things work. We will consider a weather forecast web service exposed on the internet for our demo project. The wsdl for the same is http://www.webservicex.net/globalweather.asmx?WSDL.
Once soapUI opens, go to file menu on the top left and create a new soap project. When the create new project pop up appears, provide a desired name and in the field below where the wsdl is required, provide the one mentioned above. Note that it is not mandatory to add a wsdl initially to your project. After adding the wsdl to the field, just click “OK” without making changes to the default settings for now.
After this is done, you should be able to see on the left hand side that there is a tree of the project as shown in the figure below:
In this figure, we see there are two soaps, namely
GlobalWeatherSoap12. These are nothing but the soap binding versions. Let us focus on the former one for now. Here, we see the following services which are
GetWeather. Let us select any one service, let us say
GetWeather. Click on the tree to expand the service. The view should look like the image shown below:
Now double click on the soap
Request1, upon doing so, a request response editor shows up as shown in the image below:
The left editor is the request editor and the corresponding response is displayed in the right pane.
In the set of code in the request editor, you should be able to see two question marks like this ‘?’ within the
CountryName tags. Replace these with a set of proper values and click on the green play button on the top left corner of the editor to run it. I have entered the city name as “
New Delhi” and country name as “
India”. The subsequent response pane should look like this:
Here, we see that the request we sent fetched a proper response, in our case the weather of New Delhi was displayed. However we are not judging the accuracy of the weather data we get in the response pane. Now try some random and inappropriate values in the request editor and run.
The response for inappropriate values will result in a response shown below:
There occurs a soap fault due to inappropriate values which were not found in the service database. The resulting fault
string is being displayed in the response pane.
Creating test cases and test suites and further topics will be covered in the coming blog posts. Hope you have enjoyed and learnt so far.