日期:2014-05-18 浏览次数:20952 次
package com.yknife; import java.util.Iterator; import java.util.List; import java.util.Set; import junit.framework.TestCase; import org.jbpm.api.*; import org.jbpm.api.history.HistoryProcessInstance; import org.jbpm.api.task.Task; public class MyTask extends TestCase { ProcessEngine processEngine; public MyTask(){ processEngine = Configuration.getProcessEngine(); } public void setUp(){ RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.createDeployment().addResourceFromClasspath("task.jpdl.xml").deploy(); } public void testTask(){ ExecutionService es = processEngine.getExecutionService(); HistoryService hs = processEngine.getHistoryService(); ProcessInstance pi = es.startProcessInstanceByKey("task"); TaskService ts = processEngine.getTaskService(); List<Task> list = ts.findPersonalTasks("yknife"); Task task = list.get(0); String taskId = task.getId(); ts.completeTask(taskId); //查看历史流程表,可以断言流程已经结束了 HistoryProcessInstance hpi = hs.createHistoryProcessInstanceQuery().processInstanceId(pi.getId()).uniqueResult(); assertTrue("ended".equals(hpi.getState())); //查看任务表任务,可以通过任务不存在了 List<Task> taskList = ts.createTaskQuery().processInstanceId(pi.getId()).list(); assertTrue(taskList.size()==0); } }
------解决方案--------------------
findActiveActivityNames()的结果依然是task1
对于这个问题,你需要建2个任务,完成一个任务后,再试试下面的代码,需要重查一下流程。
pi = es.findProcessInstanceById(pi.getId()); Set set = pi.findActiveActivityNames(); Iterator it = set.iterator(); while(it.hasNext()){ System.out.println(it.next()); }