feat: wire my started workflow tasks
This commit is contained in:
@@ -3,6 +3,7 @@ package com.eip4.flowservice.api;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -11,10 +12,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.flowable.engine.HistoryService;
|
||||
import org.flowable.engine.IdentityService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstanceQuery;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.engine.runtime.ProcessInstanceQuery;
|
||||
import org.flowable.engine.runtime.ChangeActivityStateBuilder;
|
||||
import org.flowable.engine.task.Comment;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.TaskQuery;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -41,15 +48,26 @@ class FlowControllerTest {
|
||||
@Mock
|
||||
RepositoryService repositoryService;
|
||||
@Mock
|
||||
IdentityService identityService;
|
||||
@Mock
|
||||
TaskQuery taskQuery;
|
||||
@Mock
|
||||
ProcessInstanceQuery processInstanceQuery;
|
||||
@Mock
|
||||
HistoricProcessInstanceQuery historicProcessInstanceQuery;
|
||||
@Mock
|
||||
ChangeActivityStateBuilder changeActivityStateBuilder;
|
||||
@Mock
|
||||
JdbcTemplate bizJdbc;
|
||||
|
||||
MockMvc mvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
FlowController controller = new FlowController(taskService, runtimeService, historyService, repositoryService, bizJdbc);
|
||||
FlowController controller = new FlowController(taskService, runtimeService, historyService, repositoryService,
|
||||
identityService, bizJdbc,
|
||||
new com.eip4.flowservice.wf.FormKeyResolver(historyService),
|
||||
new com.eip4.flowservice.wf.StartFormKeyResolver(repositoryService));
|
||||
mvc = MockMvcBuilders.standaloneSetup(controller).build();
|
||||
}
|
||||
|
||||
@@ -70,10 +88,12 @@ class FlowControllerTest {
|
||||
|
||||
mvc.perform(post("/api/flow/process/start")
|
||||
.contentType("application/json")
|
||||
.content("{\"processDefinitionKey\":\"leaveProcess\",\"businessKey\":\"biz-9\"}"))
|
||||
.content("{\"processDefinitionKey\":\"leaveProcess\",\"businessKey\":\"biz-9\",\"startUserId\":\"U1\"}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id").value("pi-1"))
|
||||
.andExpect(jsonPath("$.processDefinitionKey").value("leaveProcess"));
|
||||
verify(identityService).setAuthenticatedUserId("U1");
|
||||
verify(identityService).setAuthenticatedUserId((String) null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,6 +119,90 @@ class FlowControllerTest {
|
||||
verify(runtimeService).activateProcessInstanceById("pi-3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_移动回起始节点并挂起实例() throws Exception {
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
when(task.getId()).thenReturn("T1");
|
||||
when(task.getTaskDefinitionKey()).thenReturn("approve");
|
||||
when(taskService.createTaskQuery()).thenReturn(taskQuery);
|
||||
when(taskQuery.processInstanceId("PI-1")).thenReturn(taskQuery);
|
||||
when(taskQuery.active()).thenReturn(taskQuery);
|
||||
when(taskQuery.orderByTaskCreateTime()).thenReturn(taskQuery);
|
||||
when(taskQuery.asc()).thenReturn(taskQuery);
|
||||
when(taskQuery.list()).thenReturn(java.util.List.of(task));
|
||||
|
||||
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
|
||||
when(pi.getBusinessKey()).thenReturn("BK-1");
|
||||
when(pi.isSuspended()).thenReturn(false);
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-1")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(pi);
|
||||
|
||||
HistoricProcessInstance hpi = org.mockito.Mockito.mock(HistoricProcessInstance.class);
|
||||
when(hpi.getBusinessKey()).thenReturn("BK-1");
|
||||
when(hpi.getStartActivityId()).thenReturn("startEvent");
|
||||
when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.processInstanceId("PI-1")).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.singleResult()).thenReturn(hpi);
|
||||
when(bizJdbc.query(anyString(), any(org.springframework.jdbc.core.ResultSetExtractor.class), eq("BK-1")))
|
||||
.thenReturn(2);
|
||||
|
||||
when(runtimeService.createChangeActivityStateBuilder()).thenReturn(changeActivityStateBuilder);
|
||||
when(changeActivityStateBuilder.processInstanceId("PI-1")).thenReturn(changeActivityStateBuilder);
|
||||
when(changeActivityStateBuilder.moveActivityIdsToSingleActivityId(java.util.List.of("approve"), "startEvent"))
|
||||
.thenReturn(changeActivityStateBuilder);
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-1/withdraw")
|
||||
.contentType("application/json")
|
||||
.content("{}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.withdrawn").value(true))
|
||||
.andExpect(jsonPath("$.businessKey").value("BK-1"))
|
||||
.andExpect(jsonPath("$.targetKey").value("startEvent"));
|
||||
|
||||
verify(taskService).addComment("T1", "PI-1", "主动召回");
|
||||
verify(changeActivityStateBuilder).changeState();
|
||||
verify(runtimeService).suspendProcessInstanceById("PI-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 撤回流程_已有非白名单意见则拒绝() throws Exception {
|
||||
Task task = org.mockito.Mockito.mock(Task.class);
|
||||
when(taskService.createTaskQuery()).thenReturn(taskQuery);
|
||||
when(taskQuery.processInstanceId("PI-2")).thenReturn(taskQuery);
|
||||
when(taskQuery.active()).thenReturn(taskQuery);
|
||||
when(taskQuery.orderByTaskCreateTime()).thenReturn(taskQuery);
|
||||
when(taskQuery.asc()).thenReturn(taskQuery);
|
||||
when(taskQuery.list()).thenReturn(java.util.List.of(task));
|
||||
|
||||
ProcessInstance pi = org.mockito.Mockito.mock(ProcessInstance.class);
|
||||
when(pi.getBusinessKey()).thenReturn("BK-2");
|
||||
when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.processInstanceId("PI-2")).thenReturn(processInstanceQuery);
|
||||
when(processInstanceQuery.singleResult()).thenReturn(pi);
|
||||
HistoricProcessInstance hpi = org.mockito.Mockito.mock(HistoricProcessInstance.class);
|
||||
when(hpi.getBusinessKey()).thenReturn("BK-2");
|
||||
when(historyService.createHistoricProcessInstanceQuery()).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.processInstanceId("PI-2")).thenReturn(historicProcessInstanceQuery);
|
||||
when(historicProcessInstanceQuery.singleResult()).thenReturn(hpi);
|
||||
when(bizJdbc.query(anyString(), any(org.springframework.jdbc.core.ResultSetExtractor.class), eq("BK-2")))
|
||||
.thenReturn(2);
|
||||
|
||||
Comment comment = org.mockito.Mockito.mock(Comment.class);
|
||||
when(comment.getFullMessage()).thenReturn("同意");
|
||||
when(taskService.getProcessInstanceComments("PI-2", "comment"))
|
||||
.thenReturn(java.util.List.of(comment));
|
||||
|
||||
mvc.perform(post("/api/flow/process/PI-2/withdraw")
|
||||
.contentType("application/json")
|
||||
.content("{}"))
|
||||
.andExpect(status().isConflict())
|
||||
.andExpect(jsonPath("$.msg").value("该任务已流转,无法撤回!"));
|
||||
|
||||
verify(runtimeService, never()).createChangeActivityStateBuilder();
|
||||
verify(taskService, never()).addComment(eq("T1"), eq("PI-2"), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 委托缺少受托人返回400() throws Exception {
|
||||
mvc.perform(post("/api/flow/tasks/task-7/delegate")
|
||||
|
||||
Reference in New Issue
Block a user