Chapter 4. Test Driven Process Development

One of the most important advantages of JBoss jBPM's lightweight approach to BPM and workflow management is that developers can easily leverage their usual programming skills and techniques. One of these well-known techniques is unit testing and test driven development. In this chapter we will show how developers, making use of the JBoss jBPM GPD can use a technique we have baptized Test Driven Process Development to create process definitions and test their correctness.

When creating the HellojBPM project the create process project wizard has already put in place all the library requirements we need to start writing jBPM unit tests. These are contained in the jBPM Library container and the most important of it is the .jar file containing the core jBPM classes. It must be noted that it is possible to change the location of the core jBPM installation by changing the preference settings. More on this later in the book.

With that extra knowledge on the project settings, you can create your first test. To do this, we create the com.jbay package in the test/java source folder. Then we bring up the context menu on this package and select New > Other... and then Java > JUnite > JUnite Test Case.

Create a Test

Figure 4.1. Create a Test


We call the test class HelloTest .

Create Test Dialog

Figure 4.2. Create Test Dialog


We write a simple test scenario as shown on the next figure. Let's study the code of this testcase.

A First Test Scenario

Figure 4.3. A First Test Scenario


In the first line of the method, a jBPM process archive object is created. We use a constructor accepting the filename of the archive. In our case it is the hello file we created earlier and which lives in the src/main/jpdl folder of our project. After asserting that this object is really created, we extract a process definition object from it. This object is fed to the constructor of a process instance object. We have a process instance object, but this process is not yet started, so we can safely assert that its root token still resides in the start node. After signalling the token will move to the next state and the process will be in the auction state. Finally another signal will end the process.

After writing this test we can check whether it works as expected by running it .

Running the Process Test

Figure 4.4. Running the Process Test


All went well as we have a green light:

Successful Test Run

Figure 4.5. Successful Test Run


Of course, this simple scenario was not very interesting, but the purpose of it was to show how you can reuse your development skills in a very straightforward way when doing process development. To see how more interesting processes and process test scenario's can be developed, we suggest you to read the JBoss jBPM User Guide and to study the API reference. Moreover some more examples will be given later in this book.