feat: wire process monitor actions

This commit is contained in:
2026-06-18 09:02:54 +08:00
parent 7192c2aaa6
commit a019af8e3a
8 changed files with 267 additions and 0 deletions

View File

@@ -156,6 +156,49 @@ class FlowControllerTest {
verify(historyService, never()).deleteHistoricProcessInstance(anyString());
}
@Test
void 结束运行中流程实例_记录评论并删除实例() throws Exception {
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
when(pi.getBusinessKey()).thenReturn("BK-END");
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
when(processInstanceQuery.processInstanceId("PI-END")).thenReturn(processInstanceQuery);
when(processInstanceQuery.singleResult()).thenReturn(pi);
Task task = org.mockito.Mockito.mock(Task.class);
when(task.getId()).thenReturn("T-END");
when(taskService.createTaskQuery()).thenReturn(taskQuery);
when(taskQuery.processInstanceId("PI-END")).thenReturn(taskQuery);
when(taskQuery.active()).thenReturn(taskQuery);
when(taskQuery.list()).thenReturn(java.util.List.of(task));
mvc.perform(post("/api/flow/process/PI-END/terminate")
.contentType("application/json")
.content("{}"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.terminated").value(true))
.andExpect(jsonPath("$.businessKey").value("BK-END"))
.andExpect(jsonPath("$.activeTaskCount").value(1));
verify(taskService).addComment("T-END", "PI-END", "流程有误作废处理");
verify(runtimeService).setVariable("PI-END", "approveResult", "invalid");
verify(runtimeService).deleteProcessInstance("PI-END", "流程有误作废处理");
}
@Test
void 结束已结束流程实例_返回409且不删除() throws Exception {
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
when(processInstanceQuery.processInstanceId("PI-DONE")).thenReturn(processInstanceQuery);
when(processInstanceQuery.singleResult()).thenReturn(null);
mvc.perform(post("/api/flow/process/PI-DONE/terminate")
.contentType("application/json")
.content("{}"))
.andExpect(status().isConflict())
.andExpect(jsonPath("$.msg").value("该流程已结束"));
verify(runtimeService, never()).deleteProcessInstance(anyString(), anyString());
}
@Test
void 撤回流程_移动回起始节点并挂起实例() throws Exception {
Task task = org.mockito.Mockito.mock(Task.class);