一个流程实例
一个流程实例
package com.Demo.test;
import com.Demo.DemoApplication;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ActivitiJunitTest {
private static final Logger log = LoggerFactory.getLogger(ActivitiJunitTest.class);
@Autowired
RepositoryService repositoryService;
@Autowired
RuntimeService runtimeService;
@Autowired
TaskService taskService;
@Autowired
HistoryService historyService;
/***
* 1.流程部署
* @author lxd
* @date2023-09-06 10:00
* @param[]
* @return void
*/
@Test
public void testDeployment() {
Deployment deployment = repositoryService.createDeployment()
.name("测试流程文件部署")
.addClasspathResource("leavess.bpmn")
// .addClasspathResource("processes/leave.jpg")
.deploy();
System.out.println("部署的流程id ="+ deployment.getId());
System.out.println("部署的流程id ="+ deployment.getName());
log.info("部署的流程id = {}", deployment.getId());
log.info("部署的流程名称 = {}", deployment.getName());
}
@Test
public void start(){
Map<String,Object> map=new HashMap<>();
List<String> groupList=new ArrayList<>();
groupList.add("hr");
groupList.add("ceshi");
map.put("hr",groupList);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("v3",map);
log.info("启动流程实例成功 = {}", processInstance);
log.info("流程实例id = {}", processInstance.getId());
log.info("流程定义id = {}", processInstance.getProcessDefinitionId());
}
@Test
public void testGetTaskByAssignee() {
List<Task> tasks = taskService.createTaskQuery()
.taskCandidateGroup("hr")
.list();
for (Task task : tasks) {
System.out.println(task.getName());
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
<process id="v3" name="v2" isExecutable="true">
<startEvent id="sid-06D994D1-2C0E-417E-8351-B472490F386A"></startEvent>
<userTask id="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6" name="发起申请啊" activiti:candidateGroups="hr"></userTask>
<sequenceFlow id="sid-8B085EB8-E1B5-4CD8-BB92-5CEAB980BE16" sourceRef="sid-06D994D1-2C0E-417E-8351-B472490F386A" targetRef="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6"></sequenceFlow>
<endEvent id="sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199"></endEvent>
<sequenceFlow id="sid-3EA5C2F3-0191-4700-99A3-447398272A79" sourceRef="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6" targetRef="sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_v3">
<bpmndi:BPMNPlane bpmnElement="v3" id="BPMNPlane_v3">
<bpmndi:BPMNShape bpmnElement="sid-06D994D1-2C0E-417E-8351-B472490F386A" id="BPMNShape_sid-06D994D1-2C0E-417E-8351-B472490F386A">
<omgdc:Bounds height="30.0" width="30.0" x="95.0" y="30.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6" id="BPMNShape_sid-5CEB1E7A-0860-46A1-8D9D-B2C5E9086DB6">
<omgdc:Bounds height="80.0" width="100.0" x="60.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199" id="BPMNShape_sid-BE42DCB2-13EE-44BB-ADC0-1B2994BA2199">
<omgdc:Bounds height="28.0" width="28.0" x="96.0" y="420.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-3EA5C2F3-0191-4700-99A3-447398272A79" id="BPMNEdge_sid-3EA5C2F3-0191-4700-99A3-447398272A79">
<omgdi:waypoint x="110.0" y="200.0"></omgdi:waypoint>
<omgdi:waypoint x="110.0" y="420.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-8B085EB8-E1B5-4CD8-BB92-5CEAB980BE16" id="BPMNEdge_sid-8B085EB8-E1B5-4CD8-BB92-5CEAB980BE16">
<omgdi:waypoint x="110.0" y="60.0"></omgdi:waypoint>
<omgdi:waypoint x="110.0" y="120.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>