本篇主要对流程进行启动,终止和删除操作。- package org.wxp;
- import java.util.List;
- import junit.framework.TestCase;
- import org.jbpm.api.Configuration;
- import org.jbpm.api.ExecutionService;
- import org.jbpm.api.ProcessEngine;
- import org.jbpm.api.ProcessInstance;
- /**
- * 管理流程实例
- * 1.创建流程
- * 2.判断流程是否终结
- * 3.手动停止一个流程
- * 4.删除流程
- * @author Champion.Wong
- *
- */
- public class ProcessInstanceTest extends TestCase {
- ProcessEngine processEngine; // 创建流程引擎
- public ProcessInstanceTest() {
- processEngine = Configuration.getProcessEngine(); // 实例化流程引擎
- }
- protected void setUp() {
- processEngine.getRepositoryService().createDeployment()
- .addResourceFromClasspath("helloworld.jpdl.xml").deploy(); // 启动流程引擎
- }
- public void testProcessInstance() {
- ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行
- ProcessInstance pi = executionService
- .startProcessInstanceByKey("helloworld"); // 启动一个流程定义
- System.out.println("刚启动的流程为:" + pi);
- System.out.println("流程是否终结:" + pi.isEnded()); // 流程为等待状态,所以没有终结
- pi = executionService.signalExecutionById(pi.getId()); // 手动执行流程
- System.out.println("流程是否终结:" + pi.isEnded());
- }
- public void testProcessInstanceEnd() {
- ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行
- ProcessInstance pi = executionService
- .startProcessInstanceByKey("helloworld"); // 启动一个流程定义
- executionService.endProcessInstance(pi.getId(), "cancel"); // 强制终止一个流程
- }
- public void testProcessInstanceDelete() {
- ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行
- ProcessInstance pi = executionService
- .startProcessInstanceByKey("helloworld"); // 启动一个流程定义
- executionService.deleteProcessInstanceCascade(pi.getId()); // 删除一个流程
- }
- public void testProcessInstanceList() {
- ExecutionService executionService = processEngine.getExecutionService(); // 获取一个流程执行
- ProcessInstance pi = executionService
- .startProcessInstanceByKey("helloworld"); // 启动一个流程定义
- ProcessInstance pi2 = executionService
- .startProcessInstanceByKey("helloworld"); // 启动一个流程定义
- List<ProcessInstance> list = executionService
- .createProcessInstanceQuery().list(); // 获取引擎中所有流程定义的信息
- for (ProcessInstance processInstance : list) {
- System.out.println(processInstance.getId());
- }
- }
- }