Jbpm5.1 introduction (8)

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.