package com.task.group;
import java.util.List;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.junit.Test;
/**
* 公共任务测试
*
*
*/
public class GroupTaskTest {
static ProcessEngine pe =null;
static{
ProcessEngineConfiguration conf = ProcessEngineConfiguration.
createStandaloneProcessEngineConfiguration();
conf.setJdbcDriver("com.mysql.jdbc.Driver");
conf.setJdbcUrl("jdbc:mysql://localhost:3306/activiti02?useUnicode=true&characterEncoding=UTF-8");
conf.setJdbcUsername("root");
conf.setJdbcPassword("root");
conf.setDatabaseSchemaUpdate("true");
pe = conf.buildProcessEngine();
}
/**
* 部署流程定义
*/
@Test
public void test1() {
DeploymentBuilder deploymentBuilder = pe.getRepositoryService()
.createDeployment();
deploymentBuilder
.addClasspathResource("com/task/group/groupTask.bpmn");
deploymentBuilder .addClasspathResource("com/task/group/groupTask.png");
Deployment deployment = deploymentBuilder.deploy();
}
/**
* 启动流程实例
*/
@Test
public void test2(){
String processDefinitionId = "grouptTask:1:7404";
pe.getRuntimeService().startProcessInstanceById(processDefinitionId);
}
/**
* 办理个人任务
*/
@Test
public void test3(){
String taskId = "7504";
pe.getTaskService().complete(taskId);
}
/**
* 查询公共任务列表
*/
@Test
public void test4(){
TaskQuery query = pe.getTaskService().createTaskQuery();
String candidateUser = "王五";
//根据候选人过滤
query.taskCandidateUser(candidateUser);
List<Task> list = query.list();
for (Task task : list) {
System.out.println(task.getName());
}
}
/**
* 拾取任务(将公共任务变为个人任务)
*/
@Test
public void test5(){
String taskId = "7602";
String userId = "王五";
pe.getTaskService().claim(taskId , userId);
}
/**
* 退回任务(将个人任务变为公共任务)
*/
@Test
public void test6(){
String taskId = "1602";
pe.getTaskService().setAssignee(taskId , null);
}
}