注:本篇只做简略的入门样例,更深入的介绍,请关注之后的博客内容。
?
主要功能包括:
-发布流程定义
-查看流程定义
-删除流程定义
import java.util.List; import org.jbpm.api.Configuration; import org.jbpm.api.ProcessDefinition; import org.jbpm.api.ProcessEngine; import org.jbpm.api.RepositoryService; import junit.framework.TestCase; public class HelloTest extends TestCase { ProcessEngine processEngine; public HelloTest() { processEngine = Configuration.getProcessEngine(); } public void testDeploy(){ RepositoryService rs = processEngine.getRepositoryService(); //发布流程定义 String deploymentId=rs.createDeployment(). addResourceFromClasspath("helloworld.jpdl.xml").deploy(); //获得流程定义 List<ProcessDefinition> list=rs.createProcessDefinitionQuery().list(); System.out.println("list.size():"+list.size()); for (ProcessDefinition pd : list) { System.out.println("pd.id:"+pd.getId()); } System.out.println("deploymentId:"+deploymentId); //删除流程定义 rs.deleteDeploymentCascade(deploymentId); //删除后查询流程定义 System.out.println("after del list count:"+ rs.createProcessDefinitionQuery().list().size()); } }
?
?
完成后点击右键,选择【Run As】,进一步【Junit Test】。Junit出现绿条,并且控制台输出如下结果,则测试通过。
?
list.size():1 pd.id:helloworld-1 deploymentId:1 after del list count:0
?
?
主要功能包括:
-发起新流程
-执行等待的流程
-查看流程实例
-终止流程实例
-删除流程实例
?
import java.util.List; import org.jbpm.api.Configuration; import org.jbpm.api.ExecutionService; import org.jbpm.api.ProcessEngine; import org.jbpm.api.ProcessInstance; import junit.framework.TestCase; public class ProcessInstanceTest extends TestCase { ProcessEngine processEngine; public ProcessInstanceTest() { processEngine = Configuration.getProcessEngine(); } @Override protected void setUp() throws Exception { processEngine.getRepositoryService().createDeployment() .addResourceFromClasspath("helloworld.jpdl.xml").deploy(); } /** * 流程实例state节点向下执行 */ public void testProcessInstance(){ ExecutionService es= processEngine.getExecutionService(); //流程实例 ProcessInstance pi = es.startProcessInstanceByKey("helloworld"); //state向下执行 pi= es.signalExecutionById(pi.getId()); System.out.println("pi.isEnded"+pi.isEnded()); } /** * 终止流程实例 */ public void testProcessInstanceEnd(){ ExecutionService es= processEngine.getExecutionService(); //流程实例 ProcessInstance pi = es.startProcessInstanceByKey("helloworld"); //终止流程实例 es.endProcessInstance(pi.getId(), "结束流程"); } /** * 删除流程实例 */ public void testProcessInstanceDel(){ ExecutionService es= processEngine.getExecutionService(); //流程实例 ProcessInstance pi = es.startProcessInstanceByKey("helloworld"); //删除流程实例 es.deleteProcessInstanceCascade(pi.getId()); } /** * 流程实例列表 */ public void testProcessInstanceList(){ ExecutionService es= processEngine.getExecutionService(); //流程实例 ProcessInstance pi = null; for (int i = 0; i < 10; i++) { pi= es.startProcessInstanceByKey("helloworld"); } //查询流程实例列表 List<ProcessInstance> list= es.createProcessInstanceQuery().list(); //输出列表数到控制台 System.out.println("list.size:"+list.size()); } }
?
?
以下是测试用的工程,有需要的朋友可以下载运行看看结果!当然环境配置是必须的,关于环境配置请参考我的上一篇博客。
?