jbpm 学习二 流程管理实例

package com.wujc;

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;
public class ProcessInstanceTest extends TestCase {
	
	ProcessEngine processEngine;
	
	public ProcessInstanceTest(){
		processEngine = Configuration.getProcessEngine();
		
	}
	
	/**
	 * deploy 发布流程
	 */
	protected void setUp(){
		processEngine.getRepositoryService().createDeployment().addResourceFromClasspath("helloword.jpdl.xml").deploy();
//		String deploymentId = repository.createDeployment().addResourceFromClasspath("helloword.jpdl.xml").deploy();
	}
	
	
	/**
	 * 发起新流程和执行等待流程
	 */
	public void testProcessInstance(){
		
		//控制流程实例
		ExecutionService execution = processEngine.getExecutionService();
		//启动流程实例
		ProcessInstance pi = execution.startProcessInstanceByKey("helloword");
		System.out.println(pi);
		System.out.println(pi.isEnded());
		
		//执行等待流程
		pi = execution.signalExecutionById(pi.getId());
		System.out.println(pi.isEnded());
	}
	
	/**
	 * 终止流程实例
	 */
	public void testProcessInstanceEnd(){
		//控制流程实例
		ExecutionService execution = processEngine.getExecutionService();
		//启动流程实例
		ProcessInstance pi = execution.startProcessInstanceByKey("helloword");
		execution.endProcessInstance(pi.getId(), "cancle");
		
	}
	
	/**
	 * 删除流程实例
	 */
	public void testProcessInstanceDelete(){
		//控制流程实例
		ExecutionService execution = processEngine.getExecutionService();
		//启动流程实例
		ProcessInstance pi = execution.startProcessInstanceByKey("helloword");
		execution.deleteProcessInstanceCascade(pi.getId());
	}
	
	/**
	 * 查看流程实例
	 */
	public void testProcessInstanceList(){
		//控制流程实例
		ExecutionService execution = processEngine.getExecutionService();
		//启动流程实例
		ProcessInstance pi = execution.startProcessInstanceByKey("helloword");
		//启动流程实例
		ProcessInstance piA = execution.startProcessInstanceByKey("helloword");
		List<ProcessInstance> list = execution.createProcessInstanceQuery().list();
		for(ProcessInstance  pi2 :list){
			System.out.println(pi2.getId());
		}
	}
}

你可能感兴趣的:(xml,jbpm,JUnit)