The goal of this article is to explain how to test a Web Service designed for IBM WebSphere Application Server 7.0 using IBM Rational Application Developer and IBM Rational Service Tester 8.x or IBM Rational Performance Tester with SOA extension.
This document will demonstrate:
- How to create a Web Service (invoker) with Rational Application Developer;
- How to create a stub of a Web Service with Rational Application Developer which is call in a first step;
- How to test a Web Service calling a stubbed Web Service with Rational Service Tester or Rational Performance Tester SOA extension.
Before following the instructions in this article, you must install the following products:
- Rational Application Developer 7.5.2 (minimal version)
- WebSphere Application Server 7.0
- Either Rational Service Tester 8.1.0.3 (minimal version) or Rational Performance Tester 8.1.0.3 with the SOA Extension
Creation of two web services with Rational Application Developer
To illustrate this example, we will create two web services:
- A quotation service: this is the web service that will be replaced with a stub. This service provides a quotation rate for each market.
- An intermediate invoker service: this is the web service under test, which uses the quotation service to select the best quotation among several markets.
In addition, you will need a client that can call the invoker service.
Creation of quotation web service to stub
- Open Rational Application Developer:
Start > All Programs > IBM Software Delivery Platform > IBM Rational Application Developer 7.5 > IBM Rational Application Developer - Open the J2EE Perspective:
Click Windows > Open Perspective > Other > Java EE
When prompted, specify a workspace location. - Create a new dynamic Web project and then create a new WSDL File:
File > New > Dynamic Web Project
Figure 1. New Dynamic web project
- Select WebSphere Application Server 7.
Figure 2. Selection of runtime application
- Click Finish.
- Enter the Project name and target runtime such as on next figure.
Figure 3. Project name setting
- Click Finish.
- Create a new WSDL file
File > New > Web Services > WSDL
Figure 4. Create a new WSDL file
- Click Next.
- Specify a file name, for example: Quotation1.wsdl
Figure 5. Fill the WSDL file name
- Click Next.
Figure 6. Attributes selection for the new WSDL
- Click Finish.
- Use the WSDL editor to create the following WSDL.
Replace the name of the operation NewOperation with ProvideQuotation1 and switch to View > Advanced.
Figure 7. Update name of operation
- Click on the arrow to specify the input data and define following input elements:
Figure 8. Data for input parameter ProvideQuotation1
- Click the Output value arrow to specify the output data.
Figure 9. Data for output parameter ProvideQuotation1Response
You have now defined the web service that you want to stub. We will define now the web service invoker in next section.
Creation of the web service for invocation
You can use the existing quotation web service to create another web service that will be used to invoke it.
- Create a new dynamic web service named: QuotationInvoker
Figure 10. Creation of new dynamic Web project for invoker
- Click New to create a new EAR project.
Specify the project name, for example: QuotationInvokerWebServiceEAR
Figure 11. Specification of the project name for invoker
- Click Finish.
You should see the following window:
Figure 12. Summarize of new dynamic Web project creation
- Click Finish.
- In the QuotationInvoker project, create a new WSDL file with the name:
QuotationInvoker.wsdl File > New > Web Services > WSDL
Figure 13. Creation of new WSDL file
- Click Next.
- Change the target namespace to the following value:
Figure 14. Specification of target namespace
- Click Finish.
- Specify the Web Service WSDL as in the following diagram, with an operation named: GetBestQuotation.
Figure 15. Update operation name with GetBestQuotation
- Define the Input parameter: Define a String for the endpoint. This endpoint value is used for providing the endpoint that the web service will use.
Figure 16. Definition of input parameter
- Define the output value returns two values:
place_market
quotation
Figure 17. Definition of output parameter
- Select the WSDL and generate the skeleton java code: Right-click > Web
services > Generate Java Bean Skeleton
Ensure that enabled web service runtime is: IBM WebSphere JAX-RPC Enable Publish the Web Service
Figure 18. Java skeleton generation for the invoker
- Click Next twice.
Figure 19. Final step for publication
- Click Finish.
The following code is generated:
Figure 20. Generated code for the skeleton
Creation of a client for the QuotationWebService1 web service to call
- You can use the QuotationWebService1 Web Service to generate a dedicated client for
the service.
To do this, you can generate a client from the Quotation1.wsdl file.
To generate the skeleton: right click the WSDL file and select Web Service > Generate Client
Copy-paste the code into the Web Service invoker.
Figure 21. Generation of client for Quotation1
- Ensure that Web Service runtime is set to IBM WebSphere JAX-RPC.
Figure 22. Check Web Service runtime
- Click Finish.
- This generates the Java source code:
Figure 23. Java code generated
Populating and using the web service invoker
- In the QuotationInvoker project src folder, copy-paste the
org.example.wwwpackage source code from QuotationWebService1 to obtain the following result in the invoker:
Figure 24. Copy-Paste code into the invoker
- Replace the implementation code in QuotationInvokerSOAPImpl with the following code:
Listing 1. QuotationInvoker implementation
import java.rmi.RemoteException;
import org.example.www.Quotation1_PortTypeProxy;
public class QuotationInvokerSOAPImpl implements
org.QuotationInvoker.www.QuotationInvoker_PortType{
public void getBestQuotation(java.lang.String endP,
javax.xml.rpc.holders.StringHolder place_market,
javax.xml.rpc.holders.DoubleHolder quotation)
throws java.rmi.RemoteException {
// Display on the console
System.err.println("endpoint : " + endP);
Quotation1_PortTypeProxy proxy = new Quotation1_PortTypeProxy();
proxy.setEndpoint(endP);
double quoteNY = 0.0 ;
double quoteParis = 0.0 ;
try {
System.err.println(">>>");
quoteNY = proxy.provideQuotation1("New York", "gold") ;
System.err.println("quote New York= " + quoteNY);
quoteParis = proxy.provideQuotation1("Paris", "gold") ;
System.err.println("quote Paris= " + quoteParis);
} catch (RemoteException e) {
// NOP
e.printStackTrace();
}
// Computation of best quote
if (quoteNY > quoteParis)
{
place_market.value = "New York";
quotation.value = quoteNY;
}
else
{
place_market.value = "Paris";
quotation.value = quoteParis;
}
}
}
|
Get the QuotationInvoker.wsdl file for testing
- Copy the QuotationInvoker.wsdl file from the Rational Application Developer workspace l to a temporary directory, for example: C:\wsdl
Figure 25. Copy of QuotationInvoker.wsdl file
- Copy the WSDL file of the Web Service that you want to stub into the same temporary directory for example: C:\wsdl
Figure 26. Copy wsdl file Quotation1.wsdl
The section demonstrates how to stub the call to the Web Service proxy.provideQuotation1 in Rational Service Tester because the associated java code has not been implemented yet.
Project creation on RST or RPT SOA extension
- Start Rational Service Tester or Rational Performance Tester with the SOA extension.
- Start > All Programs > IBM Software Delivery Platform > IBM Rational Service Tester > IBM Rational Service Tester – Full Eclipse
Figure 27. Start of Rational Service Tester
- Create a service test project
File > New > Service Test Project
Figure 28. Creation of new Service Test project
- Click Finish.
- At this point, Cancel the creation of a new test from recording.
Figure 29. Cancel creation of new recording
Creation of a stub for Quotation Web Service
Now it is required to write the stub of the Web ServiceQuotation1 to simulate the behaviour of the operation ProvideQuotation1
- Click on Create a Service Stub icon
Figure 30. Service Stub icon
- Then click the Import From File button.
Figure 31. Importation of file for stubbing
- Select the WSDL file from the temporary directory, for example: c:\wsdl\Quotation1.wsdl
Figure 32. Selection of the wsdl file for stubbing
- Click OK.
Figure 33. Click on Next button
- Then click Next.
Figure 34. Finalization of stub creation
- Click Finish.
- Now, we will specify the behaviour of the stub: Specify the default stub response of quote to -1.0
Figure 35. Default stub answer setting
- Define a new stub Equals Case:
- Right-click DefaultCase and select Insert > Stub Equals Case.
Figure 36. Insertion of Stub Equals Case
In the Body of the request set the following values by selecting stub case name=Equals case:
market_place = New York
metal_name = gold
Figure 37. Set input parameters of the stub
In the response, select the ProvideQuotation1 parameter of the equal case and set it to 100.0
Figure 38. Set output parameters of the stub
- Create another equal case with the following values:
market_place=Paris
metal_name=gold
For this input, set the response to 105.0
You should have the stub behaviour set as follows:
Figure 39. Other Equals case setting
- Save the stub.
Starting the local stub server
- Click on Deploy button in the stub editor.
Figure 40. Deployment of the stub
- This creates a stub server on the local machine. Start the stub on the local machine by clicking the green arrow button
Figure 41. Run button of Stub Monitor view
- In the stub monitor view, copy the URL of the WSDL of the Quotation1_Stub1 Web Service. You can import this WSDL into the Generic Service Client to test the stub.
Figure 42. Get WSDL URL published for the stub
Testing the locally deployed stub with the Generic Service Client
- Click the Generic Service Client (GSC) icon
Figure 43. Generic Service Client icon
- Click on Add WSDL file
Select Import from URL.
Figure 44. Importation of WSDL with stub URL
- Paste the URL of the WSDL file copied from the stub monitor view.
Figure 45. Paste publication URL of the stub
- Click OK.
- Test the default case
Keep the default value for market_place and metal_name and click the Invoke button.
Figure 46. Invocation on the stub
- Check that the response is –1.0
Figure 47. Check quote response
-
Test the values New York gold
Click the Edit Data button
Set market_place to New York
Set metal_name to gold
Click Invoke
Check that the response is 100.0 -
Test the values: Paris, gold
Click the Edit Data button
Set market_place to Paris
Set metal_name to gold
Click Invoke
Check that the response is 105.0
Before testing the Web Service invoker deployed on the WebSphere Application Server, you must get the associated/published QuotationInvokerWebServiceEAR WSDL file.
- Open the administrative console of the WebSphere server: Start > All
Programs > IBM WebSphere > Application Server 7.0 > Profiles > AppServ01
> Administrative console
Extend Applications and Application Types nodes
Select WebSphere enterprise applications
Click on QuotationInvokerWebServiceEAR
Figure 48. Selection of published application QuotationInvoker
- Publish the WSDL file and copy it into the temporary folder, for example: c:\wsdl
Figure 49. Publish the WSDL file
- In Rational Service Tester or Rational Performance Tester, click the New test from recording button.
Figure 50. Creation of a new recording
- Select the Web Service recording using Generic Service Client.
Figure 51. Selection of recording using GSC
- Click Next.
- Select TestQuotation and keep the default test file name.
Figure 52. Project Selection
- Click Next.
- Select Accept and click Finish.
Figure 53. Accept privacy warning
- In the Generic Service Client, click the Add WSDL button.
- Select Import from file and select the WSDL file that you exported from WebSphere:
c:\wsdl\QuotationInvoker.wsdl
Figure 54. Selection of WSDL QuotationInvoker
- Click OK.
- Specify the end point of the deployed stub. Copy it from the stub monitor view.
Figure 55. Copy publication URL of the stub
- Paste into the endPparameter in the Generic Service Client.
Figure 56. endP setting with stub URL
- Click Invoke.
- You receive the response with the best quotation.
Figure 57. Response from QuotationInvoker
Paris has the best quotation value.
- You can change the behaviour of the stub by updating the value return for Paris
from 105.0 to 95.0
To do this, open the stub behaviour and simply change the return value for Paris to 95.0 and save the stub. The stub is automatically redeployed with new behaviour.
In the Generic Service Client click Invoke again.
Now, the best quotation is for the New York market place.
Figure 58. New Response from QuotationInvoker
- Now, in the Call History list, delete the first call corresponding to the Paris best quotation response.
Figure 59. Delete first call
- Click the Stop recording button
Figure 60. Stop test suite recording
- Answer Yes to open the generated test suite
- Select the response for GetBestQuotation and add an equal verification point.
Figure 61. Add verification point in test suite
Executing the generated test suite
- Click the Run button of the test suite or right click on the test suite and request a run. The test is executed
Figure 62. Execution of the test suite
Generating a functional test report
- You can request the generation of a functional test report of the previous execution. Right click the result and select Generate Functional Report.
Figure 63. Requesting functional report generation
Figure 64. Selection of location for generation
- Click Next.
- Select, for example, Service Test – Full (XSL)
Figure 65. Selection of report design
- Click Finish.
The functional report is generated:
Figure 66. Result of functional report execution
This report also includes test log data:
Figure 67. Test Log data in functional report
Learn
- Explore the
Rational Performance Tester page on IBM developerWorks, for links to technical information for software developers and testers and to related IBM software.
- Explore the
Rational Service Tester for SOA Quality on IBM developerWorks, for links to technical information for software developers and testers and to related IBM software.
- Rational Service Tester:
http://www-01.ibm.com/software/awdtools/tester/service/.
- Learn about other applications in the
IBM Rational Software Delivery Platform, including collaboration tools for parallel development and geographically dispersed teams, plus specialized software for architecture management, asset management, change and release management, integrated requirements management, process and portfolio management, and quality management.
- Visit the
Rational software area on developerWorks, for technical resources and best practices for Rational Software Delivery Platform products.
- Learn about other applications in the
IBM Rational Software Delivery Platform, including collaboration tools for parallel development and geographically dispersed teams, plus specialized software for architecture management, asset management, change and release management, integrated requirements management, process and portfolio management, and quality management.
- Learn more on the
Rational Performance Tester product page.
- In the
SOA and web services area
on developerWorks, get the resources you need to advance your skills.
- Browse the
technology
bookstore for books on these and other technical topics.
Get products and technologies
- Download
IBM product evaluation versions
or
explore
the online trials in the IBM SOA Sandbox and get your hands on
application development tools and middleware products from
DB2®, Lotus®, Rational®, Tivoli®, and
WebSphere®.
Discuss
- Check out
developerWorks
blogs and get involved in the
developerWorks community.




