| Author: | Buddhika Chamith |
|---|---|
| Version: | 2009-07-22 |
This tutorial describes how the BPELUnit framework can be used to unit test a BPEL process and to calculate the achieved test coverage. Test coverage in this context is the number of activities that are executed along the execution path of a BPEL process for a particular test case. These statistics will be displayed at the end of the test run as a percentage of the total activities of the BPEL process. The ODE BPEL process engine will be used to deploy the process.
To proceed with the tutorial it is assumed that that you know how to develop and understand a rudimentary BPEL process.
This tutorial assumes ...
If From and To language codes are the same, the process just echoes back the unmodified text to the client. If the language codes are different it invokes an external service named TranslatorService and channels the response of this service to the client.
In the first part of this two part tutorial a unit test will be created to test the branch which will just echo the output to the client. Therefore, no calls to the TranslatorService will be made in this test run.
To go ahead, download this process here. The version you can download is bundled with an Apache ODE deployment descriptor. However, the BPEL constructs used are so simple that you should be able to easily deploy this process on any server. If you are not familiar enough with BPEL, you can revisit the BPEL tutorials. Unzip the archive after downloading and make a note of this location.
Because we will replace the TranslatorService with a mock, we do not have to download and deploy the service. (We still require the TranslatorService up and running for the sake of completeness of the testing environment though no calls are going to be made to it in this test.)
File / New / Other / BPELUnit / BPELUnit Test Suite. Save the suite file within the project. After you have successfully created the test suite, the Test Suite Editor should show up as illustrated in the following figure.

Browse... button and choose the TranslatorProcess/ TranslatorProcessArtifacts.wsdl. Please be aware that the WSDL file has to contain the correct endpoint address for your process. If you have deployed the BPEL process differently (not on Apache ODE or on another host), you will have to change the WSDL! "Configure Deployment Options... ". Following dialog comes up.
Add... button to get the "Add an Option" dialog as show below.
Keys... button to get the set of deployment parameters associated with this deployment.
DeploymentArchive from the list and click OK. Key value will be automatically filled in the "Add an Option" dialog. As the Value give the location of the deployment archive. BPELUnit can work with directory deployments as well as zip archive deployments. Relative paths will be resolved with the project root as the base directory. Since we have created a directory within our project and copied all the process artifacts to it we can use this directory. So give TranslatorProcess as the input for the Value field and click OK. Resultant dialog will be as follows. 
Add... button in the partner section. Enter TranslatorPartner as the name and choose TranslatorProcess/ TranslatorService.wsdl for the WSDL file. Please note that we have given the same partner name as the partnerlink name of the service in the BPEL file. This is required since we will be using the option of automatically changing endpoint URL in the partner service's WSDL to the mock service URL. The way to set this option is described in later steps in this tutorial. Now the editor should look like this:

Add... in the Test Cases and Tracks section. Name the new Test Case Greet and do not alter the other settings. This time the test case has two partners: The already known client and a TranslatorPartner. The latter one will define the behavior of the mock.
Add... button in the activities section. Choose the Send/Receive Synchronous activity and confirm. Choose for:
| Service: | Translator |
| Port: | TranslatorPort |
| Operation: | process |
"Data to be sent" text area.
<TranslatorProcessRequestYour dialog should look like the one in the figure now:
xmlns="http://www.se.uni-hannover.de/soa08/tutorial/TranslatorProcess"> <From>EN</From> <To>EN</To> <Text>Greetings</Text> </TranslatorProcessRequest>

Next for defining the assertions for the response message. Assertions consist of an XPath query and an expected value. Choose Add and enter //tran:TranslatorProcessResponse/tran:Text as the XPath query and 'Greetings' as the expected value. Please be aware of the quotes that are necessary to denote that Greetings is an XPath string. Your dialog should then look like in the following figure:
Window/ Preferences/BPELUnit in Eclipse. Select the Test Coverage page under BPELUnit and check the "Coverage Measurement" check box. This will enable a check box group below. Here one can select which activities should be traced during test runs. In this case we are going to monitor whether invoke and assign activities were properly covered during the execution. So check invoke and assign check boxes as shown in the screenshot below.


"Automatically modify endpoints to simulated URLs" below. For this to work partner track names must be the same as the names of the partner links in the BPEL process as noted in step 7.
Add... button besides the table.ODEDeploymentServiceURL as the Key and the web service endpoint of your ODE Deployment Service
(e.g:http://192.134.12.1:8080/ode/processes/DeploymentService) as the value.

http://localhost:8080/ode/processes/DeploymentService as the default parameter value if no value is specified.
Run as/ BPELUnit Test Suite from its context menu. The BPELUnit view should appear, in which you can observe the progress of the test run. Like with the JUnit view, a green bar means that everything went fine and a red bar means that a test failed. If you have done everything correctly, you should see a green bar like in the picture:

Window/Show View/Other.../BPEL Category/Test Coverage. In this case it shows one assignment activity out of three was executed while the single invoke in the process (invoke to TranslatorService) was not executed in this test's execution path. This is because we have only triggered the if branch in the BPEL process. The else branch will be tested in the second part of this tutorial.

Now you know how test a service with BPELUnit and measure test coverage. The second part of this tutorial describes how to set up a test involving partner service calls.
Both the Translator Process as well as the corresponding test project can be downloaded. You can import the projects directly into Eclipse.
Last Update: 2009-07-27 by Buddhika Chamith
Webmaster
© 2004-2010 Fachgebiet Software Engineering
Impressum
|