BPELUnit Tutorial - Testing a BPEL Process with invokes using a mock
Remark: This tutorial has been created as part of the lecture "Development of Service-Oriented Architectures and Applications" (Entwicklung service-orientierter Architekturen und Anwendungen (SOA)).
| Author: | Carl Volhard |
|---|---|
| Version: | 2009-03-13 |
This tutorial describes how to test a BPEL process with BPELUnit using mocks. It is assumed that you have already installed BPELUnit and that you know how to develop rudimentary BPEL processes and deploy them onto your BPEL engine.
Prerequisites
This tutorial assumes ...
- that you can understand a simple BPEL process,
- that you are familiar with SOAP messages,
- that you have installed a BPEL server,
- that you have installed BPELUnit in Eclipse,
- that you know how to write a simple test with BPELUnit (see the HelloBPEL test tutorial).
Course of Action
- Download and import the SimpleInvokeProcess process: Within this tutorial you will work with a modified version of SimpleInvokeProcess process from the second BPEL tutorial. 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. After you have downloaded the archive, import it into Eclipse: Create a new project named
SimpleInvokeand selectImportfrom the project's context menu. The process is looks like the HelloBPEL process from the first BEPLUnit tutorial. But this one does not allways returnHello Name. Instead it calls the RandomHelloService which returnshelloin a randomly choosen language.
Because we will replace the RandomHelloService with a mock, we do not have to download and deploy the service. - Deploy the Process: Before you deploy the BPEL Process you have to change the endpoint (line 76) in the RandomHelloService.wsdl into
http://localhost:7777/ws/RandomHelloPartner. Port 7777 must be free. The first part (http://localhost:7777/ws) is the base url for the BPELUnit test suite. The second part is the name of the partner in the BPELUnit test suite. Now deploy the BPEL Process. If you experience difficulties and use Apache ODE, follow the instructions in this tutorial. - Create a new Test Project: Create a new Eclipse project. The project does not need to have a special facade, therefore choose
File / New / Project / General / Projectand name the projectSimpleInvokeTest. Within this project, the BPELUnit test suite will be created. - Create a new BPELUnit Test Suite: All test cases are defined in so-called Test Suites. Create a new test suite by choosing
File / New / Other / BPELUnit / BPELUnit Test Suite.
Place the suite in the suggested location. After you have successfully created the test suite, the Test Suite Editor should show up as illustrated in the following figure.

- Copy the WSDLs: This time we have to copy two WSDL files to the project directory: the SimpleInvokeProcessArtifacts.wsdl and the RandomHelloService.wsdl.
- Fill in Process Information: General information has to be entered in the test suite. This time the Base URL is important. Among the Base URL BPELUnit will provide the mocks. Enter
http://localhost:7777/ws. As the PUT (process under test) name, giveSimpleInvoke. Because the BPEL process has been deployed manually beforehand, choose theFixed Deployeras the PUT type. - Specifying the WSDLs: Click the
Browse...button and choose the SimpleInvokeProcessArtifacts.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 have to change the WSDL! Because we want to mock the RandomHelloService we have to specify a partner process. Therefore, click the add button in the partner section. EnterRandomHelloPartneras the name and choose theRandomHelloService.wsdlfor the WSDL file. The editor should now look like this:
- Create a new Test Case:
Choose
Add...in the Test Cases and Tracks section. Name the new Test CaseDaisyand do not alter the other settings. This time the test case has two partners: The already known client and aRandomHelloPartner. The latter one will serve us as a mock. -
Define messages for the mock:
Select the partner
RandomHelloPartnerand then press theAdd...button in the activities section. Because our BPEL process calls the RandomHelloService and the Service has to respond we have to choose theReceive/Send Snychronousactivity. Choose for:
Then press next. Copy the following XML intoService: RandomHelloServiceService Port: RandomHelloService Operation: sayHello the date to be senttextarea and press finish.
<sayHelloResponse xmlns="http://randomHelloService.tutorial.soa08.se.unihannover.de"> <sayHelloReturn>Moin</sayHelloReturn> </sayHelloResponse>
On the East Frisian Islands you say "Moin" instead of Hallo (the german word for hello). The RandomHelloService mock will now responses with the XML above. - Send a Message to the Process: Select the
clientand choose theAdd...button in the activities section. Choose theSend/Receive Synchronousactivity and confirm. Choose for:
Copy the following XML into theService: SimpleInvokeService Port: SimpleInvokePort Operation: process the date to be senttextarea.<sim:SimpleInvokeProcessRequest> <sim:input>Daisy</sim:input> </sim:SimpleInvokeProcessRequest>Your dialog should look like the one in the figure now:
Choose
Nextfor defining the assertions for the response message. Assertitions consist of an XPath query and an expected value. ChooseAddand enter//sim:SimpleInvokeProcessResponseas the XPath query and'Moin Daisy'as the expected value. Please be aware of the quotes that are necessary to denote thatHello Daisyis an XPath string. Your dialog should then look like in the following figure:
Now choose
Finishto create the new activity. - Run the Test Suite: Make sure your the SimpleInvoke process is deployed and accessible and that your BPELUnit Test Suite is saved. Select the
suite.bptsfile in the Project Explorer and chooseRun as / BPELUnit Test Suitefrom the context menu of the suite.bpts file. 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:
In the bottom part of the BPELUnit view is an area for technical details. You can browse through the test run structure to inspect the SOAP messages, which were sent, and the assertions and their results.
Congratulations
Now you know how to mock a service with BPELUnit.
Eclipse Projects
Both the SimpleInvoke Process as well as the corresponding test project can be downloaded. You can import the projects directly into Eclipse.
Last Update: 2009-03-13 by Carl Volhard

