JUnit testing or process
The following example uses the or process. The flowchart is as follows:
Judge whether the node value is greater than 0, greater than 10 or greater than 20
View Test Program
public void testInclusiveSplit() throws Exception {KnowledgeBase kbase = createKnowledgeBase("BPMN2-InclusiveSplit.bpmn2");StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);Map<String, Object> params = new HashMap<String, Object>();params.put("x", 15);ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);}
If the input value is 15, the execution result should be path1 and path2, because both nodes meet the conditions.
View output results
Loading Process BPMN2-InclusiveSplit.bpmn2
Path1
Path2
Other values can be used for testing.
JUnit test or process 2
This example is the same as above, but the difference is that if no qualified node is found at the execution process node, the default process is automatically executed.
Test procedure
public void testInclusiveSplitDefault() throws Exception {KnowledgeBase kbase = createKnowledgeBase("BPMN2-InclusiveSplitDefault.bpmn2");StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);Map<String, Object> params = new HashMap<String, Object>();params.put("x", -5);ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);}
The execution result is as follows:
Loading Process BPMN2-InclusiveSplitDefault.bpmn2
Path3
JUnit test trigger event
This example is an example of how to trigger an event during the process execution.
Two events are added. The trigger conditions are yes or no. Then, they are triggered separately in the following program.
public void testEventBasedSplit() throws Exception {KnowledgeBase kbase = createKnowledgeBase("BPMN2-EventBasedSplit.bpmn2");StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);ksession.getWorkItemManager().registerWorkItemHandler("Email1",new SystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler("Email2",new SystemOutWorkItemHandler());// YesProcessInstance processInstance = ksession.startProcess("com.sample.test");assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);ksession = restoreSession(ksession, true);ksession.getWorkItemManager().registerWorkItemHandler("Email1",new SystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler("Email2",new SystemOutWorkItemHandler());ksession.signalEvent("Yes", "YesValue", processInstance.getId());assertProcessInstanceCompleted(processInstance.getId(), ksession);// NoprocessInstance = ksession.startProcess("com.sample.test");assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);ksession = restoreSession(ksession, true);ksession.getWorkItemManager().registerWorkItemHandler("Email1",new SystemOutWorkItemHandler());ksession.getWorkItemManager().registerWorkItemHandler("Email2",new SystemOutWorkItemHandler());ksession.signalEvent("No", "NoValue", processInstance.getId());assertProcessInstanceCompleted(processInstance.getId(), ksession);}
Trigger separately. The execution result is
Loading Process BPMN2-EventBasedSplit.bpmn2
Executing work item workitem 1 [name = email1, state = 0, processinstanceid = 1, parameters {}]
Executing Yes
X = yesvalue
Executing work item workitem 2 [name = email2, state = 0, processinstanceid = 1, parameters {}]
Executing work item workitem 3 [name = email1, state = 0, processinstanceid = 2, parameters {}]
Executing No
X = novalue
Executing work item workitem 4 [name = email2, state = 0, processinstanceid = 2, parameters {}]
JUnit test trigger time event
This example shows the result of a time event triggered during running.
The flowchart is as follows: