|
27 | 27 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
28 | 28 | import static org.mockito.ArgumentMatchers.any; |
29 | 29 | import static org.mockito.ArgumentMatchers.anyList; |
| 30 | +import static org.mockito.ArgumentMatchers.anyLong; |
30 | 31 | import static org.mockito.ArgumentMatchers.eq; |
31 | 32 | import static org.mockito.Mockito.doNothing; |
32 | 33 | import static org.mockito.Mockito.doThrow; |
|
78 | 79 | import org.apache.dolphinscheduler.plugin.task.api.model.SwitchResultVo; |
79 | 80 | import org.apache.dolphinscheduler.plugin.task.api.parameters.ConditionsParameters; |
80 | 81 | import org.apache.dolphinscheduler.plugin.task.api.parameters.SwitchParameters; |
| 82 | +import org.apache.dolphinscheduler.service.model.TaskNode; |
81 | 83 | import org.apache.dolphinscheduler.service.process.ProcessService; |
82 | 84 |
|
83 | 85 | import org.apache.commons.lang3.StringUtils; |
@@ -881,6 +883,55 @@ public void testUpdateWorkflowDefinition() { |
881 | 883 | } |
882 | 884 | } |
883 | 885 |
|
| 886 | + @Test |
| 887 | + public void testCreateWorkflowDefinitionShouldSyncVersionToResponse() { |
| 888 | + Project project = getProject(projectCode); |
| 889 | + when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
| 890 | + when(projectService.hasProjectAndWritePerm(eq(user), eq(project), any(Map.class))).thenReturn(true); |
| 891 | + when(workflowDefinitionMapper.verifyByDefineName(projectCode, name)).thenReturn(null); |
| 892 | + when(processService.transformTask(anyList(), anyList())).thenReturn(getTaskNodeList()); |
| 893 | + when(processService.saveTaskDefine(eq(user), eq(projectCode), anyList(), eq(Boolean.TRUE))).thenReturn(1); |
| 894 | + when(processService.saveWorkflowDefine(any(User.class), any(WorkflowDefinition.class), eq(Boolean.TRUE), |
| 895 | + eq(Boolean.TRUE))).thenReturn(1); |
| 896 | + when(processService.saveTaskRelation(eq(user), eq(projectCode), anyLong(), eq(1), anyList(), anyList(), |
| 897 | + eq(Boolean.TRUE))).thenReturn(Constants.EXIT_CODE_SUCCESS); |
| 898 | + |
| 899 | + Map<String, Object> result = workflowDefinitionService.createWorkflowDefinition( |
| 900 | + user, projectCode, name, description, "[]", "[]", timeout, |
| 901 | + taskRelationJson, taskDefinitionJson, null, WorkflowExecutionTypeEnum.PARALLEL); |
| 902 | + |
| 903 | + Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
| 904 | + WorkflowDefinition workflowDefinition = (WorkflowDefinition) result.get(Constants.DATA_LIST); |
| 905 | + Assertions.assertEquals(1, workflowDefinition.getVersion()); |
| 906 | + } |
| 907 | + |
| 908 | + @Test |
| 909 | + public void testUpdateWorkflowDefinitionShouldSyncVersionToResponse() { |
| 910 | + Project project = getProject(projectCode); |
| 911 | + WorkflowDefinition workflowDefinition = getWorkflowDefinition(); |
| 912 | + workflowDefinition.setName("origin-name"); |
| 913 | + when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
| 914 | + when(projectService.hasProjectAndWritePerm(eq(user), eq(project), any(Map.class))).thenReturn(true); |
| 915 | + when(processService.transformTask(anyList(), anyList())).thenReturn(getTaskNodeList()); |
| 916 | + when(workflowDefinitionMapper.queryByCode(processDefinitionCode)).thenReturn(workflowDefinition); |
| 917 | + when(workflowDefinitionMapper.verifyByDefineName(projectCode, name)).thenReturn(null); |
| 918 | + when(processService.saveTaskDefine(eq(user), eq(projectCode), anyList(), eq(Boolean.TRUE))).thenReturn(1); |
| 919 | + when(processService.saveWorkflowDefine(any(User.class), any(WorkflowDefinition.class), eq(Boolean.TRUE), |
| 920 | + eq(Boolean.TRUE))).thenReturn(2); |
| 921 | + when(workflowTaskRelationMapper.queryByWorkflowDefinitionCode(processDefinitionCode)) |
| 922 | + .thenReturn(Collections.emptyList()); |
| 923 | + when(processService.saveTaskRelation(eq(user), eq(projectCode), eq(processDefinitionCode), eq(2), anyList(), |
| 924 | + anyList(), eq(Boolean.TRUE))).thenReturn(Constants.EXIT_CODE_SUCCESS); |
| 925 | + |
| 926 | + Map<String, Object> result = workflowDefinitionService.updateWorkflowDefinition( |
| 927 | + user, projectCode, name, processDefinitionCode, description, "[]", "[]", timeout, |
| 928 | + taskRelationJson, taskDefinitionJson, WorkflowExecutionTypeEnum.PARALLEL); |
| 929 | + |
| 930 | + Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
| 931 | + WorkflowDefinition resultDefinition = (WorkflowDefinition) result.get(Constants.DATA_LIST); |
| 932 | + Assertions.assertEquals(2, resultDefinition.getVersion()); |
| 933 | + } |
| 934 | + |
884 | 935 | @Test |
885 | 936 | public void testGetNewProcessName() { |
886 | 937 | String processName1 = "test_copy_" + DateUtils.getCurrentTimeStamp(); |
@@ -976,6 +1027,18 @@ private WorkflowTaskRelation getWorkflowTaskRelation(int id, int workflowDefinit |
976 | 1027 | return workflowTaskRelation; |
977 | 1028 | } |
978 | 1029 |
|
| 1030 | + private List<TaskNode> getTaskNodeList() { |
| 1031 | + TaskNode firstTaskNode = new TaskNode(); |
| 1032 | + firstTaskNode.setCode(123456789L); |
| 1033 | + firstTaskNode.setPreTasks(JSONUtils.toJsonString(Collections.emptyList())); |
| 1034 | + |
| 1035 | + TaskNode secondTaskNode = new TaskNode(); |
| 1036 | + secondTaskNode.setCode(123451234L); |
| 1037 | + secondTaskNode.setPreTasks(JSONUtils.toJsonString(Collections.singletonList(123456789L))); |
| 1038 | + |
| 1039 | + return Arrays.asList(firstTaskNode, secondTaskNode); |
| 1040 | + } |
| 1041 | + |
979 | 1042 | /** |
980 | 1043 | * get mock schedule |
981 | 1044 | * |
|
0 commit comments