|
|
@ -38,6 +38,7 @@ import org.apache.dolphinscheduler.common.graph.DAG; |
|
|
|
import org.apache.dolphinscheduler.common.model.TaskNodeRelation; |
|
|
|
import org.apache.dolphinscheduler.common.model.TaskNodeRelation; |
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.AlertDao; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
@ -146,6 +147,9 @@ public class ProcessInstanceServiceTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
CuringParamsService curingGlobalParamsService; |
|
|
|
CuringParamsService curingGlobalParamsService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
AlertDao alertDao; |
|
|
|
|
|
|
|
|
|
|
|
private String shellJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," |
|
|
|
private String shellJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," |
|
|
|
+ "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," |
|
|
|
+ "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," |
|
|
|
+ "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; |
|
|
|
+ "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; |
|
|
@ -522,15 +526,10 @@ public class ProcessInstanceServiceTest { |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_UPDATE)).thenReturn(result); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); |
|
|
|
try { |
|
|
|
Assertions.assertThrows(ServiceException.class, () -> { |
|
|
|
Map<String, Object> processInstanceNullRes = |
|
|
|
|
|
|
|
processInstanceService.updateProcessInstance(loginUser, projectCode, 1, |
|
|
|
processInstanceService.updateProcessInstance(loginUser, projectCode, 1, |
|
|
|
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, ""); |
|
|
|
shellJson, taskJson, "2020-02-21 00:00:00", true, "", "", 0, ""); |
|
|
|
Assertions.fail(); |
|
|
|
}); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
|
|
|
Assertions.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST.getCode(), ex.getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// process instance not finish
|
|
|
|
// process instance not finish
|
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); |
|
|
|
processInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION); |
|
|
|
processInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION); |
|
|
@ -598,13 +597,9 @@ public class ProcessInstanceServiceTest { |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_INSTANCE)).thenReturn(result); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.empty()); |
|
|
|
try { |
|
|
|
Assertions.assertThrows(ServiceException.class, () -> { |
|
|
|
Map<String, Object> processInstanceNullRes = |
|
|
|
|
|
|
|
processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); |
|
|
|
processInstanceService.queryParentInstanceBySubId(loginUser, projectCode, 1); |
|
|
|
|
|
|
|
}); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
|
|
|
Assertions.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST.getCode(), ex.getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// not sub process
|
|
|
|
// not sub process
|
|
|
|
ProcessInstance processInstance = getProcessInstance(); |
|
|
|
ProcessInstance processInstance = getProcessInstance(); |
|
|
@ -642,9 +637,9 @@ public class ProcessInstanceServiceTest { |
|
|
|
// project auth fail
|
|
|
|
// project auth fail
|
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_DELETE)).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectCode, INSTANCE_DELETE)).thenReturn(result); |
|
|
|
Map<String, Object> projectAuthFailRes = |
|
|
|
|
|
|
|
processInstanceService.deleteProcessInstanceById(loginUser, projectCode, 1); |
|
|
|
Assertions.assertThrows(ServiceException.class, |
|
|
|
Assertions.assertEquals(Status.PROJECT_NOT_FOUND, projectAuthFailRes.get(Constants.STATUS)); |
|
|
|
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); |
|
|
|
|
|
|
|
|
|
|
|
// not sub process
|
|
|
|
// not sub process
|
|
|
|
ProcessInstance processInstance = getProcessInstance(); |
|
|
|
ProcessInstance processInstance = getProcessInstance(); |
|
|
@ -652,12 +647,10 @@ public class ProcessInstanceServiceTest { |
|
|
|
processInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION); |
|
|
|
processInstance.setState(WorkflowExecutionStatus.RUNNING_EXECUTION); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); |
|
|
|
when(processService.findProcessInstanceDetailById(1)).thenReturn(Optional.ofNullable(processInstance)); |
|
|
|
try { |
|
|
|
when(processDefinitionLogMapper.queryByDefinitionCodeAndVersion(Mockito.anyLong(), Mockito.anyInt())) |
|
|
|
processInstanceService.deleteProcessInstanceById(loginUser, projectCode, 1); |
|
|
|
.thenReturn(new ProcessDefinitionLog()); |
|
|
|
Assertions.fail(); |
|
|
|
Assertions.assertThrows(ServiceException.class, |
|
|
|
} catch (ServiceException ex) { |
|
|
|
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); |
|
|
|
Assertions.assertEquals(Status.PROCESS_INSTANCE_STATE_OPERATION_ERROR.getCode(), ex.getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processInstance.setState(WorkflowExecutionStatus.SUCCESS); |
|
|
|
processInstance.setState(WorkflowExecutionStatus.SUCCESS); |
|
|
|
processInstance.setState(WorkflowExecutionStatus.SUCCESS); |
|
|
|
processInstance.setState(WorkflowExecutionStatus.SUCCESS); |
|
|
@ -670,26 +663,18 @@ public class ProcessInstanceServiceTest { |
|
|
|
processDefinition.setUserId(1); |
|
|
|
processDefinition.setUserId(1); |
|
|
|
processDefinition.setProjectCode(0L); |
|
|
|
processDefinition.setProjectCode(0L); |
|
|
|
when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
try { |
|
|
|
when(processService.findProcessInstanceDetailById(Mockito.anyInt())).thenReturn(Optional.empty()); |
|
|
|
processInstanceService.deleteProcessInstanceById(loginUser, projectCode, 1); |
|
|
|
Assertions.assertThrows(ServiceException.class, |
|
|
|
Assertions.fail(); |
|
|
|
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); |
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
|
|
|
Assertions.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST.getCode(), ex.getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processDefinition.setProjectCode(projectCode); |
|
|
|
processDefinition.setProjectCode(projectCode); |
|
|
|
|
|
|
|
when(processService.findProcessInstanceDetailById(Mockito.anyInt())).thenReturn(Optional.of(processInstance)); |
|
|
|
when(processService.deleteWorkProcessInstanceById(1)).thenReturn(1); |
|
|
|
when(processService.deleteWorkProcessInstanceById(1)).thenReturn(1); |
|
|
|
Map<String, Object> successRes = |
|
|
|
processInstanceService.deleteProcessInstanceById(loginUser, 1); |
|
|
|
processInstanceService.deleteProcessInstanceById(loginUser, projectCode, 1); |
|
|
|
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when(processService.deleteWorkProcessInstanceById(1)).thenReturn(0); |
|
|
|
when(processService.deleteWorkProcessInstanceById(1)).thenReturn(0); |
|
|
|
try { |
|
|
|
Assertions.assertThrows(ServiceException.class, |
|
|
|
processInstanceService.deleteProcessInstanceById(loginUser, projectCode, 1); |
|
|
|
() -> processInstanceService.deleteProcessInstanceById(loginUser, 1)); |
|
|
|
Assertions.fail(); |
|
|
|
|
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
|
|
|
Assertions.assertEquals(Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR.getCode(), ex.getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|