flowable 使用流程服务
引用这篇文章进行了学习。兼容了其中部分功能
https://blog.csdn.net/qq_29884151/article/details/147253839
1. 这里使用的是ruoyi-flowable项目进行的测试
https://gitee.com/shenzhanwang/RuoYi-flowable
1)要注意些地方
- 按照项目提供安装mysql的schema, ry-flowable,但程序中配置的缺失ry_flowable
-
redis密码。这里没有设置,就去除了
-
增加了junit test依赖
<!-- JUnit 5 dependency -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope>
</dependency>
2. 通过junit测试的方法测试
但有些麻烦,需要每次测试都要重新启动项目
- 启动项目。可视化配置流程
- 关闭项目。启动单元测试,测试流程
- 输出打印
package com.ruoyi.web.service;import org.flowable.engine.HistoryService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.util.HashMap;
import java.util.List;
import java.util.Map;@SpringBootTest
class MyJavaDelegateTest {@Autowiredprivate RuntimeService runtimeService;@Autowiredprivate HistoryService historyService;@Testvoid TestServer() {// 发起服务流程Map<String, Object> map = new HashMap<>();ProcessInstance studentLeave = runtimeService.startProcessInstanceByKey("help_audit", map);// 查看历史List<HistoricActivityInstance> activities = historyService.createHistoricActivityInstanceQuery().processInstanceId(studentLeave.getId()).finished().orderByHistoricActivityInstanceEndTime().asc().list();for (HistoricActivityInstance activity : activities) {System.out.println(activity.getActivityName());}}
}