|
|
@ -30,6 +30,7 @@ import org.apache.dolphinscheduler.common.enums.WarningType; |
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.utils.StringUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.DataSource; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.DataSource; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessData; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessData; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
@ -38,7 +39,6 @@ import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Schedule; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Schedule; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
@ -68,14 +68,14 @@ import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.Silent.class) |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
public class ProcessDefinitionServiceTest { |
|
|
|
public class ProcessDefinitionServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
@InjectMocks |
|
|
|
ProcessDefinitionServiceImpl processDefinitionService; |
|
|
|
private ProcessDefinitionServiceImpl processDefinitionService; |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private DataSourceMapper dataSourceMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ProcessDefinitionMapper processDefineMapper; |
|
|
|
private ProcessDefinitionMapper processDefineMapper; |
|
|
@ -98,28 +98,149 @@ public class ProcessDefinitionServiceTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private TaskInstanceMapper taskInstanceMapper; |
|
|
|
private TaskInstanceMapper taskInstanceMapper; |
|
|
|
|
|
|
|
|
|
|
|
private String sqlDependentJson = "{\"globalParams\":[]," + |
|
|
|
private static final String SHELL_JSON = "{\n" |
|
|
|
"\"tasks\":[{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":\"sql\"," + |
|
|
|
+ " \"globalParams\": [\n" |
|
|
|
"\"params\":{\"type\":\"MYSQL\",\"datasource\":1,\"sql\":\"select * from test\"," + |
|
|
|
+ " \n" |
|
|
|
"\"udfs\":\"\",\"sqlType\":\"1\",\"title\":\"\",\"receivers\":\"\",\"receiversCc\":\"\",\"showType\":\"TABLE\"" + |
|
|
|
+ " ],\n" |
|
|
|
",\"localParams\":[],\"connParams\":\"\"," + |
|
|
|
+ " \"tasks\": [\n" |
|
|
|
"\"preStatements\":[],\"postStatements\":[]}," + |
|
|
|
+ " {\n" |
|
|
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + |
|
|
|
+ " \"type\": \"SHELL\",\n" |
|
|
|
"\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\"," + |
|
|
|
+ " \"id\": \"tasks-9527\",\n" |
|
|
|
"\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + |
|
|
|
+ " \"name\": \"shell-1\",\n" |
|
|
|
"\"preTasks\":[\"dependent\"]},{\"type\":\"DEPENDENT\",\"id\":\"tasks-33787\"," + |
|
|
|
+ " \"params\": {\n" |
|
|
|
"\"name\":\"dependent\",\"params\":{},\"description\":\"\",\"runFlag\":\"NORMAL\"," + |
|
|
|
+ " \"resourceList\": [\n" |
|
|
|
"\"dependence\":{\"relation\":\"AND\",\"dependTaskList\":[{\"relation\":\"AND\"," + |
|
|
|
+ " \n" |
|
|
|
"\"dependItemList\":[{\"projectId\":2,\"definitionId\":46,\"depTasks\":\"ALL\"," + |
|
|
|
+ " ],\n" |
|
|
|
"\"cycle\":\"day\",\"dateValue\":\"today\"}]}]},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
+ " \"localParams\": [\n" |
|
|
|
"\"timeout\":{\"strategy\":\"\",\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + |
|
|
|
+ " \n" |
|
|
|
"\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" |
|
|
|
private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\"," + |
|
|
|
+ " },\n" |
|
|
|
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," + |
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
"\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + |
|
|
|
+ " \"dependence\": {\n" |
|
|
|
"\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"interval\": 1,\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tenantId\": 1,\n" |
|
|
|
|
|
|
|
+ " \"timeout\": 0\n" |
|
|
|
|
|
|
|
+ "}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String CYCLE_SHELL_JSON = "{\n" |
|
|
|
|
|
|
|
+ " \"globalParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tasks\": [\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"SHELL\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-9527\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"shell-1\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \"resourceList\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"localParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"interval\": 1,\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \"tasks-9529\"\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"SHELL\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-9528\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"shell-1\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \"resourceList\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"localParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"interval\": 1,\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \"tasks-9527\"\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"SHELL\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-9529\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"shell-1\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \"resourceList\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"localParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"rawScript\": \"#!/bin/bash\\necho \\\"shell-1\\\"\"\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"interval\": 1,\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \"tasks-9528\"\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tenantId\": 1,\n" |
|
|
|
|
|
|
|
+ " \"timeout\": 0\n" |
|
|
|
|
|
|
|
+ "}"; |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQueryProcessDefinitionList() { |
|
|
|
public void testQueryProcessDefinitionList() { |
|
|
@ -150,6 +271,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void testQueryProcessDefinitionListPaging() { |
|
|
|
public void testQueryProcessDefinitionListPaging() { |
|
|
|
String projectName = "project_test1"; |
|
|
|
String projectName = "project_test1"; |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
@ -168,6 +290,22 @@ public class ProcessDefinitionServiceTest { |
|
|
|
Map<String, Object> map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, "project_test1", "", 1, 5, 0); |
|
|
|
Map<String, Object> map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, "project_test1", "", 1, 5, 0); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
|
|
|
loginUser.setId(1); |
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
|
|
|
|
Page<ProcessDefinition> page = new Page<>(1, 10); |
|
|
|
|
|
|
|
page.setTotal(30); |
|
|
|
|
|
|
|
Mockito.when(processDefineMapper.queryDefineListPaging( |
|
|
|
|
|
|
|
Mockito.any(IPage.class) |
|
|
|
|
|
|
|
, Mockito.eq("") |
|
|
|
|
|
|
|
, Mockito.eq(loginUser.getId()) |
|
|
|
|
|
|
|
, Mockito.eq(project.getId()) |
|
|
|
|
|
|
|
, Mockito.anyBoolean())).thenReturn(page); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map1 = processDefinitionService.queryProcessDefinitionListPaging( |
|
|
|
|
|
|
|
loginUser, projectName, "", 1, 10, loginUser.getId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, map1.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -206,55 +344,72 @@ public class ProcessDefinitionServiceTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCopyProcessDefinition() throws Exception { |
|
|
|
public void testBatchCopyProcessDefinition() { |
|
|
|
String projectName = "project_test1"; |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryDetailById(1)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String projectName = "project_test1"; |
|
|
|
Project project = getProject(projectName); |
|
|
|
Project project = getProject(projectName); |
|
|
|
|
|
|
|
|
|
|
|
User loginUser = new User(); |
|
|
|
User loginUser = new User(); |
|
|
|
loginUser.setId(-1); |
|
|
|
loginUser.setId(-1); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// copy project definition ids empty test
|
|
|
|
|
|
|
|
Map<String, Object> map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectName, StringUtils.EMPTY, 0); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINITION_IDS_IS_EMPTY, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
//project check auth success, instance not exist
|
|
|
|
|
|
|
|
|
|
|
|
// project check auth fail
|
|
|
|
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
|
|
|
|
Map<String, Object> map1 = processDefinitionService.batchCopyProcessDefinition( |
|
|
|
|
|
|
|
loginUser, projectName, String.valueOf(project.getId()), 0); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map1.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// project check auth success, target project is null
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryDetailById(0)).thenReturn(null); |
|
|
|
|
|
|
|
Map<String, Object> map2 = processDefinitionService.batchCopyProcessDefinition( |
|
|
|
|
|
|
|
loginUser, projectName, String.valueOf(project.getId()), 0); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map2.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// project check auth success, target project name not equal project name, check auth target project fail
|
|
|
|
|
|
|
|
Project project1 = getProject(projectName); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project1); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
|
|
|
String projectName2 = "project_test2"; |
|
|
|
|
|
|
|
Project project2 = getProject(projectName2); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(project2); |
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectName2)).thenReturn(result); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryDetailById(1)).thenReturn(project2); |
|
|
|
|
|
|
|
// instance exit
|
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); |
|
|
|
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); |
|
|
|
definition.setProcessDefinitionJson("{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); |
|
|
|
definition.setProcessDefinitionJson("{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); |
|
|
|
definition.setConnects("[]"); |
|
|
|
definition.setConnects("[]"); |
|
|
|
//instance exit
|
|
|
|
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> createProcessResult = new HashMap<>(); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(processDefinitionService.createProcessDefinition( |
|
|
|
|
|
|
|
loginUser, |
|
|
|
|
|
|
|
definition.getProjectName(), |
|
|
|
|
|
|
|
definition.getName(), |
|
|
|
|
|
|
|
definition.getProcessDefinitionJson(), |
|
|
|
|
|
|
|
definition.getDescription(), |
|
|
|
|
|
|
|
definition.getLocations(), |
|
|
|
|
|
|
|
definition.getConnects())).thenReturn(createProcessResult); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> successRes = processDefinitionService.batchCopyProcessDefinition(loginUser, "project_test1", |
|
|
|
Map<String, Object> map3 = processDefinitionService.batchCopyProcessDefinition( |
|
|
|
"46", 1); |
|
|
|
loginUser, projectName, "46", 1); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, map3.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBatchMoveProcessDefinition() throws Exception { |
|
|
|
public void testBatchMoveProcessDefinition() { |
|
|
|
String projectName = "project_test1"; |
|
|
|
String projectName = "project_test1"; |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
Project project1 = getProject(projectName); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(project1); |
|
|
|
|
|
|
|
|
|
|
|
String projectName2 = "project_test2"; |
|
|
|
String projectName2 = "project_test2"; |
|
|
|
Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(getProject(projectName2)); |
|
|
|
Project project2 = getProject(projectName2); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName2)).thenReturn(project2); |
|
|
|
|
|
|
|
|
|
|
|
int targetProjectId = 2; |
|
|
|
int targetProjectId = 2; |
|
|
|
Mockito.when(projectMapper.queryDetailById(targetProjectId)).thenReturn(getProjectById(targetProjectId)); |
|
|
|
Mockito.when(projectMapper.queryDetailById(targetProjectId)).thenReturn(getProjectById(targetProjectId)); |
|
|
@ -273,27 +428,27 @@ public class ProcessDefinitionServiceTest { |
|
|
|
putMsg(result2, Status.SUCCESS, targetProject.getName()); |
|
|
|
putMsg(result2, Status.SUCCESS, targetProject.getName()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, targetProject, targetProject.getName())).thenReturn(result2); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectName2)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); |
|
|
|
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); |
|
|
|
definition.setProcessDefinitionJson("{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); |
|
|
|
definition.setProcessDefinitionJson("{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); |
|
|
|
definition.setConnects("[]"); |
|
|
|
definition.setConnects("[]"); |
|
|
|
//instance exit
|
|
|
|
|
|
|
|
|
|
|
|
// check target project result == null
|
|
|
|
Mockito.when(processDefineMapper.updateById(definition)).thenReturn(46); |
|
|
|
Mockito.when(processDefineMapper.updateById(definition)).thenReturn(46); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); |
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> successRes = processDefinitionService.batchMoveProcessDefinition( |
|
|
|
Map<String, Object> successRes = processDefinitionService.batchMoveProcessDefinition(loginUser, "project_test1", |
|
|
|
loginUser, "project_test1", "46", 2); |
|
|
|
"46", 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void deleteProcessDefinitionByIdTest() throws Exception { |
|
|
|
public void deleteProcessDefinitionByIdTest() { |
|
|
|
String projectName = "project_test1"; |
|
|
|
String projectName = "project_test1"; |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
|
|
@ -379,7 +534,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
Project project = getProject(projectName); |
|
|
|
Project project = getProject(projectName); |
|
|
|
User loginUser = new User(); |
|
|
|
User loginUser = new User(); |
|
|
|
loginUser.setId(-1); |
|
|
|
loginUser.setId(1); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
//project check auth fail
|
|
|
@ -390,17 +545,25 @@ public class ProcessDefinitionServiceTest { |
|
|
|
6, ReleaseState.OFFLINE.getCode()); |
|
|
|
6, ReleaseState.OFFLINE.getCode()); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//project check auth success, processs definition online
|
|
|
|
// project check auth success, processs definition online
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition()); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition()); |
|
|
|
Mockito.when(processDefineMapper.updateById(getProcessDefinition())).thenReturn(1); |
|
|
|
Map<String, Object> onlineRes = processDefinitionService.releaseProcessDefinition( |
|
|
|
Map<String, Object> onlineRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", |
|
|
|
loginUser, "project_test1", 46, ReleaseState.ONLINE.getCode()); |
|
|
|
46, ReleaseState.ONLINE.getCode()); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//release error code
|
|
|
|
// project check auth success, processs definition online
|
|
|
|
Map<String, Object> failRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", |
|
|
|
ProcessDefinition processDefinition1 = getProcessDefinition(); |
|
|
|
46, 2); |
|
|
|
processDefinition1.setResourceIds("1,2"); |
|
|
|
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition1); |
|
|
|
|
|
|
|
Mockito.when(processService.getUserById(1)).thenReturn(loginUser); |
|
|
|
|
|
|
|
Map<String, Object> onlineWithResourceRes = processDefinitionService.releaseProcessDefinition( |
|
|
|
|
|
|
|
loginUser, "project_test1", 46, ReleaseState.ONLINE.getCode()); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, onlineWithResourceRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// release error code
|
|
|
|
|
|
|
|
Map<String, Object> failRes = processDefinitionService.releaseProcessDefinition( |
|
|
|
|
|
|
|
loginUser, "project_test1", 46, 2); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//FIXME has function exit code 1 when exception
|
|
|
|
//FIXME has function exit code 1 when exception
|
|
|
@ -453,18 +616,24 @@ public class ProcessDefinitionServiceTest { |
|
|
|
Map<String, Object> dataNotValidRes = processDefinitionService.checkProcessNodeList(null, ""); |
|
|
|
Map<String, Object> dataNotValidRes = processDefinitionService.checkProcessNodeList(null, ""); |
|
|
|
Assert.assertEquals(Status.DATA_IS_NOT_VALID, dataNotValidRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.DATA_IS_NOT_VALID, dataNotValidRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//task not empty
|
|
|
|
// task not empty
|
|
|
|
String processDefinitionJson = shellJson; |
|
|
|
String processDefinitionJson = SHELL_JSON; |
|
|
|
ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); |
|
|
|
ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class); |
|
|
|
assert processData != null; |
|
|
|
Assert.assertNotNull(processData); |
|
|
|
Map<String, Object> taskEmptyRes = processDefinitionService.checkProcessNodeList(processData, processDefinitionJson); |
|
|
|
Map<String, Object> taskEmptyRes = processDefinitionService.checkProcessNodeList(processData, processDefinitionJson); |
|
|
|
Assert.assertEquals(Status.SUCCESS, taskEmptyRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, taskEmptyRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//task empty
|
|
|
|
// task empty
|
|
|
|
processData.setTasks(null); |
|
|
|
processData.setTasks(null); |
|
|
|
Map<String, Object> taskNotEmptyRes = processDefinitionService.checkProcessNodeList(processData, processDefinitionJson); |
|
|
|
Map<String, Object> taskNotEmptyRes = processDefinitionService.checkProcessNodeList(processData, processDefinitionJson); |
|
|
|
Assert.assertEquals(Status.DATA_IS_NULL, taskNotEmptyRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.DATA_IS_NULL, taskNotEmptyRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// task cycle
|
|
|
|
|
|
|
|
String processDefinitionJsonCycle = CYCLE_SHELL_JSON; |
|
|
|
|
|
|
|
ProcessData processDataCycle = JSONUtils.parseObject(processDefinitionJsonCycle, ProcessData.class); |
|
|
|
|
|
|
|
Map<String, Object> taskCycleRes = processDefinitionService.checkProcessNodeList(processDataCycle, processDefinitionJsonCycle); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.PROCESS_NODE_HAS_CYCLE, taskCycleRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//json abnormal
|
|
|
|
//json abnormal
|
|
|
|
String abnormalJson = processDefinitionJson.replaceAll("SHELL", ""); |
|
|
|
String abnormalJson = processDefinitionJson.replaceAll("SHELL", ""); |
|
|
|
processData = JSONUtils.parseObject(abnormalJson, ProcessData.class); |
|
|
|
processData = JSONUtils.parseObject(abnormalJson, ProcessData.class); |
|
|
@ -473,7 +642,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetTaskNodeListByDefinitionId() throws Exception { |
|
|
|
public void testGetTaskNodeListByDefinitionId() { |
|
|
|
//process definition not exist
|
|
|
|
//process definition not exist
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(null); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(null); |
|
|
|
Map<String, Object> processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionId(46); |
|
|
|
Map<String, Object> processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionId(46); |
|
|
@ -486,14 +655,14 @@ public class ProcessDefinitionServiceTest { |
|
|
|
Assert.assertEquals(Status.DATA_IS_NOT_VALID, successRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.DATA_IS_NOT_VALID, successRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//success
|
|
|
|
//success
|
|
|
|
processDefinition.setProcessDefinitionJson(shellJson); |
|
|
|
processDefinition.setProcessDefinitionJson(SHELL_JSON); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); |
|
|
|
Map<String, Object> dataNotValidRes = processDefinitionService.getTaskNodeListByDefinitionId(46); |
|
|
|
Map<String, Object> dataNotValidRes = processDefinitionService.getTaskNodeListByDefinitionId(46); |
|
|
|
Assert.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetTaskNodeListByDefinitionIdList() throws Exception { |
|
|
|
public void testGetTaskNodeListByDefinitionIdList() { |
|
|
|
//process definition not exist
|
|
|
|
//process definition not exist
|
|
|
|
String defineIdList = "46"; |
|
|
|
String defineIdList = "46"; |
|
|
|
Integer[] idArray = {46}; |
|
|
|
Integer[] idArray = {46}; |
|
|
@ -503,7 +672,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
//process definition exist
|
|
|
|
//process definition exist
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
processDefinition.setProcessDefinitionJson(shellJson); |
|
|
|
processDefinition.setProcessDefinitionJson(SHELL_JSON); |
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
processDefinitionList.add(processDefinition); |
|
|
|
processDefinitionList.add(processDefinition); |
|
|
|
Mockito.when(processDefineMapper.queryDefinitionListByIdList(idArray)).thenReturn(processDefinitionList); |
|
|
|
Mockito.when(processDefineMapper.queryDefinitionListByIdList(idArray)).thenReturn(processDefinitionList); |
|
|
@ -515,7 +684,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
public void testQueryProcessDefinitionAllByProjectId() { |
|
|
|
public void testQueryProcessDefinitionAllByProjectId() { |
|
|
|
int projectId = 1; |
|
|
|
int projectId = 1; |
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
processDefinition.setProcessDefinitionJson(shellJson); |
|
|
|
processDefinition.setProcessDefinitionJson(SHELL_JSON); |
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
processDefinitionList.add(processDefinition); |
|
|
|
processDefinitionList.add(processDefinition); |
|
|
|
Mockito.when(processDefineMapper.queryAllDefinitionList(projectId)).thenReturn(processDefinitionList); |
|
|
|
Mockito.when(processDefineMapper.queryAllDefinitionList(projectId)).thenReturn(processDefinitionList); |
|
|
@ -527,7 +696,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
public void testViewTree() throws Exception { |
|
|
|
public void testViewTree() throws Exception { |
|
|
|
//process definition not exist
|
|
|
|
//process definition not exist
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
processDefinition.setProcessDefinitionJson(shellJson); |
|
|
|
processDefinition.setProcessDefinitionJson(SHELL_JSON); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(null); |
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(null); |
|
|
|
Map<String, Object> processDefinitionNullRes = processDefinitionService.viewTree(46, 10); |
|
|
|
Map<String, Object> processDefinitionNullRes = processDefinitionService.viewTree(46, 10); |
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); |
|
|
@ -567,29 +736,71 @@ public class ProcessDefinitionServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testImportProcessDefinitionById() throws IOException { |
|
|
|
public void testImportProcessDefinitionById() throws IOException { |
|
|
|
|
|
|
|
|
|
|
|
String processJson = "[{\"projectName\":\"testProject\",\"processDefinitionName\":\"shell-4\"," + |
|
|
|
String processJson = "[\n" |
|
|
|
"\"processDefinitionJson\":\"{\\\"tenantId\\\":1,\\\"globalParams\\\":[]," + |
|
|
|
+ " {\n" |
|
|
|
"\\\"tasks\\\":[{\\\"workerGroupId\\\":\\\"default\\\",\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\"," + |
|
|
|
+ " \"projectName\": \"testProject\",\n" |
|
|
|
"\\\"type\\\":\\\"SHELL\\\",\\\"params\\\":{\\\"rawScript\\\":\\\"#!/bin/bash\\\\necho \\\\\\\"shell-4\\\\\\\"\\\"," + |
|
|
|
+ " \"processDefinitionName\": \"shell-4\",\n" |
|
|
|
"\\\"localParams\\\":[],\\\"resourceList\\\":[]},\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"}," + |
|
|
|
+ " \"processDefinitionJson\": \"{\\\"tenantId\\\":1" |
|
|
|
"\\\"maxRetryTimes\\\":\\\"0\\\",\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-4\\\"," + |
|
|
|
+ ",\\\"globalParams\\\":[],\\\"tasks\\\":[{\\\"workerGroupId\\\":\\\"3\\\",\\\"description\\\"" |
|
|
|
"\\\"dependence\\\":{},\\\"retryInterval\\\":\\\"1\\\",\\\"preTasks\\\":[],\\\"id\\\":\\\"tasks-84090\\\"}," + |
|
|
|
+ ":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SHELL\\\",\\\"params\\\":{\\\"rawScript\\\"" |
|
|
|
"{\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-5\\\",\\\"workerGroupId\\\":\\\"default\\\\," + |
|
|
|
+ ":\\\"#!/bin/bash\\\\necho \\\\\\\"shell-4\\\\\\\"\\\",\\\"localParams\\\":[],\\\"resourceList\\\":[]}" |
|
|
|
"\\\"description\\\":\\\"\\\",\\\"dependence\\\":{},\\\"preTasks\\\":[\\\"shell-4\\\"],\\\"id\\\":\\\"tasks-87364\\\"," + |
|
|
|
+ ",\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"},\\\"maxRetryTimes\\\":\\\"0\\\"" |
|
|
|
"\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SUB_PROCESS\\\",\\\"params\\\":{\\\"processDefinitionId\\\":46}," + |
|
|
|
+ ",\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-4\\\",\\\"dependence\\\":{}" |
|
|
|
"\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"}}],\\\"timeout\\\":0}\"," + |
|
|
|
+ ",\\\"retryInterval\\\":\\\"1\\\",\\\"preTasks\\\":[],\\\"id\\\":\\\"tasks-84090\\\"}" |
|
|
|
"\"processDefinitionDescription\":\"\",\"processDefinitionLocations\":\"{\\\"tasks-84090\\\":{\\\"name\\\":\\\"shell-4\\\"," + |
|
|
|
+ ",{\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-5\\\",\\\"workerGroupId\\\"" |
|
|
|
"\\\"targetarr\\\":\\\"\\\",\\\"x\\\":128,\\\"y\\\":114},\\\"tasks-87364\\\":{\\\"name\\\":\\\"shell-5\\\"," + |
|
|
|
+ ":\\\"3\\\",\\\"description\\\":\\\"\\\",\\\"dependence\\\":{},\\\"preTasks\\\":[\\\"shell-4\\\"]" |
|
|
|
"\\\"targetarr\\\":\\\"tasks-84090\\\",\\\"x\\\":266,\\\"y\\\":115}}\"," + |
|
|
|
+ ",\\\"id\\\":\\\"tasks-87364\\\",\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SUB_PROCESS\\\"" |
|
|
|
"\"processDefinitionConnects\":\"[{\\\"endPointSourceId\\\":\\\"tasks-84090\\\"," + |
|
|
|
+ ",\\\"params\\\":{\\\"processDefinitionId\\\":46},\\\"timeout\\\":{\\\"enable\\\":false" |
|
|
|
"\\\"endPointTargetId\\\":\\\"tasks-87364\\\"}]\"}]"; |
|
|
|
+ ",\\\"strategy\\\":\\\"\\\"}}],\\\"timeout\\\":0}\",\n" |
|
|
|
|
|
|
|
+ " \"processDefinitionDescription\": \"\",\n" |
|
|
|
String subProcessJson = "{\"globalParams\":[]," + |
|
|
|
+ " \"processDefinitionLocations\": \"{\\\"tasks-84090\\\":{\\\"name\\\":\\\"shell-4\\\"" |
|
|
|
"\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-52423\",\"name\":\"shell-5\"," + |
|
|
|
+ ",\\\"targetarr\\\":\\\"\\\",\\\"x\\\":128,\\\"y\\\":114},\\\"tasks-87364\\\":{\\\"name\\\"" |
|
|
|
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"shell-5\\\"\"},\"description\":\"\"," + |
|
|
|
+ ":\\\"shell-5\\\",\\\"targetarr\\\":\\\"tasks-84090\\\",\\\"x\\\":266,\\\"y\\\":115}}\",\n" |
|
|
|
"\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
+ " \"processDefinitionConnects\": \"[{\\\"endPointSourceId\\\":\\\"tasks-84090\\\"" |
|
|
|
"\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":\\\"default\\\\," + |
|
|
|
+ ",\\\"endPointTargetId\\\":\\\"tasks-87364\\\"}]\"\n" |
|
|
|
"\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ "]"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String subProcessJson = "{\n" |
|
|
|
|
|
|
|
+ " \"globalParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tasks\": [\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"SHELL\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-52423\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"shell-5\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \"resourceList\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"localParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"rawScript\": \"echo \\\"shell-5\\\"\"\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"interval\": null,\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": \"3\",\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tenantId\": 1,\n" |
|
|
|
|
|
|
|
+ " \"timeout\": 0\n" |
|
|
|
|
|
|
|
+ "}"; |
|
|
|
|
|
|
|
|
|
|
|
FileUtils.writeStringToFile(new File("/tmp/task.json"), processJson); |
|
|
|
FileUtils.writeStringToFile(new File("/tmp/task.json"), processJson); |
|
|
|
|
|
|
|
|
|
|
@ -618,28 +829,13 @@ public class ProcessDefinitionServiceTest { |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(currentProjectName), currentProjectName)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(currentProjectName), currentProjectName)).thenReturn(result); |
|
|
|
Mockito.when(processDefineMapper.queryByDefineId(46)).thenReturn(shellDefinition2); |
|
|
|
Mockito.when(processDefineMapper.queryByDefineId(46)).thenReturn(shellDefinition2); |
|
|
|
|
|
|
|
|
|
|
|
//import process
|
|
|
|
Map<String, Object> importProcessResult = processDefinitionService.importProcessDefinition(loginUser, multipartFile, currentProjectName); |
|
|
|
// Map<String, Object> importProcessResult = processDefinitionService.importProcessDefinition(loginUser, multipartFile, currentProjectName);
|
|
|
|
|
|
|
|
//
|
|
|
|
Assert.assertEquals(Status.SUCCESS, importProcessResult.get(Constants.STATUS)); |
|
|
|
// Assert.assertEquals(Status.SUCCESS, importProcessResult.get(Constants.STATUS));
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// boolean delete = file.delete();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Assert.assertTrue(delete);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// String processMetaJson = "";
|
|
|
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// processMetaJson = "{\"scheduleWorkerGroupId\":-1}";
|
|
|
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// processMetaJson = "{\"scheduleWorkerGroupId\":-1,\"projectName\":\"test\"}";
|
|
|
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// processMetaJson = "{\"scheduleWorkerGroupId\":-1,\"projectName\":\"test\",\"processDefinitionName\":\"test_definition\"}";
|
|
|
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean delete = file.delete(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.assertTrue(delete); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -658,12 +854,122 @@ public class ProcessDefinitionServiceTest { |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
Mockito.when(processService.findProcessDefineById(1)).thenReturn(getProcessDefinition()); |
|
|
|
Mockito.when(processService.findProcessDefineById(1)).thenReturn(getProcessDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String sqlDependentJson = "{\n" |
|
|
|
|
|
|
|
+ " \"globalParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tasks\": [\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"SQL\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-27297\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"sql\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"MYSQL\",\n" |
|
|
|
|
|
|
|
+ " \"datasource\": 1,\n" |
|
|
|
|
|
|
|
+ " \"sql\": \"select * from test\",\n" |
|
|
|
|
|
|
|
+ " \"udfs\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"sqlType\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"title\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"receivers\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"receiversCc\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"showType\": \"TABLE\",\n" |
|
|
|
|
|
|
|
+ " \"localParams\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"connParams\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"preStatements\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"postStatements\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \"dependent\"\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"type\": \"DEPENDENT\",\n" |
|
|
|
|
|
|
|
+ " \"id\": \"tasks-33787\",\n" |
|
|
|
|
|
|
|
+ " \"name\": \"dependent\",\n" |
|
|
|
|
|
|
|
+ " \"params\": {\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"description\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"runFlag\": \"NORMAL\",\n" |
|
|
|
|
|
|
|
+ " \"dependence\": {\n" |
|
|
|
|
|
|
|
+ " \"relation\": \"AND\",\n" |
|
|
|
|
|
|
|
+ " \"dependTaskList\": [\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"relation\": \"AND\",\n" |
|
|
|
|
|
|
|
+ " \"dependItemList\": [\n" |
|
|
|
|
|
|
|
+ " {\n" |
|
|
|
|
|
|
|
+ " \"projectId\": 2,\n" |
|
|
|
|
|
|
|
+ " \"definitionId\": 46,\n" |
|
|
|
|
|
|
|
+ " \"depTasks\": \"ALL\",\n" |
|
|
|
|
|
|
|
+ " \"cycle\": \"day\",\n" |
|
|
|
|
|
|
|
+ " \"dateValue\": \"today\"\n" |
|
|
|
|
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"maxRetryTimes\": \"0\",\n" |
|
|
|
|
|
|
|
+ " \"retryInterval\": \"1\",\n" |
|
|
|
|
|
|
|
+ " \"timeout\": {\n" |
|
|
|
|
|
|
|
+ " \"strategy\": \"\",\n" |
|
|
|
|
|
|
|
+ " \"enable\": false\n" |
|
|
|
|
|
|
|
+ " },\n" |
|
|
|
|
|
|
|
+ " \"taskInstancePriority\": \"MEDIUM\",\n" |
|
|
|
|
|
|
|
+ " \"workerGroupId\": -1,\n" |
|
|
|
|
|
|
|
+ " \"preTasks\": [\n" |
|
|
|
|
|
|
|
+ " \n" |
|
|
|
|
|
|
|
+ " ]\n" |
|
|
|
|
|
|
|
+ " }\n" |
|
|
|
|
|
|
|
+ " ],\n" |
|
|
|
|
|
|
|
+ " \"tenantId\": 1,\n" |
|
|
|
|
|
|
|
+ " \"timeout\": 0\n" |
|
|
|
|
|
|
|
+ "}"; |
|
|
|
Map<String, Object> updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectName, 1, "test", |
|
|
|
Map<String, Object> updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectName, 1, "test", |
|
|
|
sqlDependentJson, "", "", ""); |
|
|
|
sqlDependentJson, "", "", ""); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR, updateResult.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.UPDATE_PROCESS_DEFINITION_ERROR, updateResult.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testBatchExportProcessDefinitionByIds() { |
|
|
|
|
|
|
|
processDefinitionService.batchExportProcessDefinitionByIds( |
|
|
|
|
|
|
|
null, null, null, null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User loginUser = new User(); |
|
|
|
|
|
|
|
loginUser.setId(1); |
|
|
|
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String projectName = "project_test1"; |
|
|
|
|
|
|
|
Project project = getProject(projectName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT); |
|
|
|
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
processDefinitionService.batchExportProcessDefinitionByIds( |
|
|
|
|
|
|
|
loginUser, projectName, "1", null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get mock datasource |
|
|
|
* get mock datasource |
|
|
|
* |
|
|
|
* |
|
|
@ -715,7 +1021,7 @@ public class ProcessDefinitionServiceTest { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Project getProjectById(int projectId) { |
|
|
|
private Project getProjectById(int projectId) { |
|
|
|
Project project = new Project(); |
|
|
|
Project project = new Project(); |
|
|
|
project.setId(1); |
|
|
|
project.setId(projectId); |
|
|
|
project.setName("project_test2"); |
|
|
|
project.setName("project_test2"); |
|
|
|
project.setUserId(1); |
|
|
|
project.setUserId(1); |
|
|
|
return project; |
|
|
|
return project; |
|
|
|