|
|
@ -17,13 +17,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertDoesNotThrow; |
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.AssertionsHelper.assertThrowsServiceException; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_CREATE; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_CREATE; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_DELETE; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_DELETE; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_UPDATE; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.TASK_DEFINITION_UPDATE; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_SWITCH_TO_THIS_VERSION; |
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_SWITCH_TO_THIS_VERSION; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
import static org.mockito.ArgumentMatchers.isA; |
|
|
|
import static org.mockito.ArgumentMatchers.isA; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.doNothing; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.doThrow; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.dto.task.TaskCreateRequest; |
|
|
|
import org.apache.dolphinscheduler.api.dto.task.TaskCreateRequest; |
|
|
|
import org.apache.dolphinscheduler.api.dto.task.TaskUpdateRequest; |
|
|
|
import org.apache.dolphinscheduler.api.dto.task.TaskUpdateRequest; |
|
|
@ -75,13 +81,17 @@ import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
import org.junit.jupiter.api.extension.ExtendWith; |
|
|
|
import org.mockito.InjectMocks; |
|
|
|
import org.mockito.InjectMocks; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mock; |
|
|
|
|
|
|
|
import org.mockito.MockedStatic; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
import org.mockito.junit.jupiter.MockitoExtension; |
|
|
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoSettings; |
|
|
|
|
|
|
|
import org.mockito.quality.Strictness; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
|
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
@ExtendWith(MockitoExtension.class) |
|
|
|
|
|
|
|
@MockitoSettings(strictness = Strictness.LENIENT) |
|
|
|
public class TaskDefinitionServiceImplTest { |
|
|
|
public class TaskDefinitionServiceImplTest { |
|
|
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
@InjectMocks |
|
|
@ -114,9 +124,6 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private TaskPluginManager taskPluginManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ProcessTaskRelationService processTaskRelationService; |
|
|
|
private ProcessTaskRelationService processTaskRelationService; |
|
|
|
|
|
|
|
|
|
|
@ -155,13 +162,17 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void createTaskDefinition() { |
|
|
|
public void createTaskDefinition() { |
|
|
|
|
|
|
|
try ( |
|
|
|
|
|
|
|
MockedStatic<TaskPluginManager> taskPluginManagerMockedStatic = |
|
|
|
|
|
|
|
Mockito.mockStatic(TaskPluginManager.class)) { |
|
|
|
|
|
|
|
taskPluginManagerMockedStatic.when(() -> TaskPluginManager.checkTaskParameters(Mockito.any())) |
|
|
|
|
|
|
|
.thenReturn(true); |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Mockito.when(projectService.hasProjectAndWritePerm(user, project, result)) |
|
|
|
when(projectService.hasProjectAndWritePerm(user, project, result)) |
|
|
|
.thenReturn(true); |
|
|
|
.thenReturn(true); |
|
|
|
Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String createTaskDefinitionJson = |
|
|
|
String createTaskDefinitionJson = |
|
|
|
"[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
"[{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
@ -173,43 +184,51 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
+ "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}]"; |
|
|
|
+ "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}]"; |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.createTaskDefinition(user, PROJECT_CODE, createTaskDefinitionJson); |
|
|
|
.createTaskDefinition(user, PROJECT_CODE, createTaskDefinitionJson); |
|
|
|
Assertions.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void updateTaskDefinition() { |
|
|
|
public void updateTaskDefinition() { |
|
|
|
String taskDefinitionJson = getTaskDefinitionJson();; |
|
|
|
try ( |
|
|
|
|
|
|
|
MockedStatic<TaskPluginManager> taskPluginManagerMockedStatic = |
|
|
|
|
|
|
|
Mockito.mockStatic(TaskPluginManager.class)) { |
|
|
|
|
|
|
|
taskPluginManagerMockedStatic.when(() -> TaskPluginManager.checkTaskParameters(Mockito.any())) |
|
|
|
|
|
|
|
.thenReturn(true); |
|
|
|
|
|
|
|
String taskDefinitionJson = getTaskDefinitionJson(); |
|
|
|
|
|
|
|
|
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
putMsg(result, Status.SUCCESS, PROJECT_CODE); |
|
|
|
putMsg(result, Status.SUCCESS, PROJECT_CODE); |
|
|
|
Mockito.when(projectService.hasProjectAndWritePerm(user, project, new HashMap<>())).thenReturn(true); |
|
|
|
when(projectService.hasProjectAndWritePerm(user, project, new HashMap<>())).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(processService.isTaskOnline(TASK_CODE)).thenReturn(Boolean.FALSE); |
|
|
|
when(processService.isTaskOnline(TASK_CODE)).thenReturn(Boolean.FALSE); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(new TaskDefinition()); |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(new TaskDefinition()); |
|
|
|
Mockito.when(taskDefinitionMapper.updateById(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
when(taskDefinitionMapper.updateById(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
when(taskDefinitionLogMapper.insert(Mockito.any(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(processTaskRelationLogDao.insert(Mockito.any(ProcessTaskRelationLog.class))).thenReturn(1); |
|
|
|
when(processTaskRelationLogDao.insert(Mockito.any(ProcessTaskRelationLog.class))).thenReturn(1); |
|
|
|
Mockito.when(processDefinitionMapper.queryByCode(2L)).thenReturn(new ProcessDefinition()); |
|
|
|
when(processDefinitionMapper.queryByCode(2L)).thenReturn(new ProcessDefinition()); |
|
|
|
Mockito.when(processDefinitionMapper.updateById(Mockito.any(ProcessDefinition.class))).thenReturn(1); |
|
|
|
when(processDefinitionMapper.updateById(Mockito.any(ProcessDefinition.class))).thenReturn(1); |
|
|
|
Mockito.when(processDefinitionLogMapper.insert(Mockito.any(ProcessDefinitionLog.class))).thenReturn(1); |
|
|
|
when(processDefinitionLogMapper.insert(Mockito.any(ProcessDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(1); |
|
|
|
when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(1); |
|
|
|
Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
when(processTaskRelationMapper.queryProcessTaskRelationByTaskCodeAndTaskVersion(TASK_CODE, 0)) |
|
|
|
Mockito.when(processTaskRelationMapper.queryProcessTaskRelationByTaskCodeAndTaskVersion(TASK_CODE, 0)) |
|
|
|
|
|
|
|
.thenReturn(getProcessTaskRelationList2()); |
|
|
|
.thenReturn(getProcessTaskRelationList2()); |
|
|
|
Mockito.when(processTaskRelationMapper |
|
|
|
when(processTaskRelationMapper |
|
|
|
.updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(1); |
|
|
|
.updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(1); |
|
|
|
result = taskDefinitionService.updateTaskDefinition(user, PROJECT_CODE, TASK_CODE, taskDefinitionJson); |
|
|
|
result = taskDefinitionService.updateTaskDefinition(user, PROJECT_CODE, TASK_CODE, taskDefinitionJson); |
|
|
|
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
// failure
|
|
|
|
// failure
|
|
|
|
Mockito.when(processTaskRelationMapper |
|
|
|
when(processTaskRelationMapper |
|
|
|
.updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(2); |
|
|
|
.updateProcessTaskRelationTaskVersion(Mockito.any(ProcessTaskRelation.class))).thenReturn(2); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
() -> taskDefinitionService.updateTaskDefinition(user, PROJECT_CODE, TASK_CODE, taskDefinitionJson)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinition(user, PROJECT_CODE, TASK_CODE, |
|
|
|
Assertions.assertEquals(Status.PROCESS_TASK_RELATION_BATCH_UPDATE_ERROR.getCode(), |
|
|
|
taskDefinitionJson)); |
|
|
|
|
|
|
|
assertEquals(Status.PROCESS_TASK_RELATION_BATCH_UPDATE_ERROR.getCode(), |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -217,72 +236,72 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
public void queryTaskDefinitionByName() { |
|
|
|
public void queryTaskDefinitionByName() { |
|
|
|
String taskName = "task"; |
|
|
|
String taskName = "task"; |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
putMsg(result, Status.SUCCESS, PROJECT_CODE); |
|
|
|
putMsg(result, Status.SUCCESS, PROJECT_CODE); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, TASK_DEFINITION)) |
|
|
|
when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, TASK_DEFINITION)) |
|
|
|
.thenReturn(result); |
|
|
|
.thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByName(project.getCode(), PROCESS_DEFINITION_CODE, taskName)) |
|
|
|
when(taskDefinitionMapper.queryByName(project.getCode(), PROCESS_DEFINITION_CODE, taskName)) |
|
|
|
.thenReturn(new TaskDefinition()); |
|
|
|
.thenReturn(new TaskDefinition()); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.queryTaskDefinitionByName(user, PROJECT_CODE, PROCESS_DEFINITION_CODE, taskName); |
|
|
|
.queryTaskDefinitionByName(user, PROJECT_CODE, PROCESS_DEFINITION_CODE, taskName); |
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void deleteTaskDefinitionByCode() { |
|
|
|
public void deleteTaskDefinitionByCode() { |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
|
|
// error task definition not find
|
|
|
|
// error task definition not find
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
() -> taskDefinitionService.deleteTaskDefinitionByCode(user, TASK_CODE)); |
|
|
|
() -> taskDefinitionService.deleteTaskDefinitionByCode(user, TASK_CODE)); |
|
|
|
Assertions.assertEquals(Status.TASK_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
assertEquals(Status.TASK_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// error delete single task definition object
|
|
|
|
// error delete single task definition object
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(getTaskDefinition()); |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(getTaskDefinition()); |
|
|
|
Mockito.when(taskDefinitionMapper.deleteByCode(TASK_CODE)).thenReturn(0); |
|
|
|
when(taskDefinitionMapper.deleteByCode(TASK_CODE)).thenReturn(0); |
|
|
|
Mockito.when(projectService.hasProjectAndWritePerm(user, project, new HashMap<>())).thenReturn(true); |
|
|
|
when(projectService.hasProjectAndWritePerm(user, project, new HashMap<>())).thenReturn(true); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
() -> taskDefinitionService.deleteTaskDefinitionByCode(user, TASK_CODE)); |
|
|
|
() -> taskDefinitionService.deleteTaskDefinitionByCode(user, TASK_CODE)); |
|
|
|
Assertions.assertEquals(Status.DELETE_TASK_DEFINE_BY_CODE_MSG_ERROR.getCode(), |
|
|
|
assertEquals(Status.DELETE_TASK_DEFINE_BY_CODE_MSG_ERROR.getCode(), |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
// success
|
|
|
|
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, |
|
|
|
doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, |
|
|
|
TASK_DEFINITION_DELETE); |
|
|
|
TASK_DEFINITION_DELETE); |
|
|
|
Mockito.when(processTaskRelationMapper.queryDownstreamByTaskCode(TASK_CODE)).thenReturn(new ArrayList<>()); |
|
|
|
when(processTaskRelationMapper.queryDownstreamByTaskCode(TASK_CODE)).thenReturn(new ArrayList<>()); |
|
|
|
Mockito.when(taskDefinitionMapper.deleteByCode(TASK_CODE)).thenReturn(1); |
|
|
|
when(taskDefinitionMapper.deleteByCode(TASK_CODE)).thenReturn(1); |
|
|
|
Assertions.assertDoesNotThrow(() -> taskDefinitionService.deleteTaskDefinitionByCode(user, TASK_CODE)); |
|
|
|
Assertions.assertDoesNotThrow(() -> taskDefinitionService.deleteTaskDefinitionByCode(user, TASK_CODE)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void switchVersion() { |
|
|
|
public void switchVersion() { |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS, PROJECT_CODE); |
|
|
|
putMsg(result, Status.SUCCESS, PROJECT_CODE); |
|
|
|
Mockito.when( |
|
|
|
when( |
|
|
|
projectService.checkProjectAndAuth(user, project, PROJECT_CODE, WORKFLOW_SWITCH_TO_THIS_VERSION)) |
|
|
|
projectService.checkProjectAndAuth(user, project, PROJECT_CODE, WORKFLOW_SWITCH_TO_THIS_VERSION)) |
|
|
|
.thenReturn(result); |
|
|
|
.thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(TASK_CODE, VERSION)) |
|
|
|
when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(TASK_CODE, VERSION)) |
|
|
|
.thenReturn(new TaskDefinitionLog()); |
|
|
|
.thenReturn(new TaskDefinitionLog()); |
|
|
|
TaskDefinition taskDefinition = new TaskDefinition(); |
|
|
|
TaskDefinition taskDefinition = new TaskDefinition(); |
|
|
|
taskDefinition.setProjectCode(PROJECT_CODE); |
|
|
|
taskDefinition.setProjectCode(PROJECT_CODE); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)) |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)) |
|
|
|
.thenReturn(taskDefinition); |
|
|
|
.thenReturn(taskDefinition); |
|
|
|
Mockito.when(taskDefinitionMapper.updateById(new TaskDefinitionLog())).thenReturn(1); |
|
|
|
when(taskDefinitionMapper.updateById(new TaskDefinitionLog())).thenReturn(1); |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
Map<String, Object> relation = taskDefinitionService |
|
|
|
.switchVersion(user, PROJECT_CODE, TASK_CODE, VERSION); |
|
|
|
.switchVersion(user, PROJECT_CODE, TASK_CODE, VERSION); |
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, relation.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void putMsg(Map<String, Object> result, Status status, Object... statusParams) { |
|
|
|
private void putMsg(Map<String, Object> result, Status status, Object... statusParams) { |
|
|
@ -331,7 +350,7 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void genTaskCodeList() { |
|
|
|
public void genTaskCodeList() { |
|
|
|
Map<String, Object> genTaskCodeList = taskDefinitionService.genTaskCodeList(10); |
|
|
|
Map<String, Object> genTaskCodeList = taskDefinitionService.genTaskCodeList(10); |
|
|
|
Assertions.assertEquals(Status.SUCCESS, genTaskCodeList.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, genTaskCodeList.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -348,31 +367,31 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
taskMainInfo.setUpstreamTaskName("4"); |
|
|
|
taskMainInfo.setUpstreamTaskName("4"); |
|
|
|
taskMainInfoIPage.setRecords(Collections.singletonList(taskMainInfo)); |
|
|
|
taskMainInfoIPage.setRecords(Collections.singletonList(taskMainInfo)); |
|
|
|
taskMainInfoIPage.setTotal(10L); |
|
|
|
taskMainInfoIPage.setTotal(10L); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, TASK_DEFINITION)) |
|
|
|
when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, TASK_DEFINITION)) |
|
|
|
.thenReturn(checkResult); |
|
|
|
.thenReturn(checkResult); |
|
|
|
Mockito.when(taskDefinitionMapper.queryDefineListPaging(Mockito.any(Page.class), Mockito.anyLong(), |
|
|
|
when(taskDefinitionMapper.queryDefineListPaging(Mockito.any(Page.class), Mockito.anyLong(), |
|
|
|
Mockito.isNull(), Mockito.anyString(), Mockito.isNull())) |
|
|
|
Mockito.isNull(), Mockito.anyString(), Mockito.isNull())) |
|
|
|
.thenReturn(taskMainInfoIPage); |
|
|
|
.thenReturn(taskMainInfoIPage); |
|
|
|
Mockito.when(taskDefinitionMapper.queryDefineListByCodeList(PROJECT_CODE, Collections.singletonList(3L))) |
|
|
|
when(taskDefinitionMapper.queryDefineListByCodeList(PROJECT_CODE, Collections.singletonList(3L))) |
|
|
|
.thenReturn(Collections.singletonList(taskMainInfo)); |
|
|
|
.thenReturn(Collections.singletonList(taskMainInfo)); |
|
|
|
Result result = taskDefinitionService.queryTaskDefinitionListPaging(user, PROJECT_CODE, |
|
|
|
Result result = taskDefinitionService.queryTaskDefinitionListPaging(user, PROJECT_CODE, |
|
|
|
null, null, null, pageNo, pageSize); |
|
|
|
null, null, null, pageNo, pageSize); |
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testReleaseTaskDefinition() { |
|
|
|
public void testReleaseTaskDefinition() { |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
Project project = getProject(); |
|
|
|
Project project = getProject(); |
|
|
|
|
|
|
|
|
|
|
|
// check task dose not exist
|
|
|
|
// check task dose not exist
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, TASK_CODE); |
|
|
|
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, TASK_CODE); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, null)).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, null)).thenReturn(result); |
|
|
|
Map<String, Object> map = |
|
|
|
Map<String, Object> map = |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.OFFLINE); |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.OFFLINE); |
|
|
|
Assertions.assertEquals(Status.TASK_DEFINE_NOT_EXIST, map.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.TASK_DEFINE_NOT_EXIST, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// process definition offline
|
|
|
|
// process definition offline
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
@ -384,23 +403,23 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
"{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}"; |
|
|
|
"{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}"; |
|
|
|
taskDefinition.setTaskParams(params); |
|
|
|
taskDefinition.setTaskParams(params); |
|
|
|
taskDefinition.setTaskType("SHELL"); |
|
|
|
taskDefinition.setTaskType("SHELL"); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(taskDefinition); |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(taskDefinition); |
|
|
|
TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog(taskDefinition); |
|
|
|
TaskDefinitionLog taskDefinitionLog = new TaskDefinitionLog(taskDefinition); |
|
|
|
Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(TASK_CODE, taskDefinition.getVersion())) |
|
|
|
when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(TASK_CODE, taskDefinition.getVersion())) |
|
|
|
.thenReturn(taskDefinitionLog); |
|
|
|
.thenReturn(taskDefinitionLog); |
|
|
|
Map<String, Object> offlineTaskResult = |
|
|
|
Map<String, Object> offlineTaskResult = |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.OFFLINE); |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.OFFLINE); |
|
|
|
Assertions.assertEquals(Status.SUCCESS, offlineTaskResult.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, offlineTaskResult.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// process definition online, resource exist
|
|
|
|
// process definition online, resource exist
|
|
|
|
Map<String, Object> onlineTaskResult = |
|
|
|
Map<String, Object> onlineTaskResult = |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.ONLINE); |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.ONLINE); |
|
|
|
Assertions.assertEquals(Status.SUCCESS, onlineTaskResult.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, onlineTaskResult.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// release error code
|
|
|
|
// release error code
|
|
|
|
Map<String, Object> failResult = |
|
|
|
Map<String, Object> failResult = |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.getEnum(2)); |
|
|
|
taskDefinitionService.releaseTaskDefinition(user, PROJECT_CODE, TASK_CODE, ReleaseState.getEnum(2)); |
|
|
|
Assertions.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failResult.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failResult.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -410,123 +429,116 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
taskCreateRequest.setWorkflowCode(PROCESS_DEFINITION_CODE); |
|
|
|
taskCreateRequest.setWorkflowCode(PROCESS_DEFINITION_CODE); |
|
|
|
|
|
|
|
|
|
|
|
// error process definition not find
|
|
|
|
// error process definition not find
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.PROCESS_DEFINE_NOT_EXIST, |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
Assertions.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error project not find
|
|
|
|
// error project not find
|
|
|
|
Mockito.when(processDefinitionMapper.queryByCode(PROCESS_DEFINITION_CODE)).thenReturn(getProcessDefinition()); |
|
|
|
when(processDefinitionMapper.queryByCode(PROCESS_DEFINITION_CODE)).thenReturn(getProcessDefinition()); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) |
|
|
|
doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) |
|
|
|
.checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION_CREATE); |
|
|
|
.checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION_CREATE); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.PROJECT_NOT_EXIST, |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error task definition
|
|
|
|
// error task definition
|
|
|
|
taskCreateRequest.setTaskParams(TASK_PARAMETER); |
|
|
|
taskCreateRequest.setTaskParams(TASK_PARAMETER); |
|
|
|
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, getProject(), |
|
|
|
doNothing().when(projectService).checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION_CREATE); |
|
|
|
TASK_DEFINITION_CREATE); |
|
|
|
assertThrowsServiceException(Status.PROCESS_NODE_S_PARAMETER_INVALID, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
Assertions.assertEquals(Status.PROCESS_NODE_S_PARAMETER_INVALID.getCode(), |
|
|
|
|
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
try ( |
|
|
|
|
|
|
|
MockedStatic<TaskPluginManager> taskPluginManagerMockedStatic = |
|
|
|
|
|
|
|
Mockito.mockStatic(TaskPluginManager.class)) { |
|
|
|
|
|
|
|
taskPluginManagerMockedStatic.when(() -> TaskPluginManager.checkTaskParameters(Mockito.any())) |
|
|
|
|
|
|
|
.thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
// error create task definition object
|
|
|
|
// error create task definition object
|
|
|
|
Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
when(taskDefinitionMapper.insert(isA(TaskDefinition.class))).thenReturn(0); |
|
|
|
Mockito.when(taskDefinitionMapper.insert(isA(TaskDefinition.class))).thenReturn(0); |
|
|
|
assertThrowsServiceException(Status.CREATE_TASK_DEFINITION_ERROR, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
Assertions.assertEquals(Status.CREATE_TASK_DEFINITION_ERROR.getCode(), |
|
|
|
|
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error sync to task definition log
|
|
|
|
// error sync to task definition log
|
|
|
|
Mockito.when(taskDefinitionMapper.insert(isA(TaskDefinition.class))).thenReturn(1); |
|
|
|
when(taskDefinitionMapper.insert(isA(TaskDefinition.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(0); |
|
|
|
when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(0); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.CREATE_TASK_DEFINITION_LOG_ERROR, |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
Assertions.assertEquals(Status.CREATE_TASK_DEFINITION_LOG_ERROR.getCode(), |
|
|
|
|
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
// success
|
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
// we do not test updateUpstreamTaskDefinition, because it should be tested in processTaskRelationService
|
|
|
|
// we do not test updateUpstreamTaskDefinition, because it should be tested in processTaskRelationService
|
|
|
|
Mockito.when( |
|
|
|
when( |
|
|
|
processTaskRelationService.updateUpstreamTaskDefinitionWithSyncDag(isA(User.class), isA(Long.class), |
|
|
|
processTaskRelationService.updateUpstreamTaskDefinitionWithSyncDag(isA(User.class), isA(Long.class), |
|
|
|
isA(Boolean.class), |
|
|
|
isA(Boolean.class), |
|
|
|
isA(TaskRelationUpdateUpstreamRequest.class))) |
|
|
|
isA(TaskRelationUpdateUpstreamRequest.class))) |
|
|
|
.thenReturn(getProcessTaskRelationList()); |
|
|
|
.thenReturn(getProcessTaskRelationList()); |
|
|
|
Mockito.when(processDefinitionService.updateSingleProcessDefinition(isA(User.class), isA(Long.class), |
|
|
|
when(processDefinitionService.updateSingleProcessDefinition(isA(User.class), isA(Long.class), |
|
|
|
isA(WorkflowUpdateRequest.class))).thenReturn(getProcessDefinition()); |
|
|
|
isA(WorkflowUpdateRequest.class))).thenReturn(getProcessDefinition()); |
|
|
|
Assertions.assertDoesNotThrow(() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
assertDoesNotThrow(() -> taskDefinitionService.createTaskDefinitionV2(user, taskCreateRequest)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdateTaskDefinitionV2() { |
|
|
|
public void testUpdateTaskDefinitionV2() { |
|
|
|
TaskUpdateRequest taskUpdateRequest = new TaskUpdateRequest(); |
|
|
|
TaskUpdateRequest taskUpdateRequest = new TaskUpdateRequest(); |
|
|
|
|
|
|
|
TaskDefinition taskDefinition = getTaskDefinition(); |
|
|
|
|
|
|
|
Project project = getProject(); |
|
|
|
|
|
|
|
|
|
|
|
// error task definition not exists
|
|
|
|
// error task definition not exists
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.TASK_DEFINITION_NOT_EXISTS, |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.TASK_DEFINITION_NOT_EXISTS.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error project not find
|
|
|
|
// error project not find
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(getTaskDefinition()); |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(taskDefinition); |
|
|
|
Mockito.when(projectMapper.queryByCode(isA(Long.class))).thenReturn(getProject()); |
|
|
|
when(projectMapper.queryByCode(isA(Long.class))).thenReturn(project); |
|
|
|
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) |
|
|
|
doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) |
|
|
|
.checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION_UPDATE); |
|
|
|
.checkProjectAndAuthThrowException(user, project, TASK_DEFINITION_UPDATE); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.PROJECT_NOT_EXIST, |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error task definition
|
|
|
|
// error task definition
|
|
|
|
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, getProject(), |
|
|
|
doNothing().when(projectService).checkProjectAndAuthThrowException(user, project, TASK_DEFINITION_UPDATE); |
|
|
|
TASK_DEFINITION_UPDATE); |
|
|
|
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
try ( |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
MockedStatic<TaskPluginManager> taskPluginManagerMockedStatic = |
|
|
|
Assertions.assertEquals(Status.PROCESS_NODE_S_PARAMETER_INVALID.getCode(), |
|
|
|
Mockito.mockStatic(TaskPluginManager.class)) { |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
taskPluginManagerMockedStatic.when(() -> TaskPluginManager.checkTaskParameters(Mockito.any())) |
|
|
|
|
|
|
|
.thenReturn(false); |
|
|
|
// error task definition already online
|
|
|
|
assertThrowsServiceException(Status.PROCESS_NODE_S_PARAMETER_INVALID, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.PROCESS_NODE_S_PARAMETER_INVALID.getCode(), |
|
|
|
} |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try ( |
|
|
|
|
|
|
|
MockedStatic<TaskPluginManager> taskPluginManagerMockedStatic = |
|
|
|
|
|
|
|
Mockito.mockStatic(TaskPluginManager.class)) { |
|
|
|
|
|
|
|
taskPluginManagerMockedStatic.when(() -> TaskPluginManager.checkTaskParameters(Mockito.any())) |
|
|
|
|
|
|
|
.thenReturn(true); |
|
|
|
// error task definition nothing update
|
|
|
|
// error task definition nothing update
|
|
|
|
Mockito.when(processService.isTaskOnline(TASK_CODE)).thenReturn(false); |
|
|
|
when(processService.isTaskOnline(TASK_CODE)).thenReturn(false); |
|
|
|
Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
assertThrowsServiceException(Status.TASK_DEFINITION_NOT_CHANGE, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.TASK_DEFINITION_NOT_CHANGE.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error task definition version invalid
|
|
|
|
// error task definition version invalid
|
|
|
|
taskUpdateRequest.setTaskPriority(String.valueOf(Priority.HIGH)); |
|
|
|
taskUpdateRequest.setTaskPriority(String.valueOf(Priority.HIGH)); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.DATA_IS_NOT_VALID, |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.DATA_IS_NOT_VALID.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error task definition update effect number
|
|
|
|
// error task definition update effect number
|
|
|
|
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(VERSION); |
|
|
|
when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(VERSION); |
|
|
|
Mockito.when(taskDefinitionMapper.updateById(isA(TaskDefinition.class))).thenReturn(0); |
|
|
|
when(taskDefinitionMapper.updateById(isA(TaskDefinition.class))).thenReturn(0); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.UPDATE_TASK_DEFINITION_ERROR, |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.UPDATE_TASK_DEFINITION_ERROR.getCode(), |
|
|
|
|
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// error task definition log insert
|
|
|
|
// error task definition log insert
|
|
|
|
Mockito.when(taskDefinitionMapper.updateById(isA(TaskDefinition.class))).thenReturn(1); |
|
|
|
when(taskDefinitionMapper.updateById(isA(TaskDefinition.class))).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(0); |
|
|
|
when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(0); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
assertThrowsServiceException(Status.CREATE_TASK_DEFINITION_LOG_ERROR, |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
Assertions.assertEquals(Status.CREATE_TASK_DEFINITION_LOG_ERROR.getCode(), |
|
|
|
|
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
// success
|
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
when(taskDefinitionLogMapper.insert(isA(TaskDefinitionLog.class))).thenReturn(1); |
|
|
|
// we do not test updateUpstreamTaskDefinition, because it should be tested in processTaskRelationService
|
|
|
|
// we do not test updateUpstreamTaskDefinition, because it should be tested in processTaskRelationService
|
|
|
|
Mockito.when( |
|
|
|
when( |
|
|
|
processTaskRelationService.updateUpstreamTaskDefinitionWithSyncDag(isA(User.class), isA(Long.class), |
|
|
|
processTaskRelationService.updateUpstreamTaskDefinitionWithSyncDag(isA(User.class), isA(Long.class), |
|
|
|
isA(Boolean.class), |
|
|
|
isA(Boolean.class), |
|
|
|
isA(TaskRelationUpdateUpstreamRequest.class))) |
|
|
|
isA(TaskRelationUpdateUpstreamRequest.class))) |
|
|
@ -534,9 +546,10 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
Assertions.assertDoesNotThrow( |
|
|
|
Assertions.assertDoesNotThrow( |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
() -> taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest)); |
|
|
|
|
|
|
|
|
|
|
|
TaskDefinition taskDefinition = |
|
|
|
taskDefinition = |
|
|
|
taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest); |
|
|
|
taskDefinitionService.updateTaskDefinitionV2(user, TASK_CODE, taskUpdateRequest); |
|
|
|
Assertions.assertEquals(getTaskDefinition().getVersion() + 1, taskDefinition.getVersion()); |
|
|
|
assertEquals(getTaskDefinition().getVersion() + 1, taskDefinition.getVersion()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -549,28 +562,28 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
ArrayList<TaskDefinitionLog> taskDefinitionLogs = new ArrayList<>(); |
|
|
|
ArrayList<TaskDefinitionLog> taskDefinitionLogs = new ArrayList<>(); |
|
|
|
taskDefinitionLogs.add(taskDefinitionLog); |
|
|
|
taskDefinitionLogs.add(taskDefinitionLog); |
|
|
|
Integer version = 1; |
|
|
|
Integer version = 1; |
|
|
|
Mockito.when(processDefinitionMapper.queryByCode(isA(long.class))).thenReturn(processDefinition); |
|
|
|
when(processDefinitionMapper.queryByCode(isA(long.class))).thenReturn(processDefinition); |
|
|
|
|
|
|
|
|
|
|
|
// saveProcessDefine
|
|
|
|
// saveProcessDefine
|
|
|
|
Mockito.when(processDefineLogMapper.queryMaxVersionForDefinition(isA(long.class))).thenReturn(version); |
|
|
|
when(processDefineLogMapper.queryMaxVersionForDefinition(isA(long.class))).thenReturn(version); |
|
|
|
Mockito.when(processDefineLogMapper.insert(isA(ProcessDefinitionLog.class))).thenReturn(1); |
|
|
|
when(processDefineLogMapper.insert(isA(ProcessDefinitionLog.class))).thenReturn(1); |
|
|
|
Mockito.when(processDefinitionMapper.insert(isA(ProcessDefinitionLog.class))).thenReturn(1); |
|
|
|
when(processDefinitionMapper.insert(isA(ProcessDefinitionLog.class))).thenReturn(1); |
|
|
|
int insertVersion = |
|
|
|
int insertVersion = |
|
|
|
processServiceImpl.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.TRUE); |
|
|
|
processServiceImpl.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.TRUE); |
|
|
|
Mockito.when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.TRUE)) |
|
|
|
when(processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.TRUE)) |
|
|
|
.thenReturn(insertVersion); |
|
|
|
.thenReturn(insertVersion); |
|
|
|
Assertions.assertEquals(insertVersion, version + 1); |
|
|
|
assertEquals(insertVersion, version + 1); |
|
|
|
|
|
|
|
|
|
|
|
// saveTaskRelation
|
|
|
|
// saveTaskRelation
|
|
|
|
List<ProcessTaskRelationLog> processTaskRelationLogList = getProcessTaskRelationLogList(); |
|
|
|
List<ProcessTaskRelationLog> processTaskRelationLogList = getProcessTaskRelationLogList(); |
|
|
|
Mockito.when(processTaskRelationMapper.queryByProcessCode(eq(processDefinition.getCode()))) |
|
|
|
when(processTaskRelationMapper.queryByProcessCode(eq(processDefinition.getCode()))) |
|
|
|
.thenReturn(processTaskRelationList); |
|
|
|
.thenReturn(processTaskRelationList); |
|
|
|
Mockito.when(processTaskRelationMapper.batchInsert(isA(List.class))).thenReturn(1); |
|
|
|
when(processTaskRelationMapper.batchInsert(isA(List.class))).thenReturn(1); |
|
|
|
Mockito.when(processTaskRelationLogMapper.batchInsert(isA(List.class))).thenReturn(1); |
|
|
|
when(processTaskRelationLogMapper.batchInsert(isA(List.class))).thenReturn(1); |
|
|
|
int insertResult = processServiceImpl.saveTaskRelation(loginUser, processDefinition.getProjectCode(), |
|
|
|
int insertResult = processServiceImpl.saveTaskRelation(loginUser, processDefinition.getProjectCode(), |
|
|
|
processDefinition.getCode(), insertVersion, processTaskRelationLogList, taskDefinitionLogs, |
|
|
|
processDefinition.getCode(), insertVersion, processTaskRelationLogList, taskDefinitionLogs, |
|
|
|
Boolean.TRUE); |
|
|
|
Boolean.TRUE); |
|
|
|
Assertions.assertEquals(Constants.EXIT_CODE_SUCCESS, insertResult); |
|
|
|
assertEquals(Constants.EXIT_CODE_SUCCESS, insertResult); |
|
|
|
Assertions.assertDoesNotThrow( |
|
|
|
Assertions.assertDoesNotThrow( |
|
|
|
() -> taskDefinitionService.updateDag(loginUser, processDefinition.getCode(), processTaskRelationList, |
|
|
|
() -> taskDefinitionService.updateDag(loginUser, processDefinition.getCode(), processTaskRelationList, |
|
|
|
taskDefinitionLogs)); |
|
|
|
taskDefinitionLogs)); |
|
|
@ -581,26 +594,30 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
// error task definition not exists
|
|
|
|
// error task definition not exists
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
Assertions.assertEquals(Status.TASK_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
assertEquals(Status.TASK_DEFINE_NOT_EXIST.getCode(), ((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// error task definition not exists
|
|
|
|
// error task definition not exists
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(getTaskDefinition()); |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(getTaskDefinition()); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
Mockito.doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService) |
|
|
|
doThrow(new ServiceException(Status.USER_NO_OPERATION_PROJECT_PERM)).when(projectService) |
|
|
|
.checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION); |
|
|
|
.checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION); |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
Assertions.assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM.getCode(), |
|
|
|
assertEquals(Status.USER_NO_OPERATION_PROJECT_PERM.getCode(), |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
((ServiceException) exception).getCode()); |
|
|
|
|
|
|
|
|
|
|
|
// success
|
|
|
|
// success
|
|
|
|
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION); |
|
|
|
doNothing().when(projectService).checkProjectAndAuthThrowException(user, getProject(), TASK_DEFINITION); |
|
|
|
Assertions.assertDoesNotThrow(() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
Assertions.assertDoesNotThrow(() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdateTaskWithUpstream() { |
|
|
|
public void testUpdateTaskWithUpstream() { |
|
|
|
|
|
|
|
try ( |
|
|
|
|
|
|
|
MockedStatic<TaskPluginManager> taskPluginManagerMockedStatic = |
|
|
|
|
|
|
|
Mockito.mockStatic(TaskPluginManager.class)) { |
|
|
|
|
|
|
|
taskPluginManagerMockedStatic.when(() -> TaskPluginManager.checkTaskParameters(Mockito.any())) |
|
|
|
|
|
|
|
.thenReturn(true); |
|
|
|
String taskDefinitionJson = getTaskDefinitionJson(); |
|
|
|
String taskDefinitionJson = getTaskDefinitionJson(); |
|
|
|
TaskDefinition taskDefinition = getTaskDefinition(); |
|
|
|
TaskDefinition taskDefinition = getTaskDefinition(); |
|
|
|
taskDefinition.setFlag(Flag.NO); |
|
|
|
taskDefinition.setFlag(Flag.NO); |
|
|
@ -608,29 +625,30 @@ public class TaskDefinitionServiceImplTest { |
|
|
|
taskDefinitionSecond.setCode(5); |
|
|
|
taskDefinitionSecond.setCode(5); |
|
|
|
|
|
|
|
|
|
|
|
user.setUserType(UserType.ADMIN_USER); |
|
|
|
user.setUserType(UserType.ADMIN_USER); |
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
Mockito.when(projectService.hasProjectAndWritePerm(user, getProject(), new HashMap<>())).thenReturn(true); |
|
|
|
when(projectService.hasProjectAndWritePerm(user, getProject(), new HashMap<>())).thenReturn(true); |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(taskDefinition); |
|
|
|
when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(taskDefinition); |
|
|
|
Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(1); |
|
|
|
when(taskDefinitionMapper.updateById(Mockito.any())).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionMapper.updateById(Mockito.any())).thenReturn(1); |
|
|
|
when(taskDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); |
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); |
|
|
|
|
|
|
|
|
|
|
|
when(taskDefinitionMapper.queryByCodeList(Mockito.anySet())) |
|
|
|
Mockito.when(taskDefinitionMapper.queryByCodeList(Mockito.anySet())) |
|
|
|
|
|
|
|
.thenReturn(Arrays.asList(taskDefinition, taskDefinitionSecond)); |
|
|
|
.thenReturn(Arrays.asList(taskDefinition, taskDefinitionSecond)); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(processTaskRelationMapper.queryUpstreamByCode(PROJECT_CODE, TASK_CODE)) |
|
|
|
when(processTaskRelationMapper.queryUpstreamByCode(PROJECT_CODE, TASK_CODE)) |
|
|
|
.thenReturn(getProcessTaskRelationListV2()); |
|
|
|
.thenReturn(getProcessTaskRelationListV2()); |
|
|
|
Mockito.when(processDefinitionMapper.queryByCode(PROCESS_DEFINITION_CODE)).thenReturn(getProcessDefinition()); |
|
|
|
when(processDefinitionMapper.queryByCode(PROCESS_DEFINITION_CODE)) |
|
|
|
Mockito.when(processTaskRelationMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
.thenReturn(getProcessDefinition()); |
|
|
|
Mockito.when(processTaskRelationMapper.updateById(Mockito.any())).thenReturn(1); |
|
|
|
when(processTaskRelationMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
Mockito.when(processTaskRelationLogDao.batchInsert(Mockito.anyList())).thenReturn(2); |
|
|
|
when(processTaskRelationMapper.updateById(Mockito.any())).thenReturn(1); |
|
|
|
|
|
|
|
when(processTaskRelationLogDao.batchInsert(Mockito.anyList())).thenReturn(2); |
|
|
|
// success
|
|
|
|
// success
|
|
|
|
Map<String, Object> successMap = taskDefinitionService.updateTaskWithUpstream(user, PROJECT_CODE, TASK_CODE, |
|
|
|
Map<String, Object> successMap = taskDefinitionService.updateTaskWithUpstream(user, PROJECT_CODE, TASK_CODE, |
|
|
|
taskDefinitionJson, UPSTREAM_CODE); |
|
|
|
taskDefinitionJson, UPSTREAM_CODE); |
|
|
|
Assertions.assertEquals(Status.SUCCESS, successMap.get(Constants.STATUS)); |
|
|
|
assertEquals(Status.SUCCESS, successMap.get(Constants.STATUS)); |
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getTaskDefinitionJson() { |
|
|
|
private String getTaskDefinitionJson() { |
|
|
|
return "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
return "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|