package com.osvue.bpmn.activitiapp.bpmn.sequence;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
public class TestSequenceFlow {
ProcessEngine proe = ProcessEngines.getDefaultProcessEngine();
@Test
public void deployProcess() {
InputStream inputStream = this.getClass().getResourceAsStream("/diagrams/sec/sec.zip");
RepositoryService repositoryService = proe.getRepositoryService();
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
Deployment deploy = repositoryService.createDeployment().name("qingjia流程001").addZipInputStream(zipInputStream)
.deploy();
System.out.println("部署成功,部署D:" + deploy.getId());
}
@Test
public void startProcess() {
RuntimeService runtimeService = proe.getRuntimeService();
String processDefinitionKey = "live_bill";
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
System.out.println("流程启动成功:" + processInstance.getId() + " " + processInstance.getProcessDefinitionId() + " "
+ processInstance.getProcessInstanceId());
}
@Test
public void queryMyTask() {
TaskService taskService = proe.getTaskService();
String assignee = "李四";
List<org.activiti.engine.task.Task> list = taskService.createTaskQuery()
.taskAssignee(assignee)
.orderByTaskCreateTime().desc()
.list();
if (null != list && list.size() > 0) {
for (Task task : list) {
System.out.println("任务ID:" + task.getId());
System.out.println("任务办理人:" + task.getAssignee());
System.out.println("执行实例ID:" + task.getExecutionId());
System.out.println("任务名称:" + task.getName());
System.out.println("流程定义ID:" + task.getProcessDefinitionId());
System.out.println("流程实例ID:" + task.getProcessInstanceId());
System.out.println("任务创建时间:" + task.getCreateTime());
System.out.println("####################");
}
}
}
@Test
public void completeTask() {
TaskService taskService = proe.getTaskService();
String taskId = "50003";
taskService.complete(taskId);
System.out.println("任务完成");
}
@Test
public void completeTaskForVariable() {
TaskService taskService = proe.getTaskService();
String taskId = "42504";
Map<String, Object> variables = new HashMap<>();
variables.put("day", 121);
taskService.complete(taskId, variables );
System.out.println("任务完成");
}
}