Functional Web Services Testing Made Easy with SoapUI - Part 3
In the first two parts(part 1 and part 2) of this series we have seen how to use SoapUI to write functional tests for web services and also how to use Groovy for test setup, properties transfer, and assertions. As we have already said, tests should be integrated with your builds and should be able to be run with them. If you have automated your builds and they are running as part of your continuous integration (CI) setup, SoapUI comes in even handier: you can run the test suites and the test cases you created and, moreover, you can generate JUnit reports.
This part of the series guides you step-by-step through the Ant tasks for running tests written using SoapUI, generating JUnit reports, integrating with CI, and to top it all off getting code coverage using Cobertura. When you are done with this part, you will be able to reap the benefits of writing tests, continuous integration, and code coverage.
The project we will use is the famous PetStore from Sun’s BluePrints. We will use JPA (with Toplink) for the persistence tier and session beans for the business tier; by adding simple annotations we will publish these session beans as web services. This project has no front end. It will be deployed to the JEE reference app server GlassFish. This is a prototype written for this series in less than an hour using the NetBeans IDE. However, we will pass over the details of project creation in favor of keeping our eyes on the prize: using SoapUI and Ant, generating JUnit reports, integration with CI, and code coverage.
package com.stelligent.biz.ws;
import java.util.Collection;
import javax.ejb.Remote;
import com.stelligent.ent.jpa.Account;
/**
*
* @author msubbarao
*/
@Remote
public interface AccountManager
{
public Account create(Account info);
public Account update(Account info);
public void remove(Account info);
public Account[] findAllAccounts();
public Account findByUsername(String username);
}
Implementation Class for Account Manager with annotations for web services:
package com.stelligent.biz.ws;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.persistence.*;
import com.stelligent.ent.jpa.Account;
import java.util.*;
/**
*
* @author msubbarao
*/
@WebService(name="AccountManager", serviceName = "AccountManagerService", targetNamespace = "urn:AccountManagerService")
@SOAPBinding(style = SOAPBinding.Style.RPC)
@Stateless(name="AccountManager")
public class AccountManagerBean implements AccountManager
{
@PersistenceContext
private EntityManager manager;
@WebMethod
public Account create(Account info)
{
this.manager.persist(info);
return info;
}
/**
* Updates the Account entity.
*
* @param info the Account object used to update.
* @return the info object.
*/
@WebMethod
public Account update(Account info)
{
return this.manager.merge(info);
}
/**
* Removes the Account entity.
*
* @param info the Account object used to update.
*/
@WebMethod
public void remove(Account info)
{
this.manager.remove(this.manager.getReference(Account.class, info.getUserid()));
}
/**
* Retrieves all the Account entities as an array.
*
* @return the objects as a Account array.
*/
@WebMethod
public Account[] findAllAccounts()
{
Query query = this.manager.createQuery("SELECT o FROM Account o");
java.util.List<Account> accounts = new java.util.ArrayList<Account>();
java.util.Iterator<Account> iter = query.getResultList().iterator();
while (iter.hasNext())
{
accounts.add(((Account) iter.next()));
}
return (Account[]) accounts.toArray(new Account[accounts.size()]);
}
/**
* This method retrieves the Account entity info using the primary key.
*
* @param username the String
* @return the object as a AccountInfo or null if not found.
*/
@WebMethod
public Account findByUsername(final String username)
{
try
{
return (Account) this.manager.find(Account.class, username);
}
catch (Exception e)
{
return null;
}
}
}
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
David Sills replied on Mon, 2008/05/19 - 8:46am
SumaBS replied on Mon, 2008/05/19 - 1:34pm
Sreekant Rajan replied on Thu, 2008/05/22 - 3:32pm
hi
I would like to know whether SOAPUI support complextype as input values.
2. whether it provides UI based support of testing Webservices
3. whether it generate test result in the report fasion.
if you have any product which support all these let me know.
Sreek
Meera Subbarao replied on Thu, 2008/05/22 - 4:10pm
Hi Sreekant,
Everything you have asked above is what SoapUI is. Also, the AccountManagerBean code shown in this page has all the methods except remove method return a complex type, which in my case is the Account entity object. And the create method does take Account as its input as shown below.
Srimaan Yerram replied on Sun, 2008/07/20 - 2:12pm
ali raza replied on Fri, 2008/08/01 - 8:49pm
hi,
I am trying to specify my Test Report XML from soapui
as
C:\Results\2008-08-01_17-32-28\28\report.xml
and I get teh following error in hudson.
What am I doing wrong. why am I getting this error when the report.xml file exists.
Tommy Van Mellaert replied on Thu, 2008/09/04 - 6:37am
in response to:
ali raza
If it is the same cause as in the Test case setup script, then it is the slash.
You used a "backward" slash. It should be a "forward" slash "/" .
Tommy
ali raza replied on Thu, 2009/04/23 - 1:22pm
yan samantha replied on Tue, 2009/06/16 - 9:23pm
john green green replied on Fri, 2009/10/23 - 5:53am
john green green replied on Fri, 2009/10/23 - 5:53am
john green green replied on Sun, 2009/10/25 - 8:48am
Sujit Nayak replied on Sun, 2010/02/28 - 4:05pm
what a explanation, its so clear and neat.
Realy appreciated your effort.
-Sujit
marissa (not verified) replied on Mon, 2010/11/15 - 12:12pm
Sridevi Soundarraju replied on Mon, 2011/10/17 - 11:19am
Hi Meera
I have my Jenkins running on linux and SoapUI running on a different windows machine. How do I invoke the cmd.exe and soapui testsuite in that case?
Please help...
Thanks
Sri
Sridevi Soundarraju replied on Tue, 2011/10/18 - 11:08am
I have my Jenkins running on linux and SoapUI running on a different windows machine. How do I invoke the cmd.exe and soapui testsuite in that case? Please help... Looking forward for your reply...
Thanks
Sri