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 ...

Course of Action

  1. 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 SimpleInvoke and select Import from the project's context menu. The process is looks like the HelloBPEL process from the first BEPLUnit tutorial. But this one does not allways return Hello Name. Instead it calls the RandomHelloService which returns hello in a randomly choosen language.

    Screenshot: The SimpleInvoke Process
    Because we will replace the RandomHelloService with a mock, we do not have to download and deploy the service.

  2. 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.
  3. 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 / Project and name the project SimpleInvokeTest. Within this project, the BPELUnit test suite will be created.
  4. 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.

    Screenshot: Create a new 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.

    Screenshot: Empty Test Suite Editor

  5. Copy the WSDLs: This time we have to copy two WSDL files to the project directory: the SimpleInvokeProcessArtifacts.wsdl and the RandomHelloService.wsdl.
  6. 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, give SimpleInvoke. Because the BPEL process has been deployed manually beforehand, choose the Fixed Deployer as the PUT type.
  7. 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. Enter RandomHelloPartner as the name and choose the RandomHelloService.wsdl for the WSDL file. The editor should now look like this:

    Screenshot: Entering General Information

  8. Create a new Test Case: Choose Add... in the Test Cases and Tracks section. Name the new Test Case Daisy and do not alter the other settings. This time the test case has two partners: The already known client and a RandomHelloPartner. The latter one will serve us as a mock.
  9. Define messages for the mock: Select the partner RandomHelloPartner and then press the Add... button in the activities section. Because our BPEL process calls the RandomHelloService and the Service has to respond we have to choose the Receive/Send Snychronous activity. Choose for:
    Service: RandomHelloServiceService
    Port: RandomHelloService
    Operation: sayHello
    Then press next. Copy the following XML into the date to be sent textarea 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.
  10. Send a Message to the Process: Select the client and choose the Add... button in the activities section. Choose the Send/Receive Synchronous activity and confirm. Choose for:
    Service: SimpleInvokeService
    Port: SimpleInvokePort
    Operation: process
    Copy the following XML into the the date to be sent textarea.
    <sim:SimpleInvokeProcessRequest>
        <sim:input>Daisy</sim:input>
    </sim:SimpleInvokeProcessRequest>
    			
    Your dialog should look like the one in the figure now:

    Screenshot: Define send operation

    Choose Next for defining the assertions for the response message. Assertitions consist of an XPath query and an expected value. Choose Add and enter //sim:SimpleInvokeProcessResponse as the XPath query and 'Moin Daisy' as the expected value. Please be aware of the quotes that are necessary to denote that Hello Daisy is an XPath string. Your dialog should then look like in the following figure:

    Screenshot: Define assertion on the incoming message

    Now choose Finish to create the new activity.
  11. 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.bpts file in the Project Explorer and choose Run as / BPELUnit Test Suite from 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:

    Screenshot: BPELUnit view

    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