Information Technology Reference
In-Depth Information
Unit testing the process definition
If we look for a project called
process-examples
inside the
chapter-05
folder,
we'll see that it contains a test file called
SprintManagementV1Test.java
. It uses
a file called
sprintManagementV1.bpmn2
that contains the definition of the pro-
cess. So, basically, the test will execute the process definition to check that everything is
working as expected. If you want, you can take a look at the source code of the test. We
will now look at the important parts of the
SprintManagementV1Test
class, where
we test how the process we just defined executes in the following code:
KieSession ksession = createKieSession();
TestAsyncWorkItemHanlder h1 = new
TestAsyncWorkItemHandler();
TestAsyncWorkItemHanlder h2 = new
TestAsyncWorkItemHandler();
TestAsyncWorkItemHanlder h3 = new
TestAsyncWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler(
"Human Task", h1);
ksession.getWorkItemManager().registerWorkItemHandler(
"compiler", h2);
ksession.getWorkItemManager().registerWorkItemHandler(
"deployer", h3);
Map<String, Object> params = new HashMap<String, Object>();
params.put("project", "MyProject");
params.put("reqDescription", "My new Requirement");
ProcessInstance instance = ksession.startProcess(
"sprintManagement-V1", params);
BPM Systems' Structure
), named
ksession
, and we registered work item handlers for it.
The main process activity starts when we call the
startProcess
method, which re-
ceives the process ID we defined and a map of parameters (whose keys, you might notice,
were described in the
Variable Definitions
property of our process). This is the
most basic API we will need on the runtime to start a process instance.