Introduction to jbpm5.1 (6)

Source: Internet
Author: User

JUnit testing mini process helloworld

This is a simple example of a script task used in the demo. It automatically outputs "Hello World" when the task node is executed"

Open a BPMN2-MinimalProcess.bpmn2 File

For example, when the process starts, the node is automatically executed, and then the output command is executed on the node.

Take a look at the test program

public void testMinimalProcess() throws Exception {KnowledgeBase kbase = createKnowledgeBase("BPMN2-MinimalProcess.bpmn2");StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);ProcessInstance processInstance = ksession.startProcess("Minimal");assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);}

After the execution is complete, assert that the execution result is completed, that is, the completion status is true.

Asserttrue (processinstance. getstate () = processinstance. state_completed );

The result is successfully output in the console.

Loading Process BPMN2-MinimalProcess.bpmn2
Hello World

Indicates that the sample is loaded successfully.

 

Helloworld for loading sub-processes in JUnit Testing

This is an example of using a sub-process in the demo. The function is the same as the above but the sub-process is used.

The process is as follows:

The Calling procedure is as follows:

public void testCompositeProcessWithDIGraphical() throws Exception {KnowledgeBase kbase = createKnowledgeBase("BPMN2-CompositeProcessWithDIGraphical.bpmn2");StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);ProcessInstance processInstance = ksession.startProcess("Composite");assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);}

After completion, the status is as above and hello World is output in the console.

 

JUnit test script task

The functions are the same as those of the previous two,

Run

public void testScriptTask() throws Exception {KnowledgeBase kbase = createKnowledgeBase("BPMN2-ScriptTask.bpmn2");StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);ProcessInstance processInstance = ksession.startProcess("ScriptTask");assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);}

Output

Loading Process BPMN2-ScriptTask.bpmn2
Hello World

 

JUnit test output list

The above functions are provided, but the list is output in the script task.

The content of the Action attribute is as follows:

Running output

Loading Process BPMN2-Import.bpmn2
[1]

 

JUnit test rule task

There are two files to load this time, one is the BPMN2-RuleTask.bpmn2, the other is the BPMN2-RuleTask.drl, the other is the process file, the other is the rule File

It loads the rule task

And set the rule

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.