From 1f184440caedf8c7691adeb9dc35a089299cdd7d Mon Sep 17 00:00:00 2001 From: zwZjut Date: Fri, 3 Dec 2021 22:01:26 +0800 Subject: [PATCH] [UT#7157]Fix Ut Run Error (#7158) * to #7157 * to #7157 Co-authored-by: honghuo.zw --- .../api/controller/ProcessInstanceControllerTest.java | 7 ++----- .../api/service/ExecutorServiceTest.java | 1 + .../api/service/ProcessInstanceServiceTest.java | 9 +++++++++ .../api/service/SchedulerServiceTest.java | 1 + .../api/service/TaskDefinitionServiceImplTest.java | 9 ++++++--- .../api/service/TaskInstanceServiceTest.java | 8 ++++++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java index b89e6381d8..7bafb59f3f 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceControllerTest.java @@ -190,15 +190,12 @@ public class ProcessInstanceControllerTest extends AbstractControllerTest { public void testViewVariables() throws Exception { Map mockResult = new HashMap<>(); mockResult.put(Constants.STATUS, Status.SUCCESS); - PowerMockito.when(processInstanceService.viewVariables(1L,1)).thenReturn(mockResult); - + PowerMockito.when(processInstanceService.viewVariables(1113L,123)).thenReturn(mockResult); MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/process-instances/{id}/view-variables", "1113", "123") - .header(SESSION_ID, sessionId) - .param("processInstanceId", "1204")) + .header(SESSION_ID, sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); - Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Assert.assertNotNull(result); Assert.assertEquals(Status.SUCCESS.getCode(), result.getCode().intValue()); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java index bb279eabab..da942fbedf 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ExecutorServiceTest.java @@ -122,6 +122,7 @@ public class ExecutorServiceTest { processDefinition.setUserId(userId); processDefinition.setVersion(1); processDefinition.setCode(1L); + processDefinition.setProjectCode(projectCode); // processInstance processInstance.setId(processInstanceId); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java index 4eb6f56734..eba085bf87 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessInstanceServiceTest.java @@ -40,6 +40,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.ProcessDefinitionLog; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; @@ -48,6 +49,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; +import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -111,6 +113,8 @@ public class ProcessInstanceServiceTest { @Mock TenantMapper tenantMapper; + @Mock + TaskDefinitionMapper taskDefinitionMapper; private String shellJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," + "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," @@ -255,6 +259,7 @@ public class ProcessInstanceServiceTest { ProcessInstance processInstance = getProcessInstance(); putMsg(result, Status.SUCCESS, projectCode); ProcessDefinition processDefinition = getProcessDefinition(); + processDefinition.setProjectCode(projectCode); when(projectMapper.queryByCode(projectCode)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); when(processService.findProcessInstanceDetailById(processInstance.getId())).thenReturn(processInstance); @@ -347,6 +352,9 @@ public class ProcessInstanceServiceTest { taskInstance.setProcessInstanceId(1); putMsg(result, Status.SUCCESS, projectCode); when(processService.findTaskInstanceById(1)).thenReturn(taskInstance); + TaskDefinition taskDefinition = new TaskDefinition(); + taskDefinition.setProjectCode(projectCode); + when(taskDefinitionMapper.queryByCode(taskInstance.getTaskCode())).thenReturn(taskDefinition); Map notSubprocessRes = processInstanceService.querySubProcessInstanceByTaskId(loginUser, projectCode, 1); Assert.assertEquals(Status.TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE, notSubprocessRes.get(Constants.STATUS)); @@ -410,6 +418,7 @@ public class ProcessInstanceServiceTest { ProcessDefinition processDefinition = getProcessDefinition(); processDefinition.setId(1); processDefinition.setUserId(1); + processDefinition.setProjectCode(projectCode); Tenant tenant = getTenant(); when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); when(tenantMapper.queryByTenantCode("root")).thenReturn(tenant); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java index c4e00a1200..d2a83b9f46 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/SchedulerServiceTest.java @@ -107,6 +107,7 @@ public class SchedulerServiceTest { Project project = getProject(projectName, projectCode); ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setProjectCode(projectCode); Schedule schedule = new Schedule(); schedule.setId(1); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java index 94f2ad5889..315f11c326 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java @@ -207,9 +207,10 @@ public class TaskDefinitionServiceImplTest { Mockito.when(taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version)) .thenReturn(new TaskDefinitionLog()); - + TaskDefinition taskDefinition = new TaskDefinition(); + taskDefinition.setProjectCode(projectCode); Mockito.when(taskDefinitionMapper.queryByCode(taskCode)) - .thenReturn(new TaskDefinition()); + .thenReturn(taskDefinition); Mockito.when(taskDefinitionMapper.updateById(new TaskDefinitionLog())).thenReturn(1); Map relation = taskDefinitionService .switchVersion(loginUser, projectCode, taskCode, version); @@ -306,7 +307,9 @@ public class TaskDefinitionServiceImplTest { // process definition offline putMsg(result, Status.SUCCESS); - Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(new TaskDefinition()); + TaskDefinition taskDefinition = new TaskDefinition(); + taskDefinition.setProjectCode(projectCode); + Mockito.when(taskDefinitionMapper.queryByCode(taskCode)).thenReturn(taskDefinition); Map offlineTaskResult = taskDefinitionService.releaseTaskDefinition(loginUser, projectCode, taskCode, ReleaseState.OFFLINE); Assert.assertEquals(Status.SUCCESS, offlineTaskResult.get(Constants.STATUS)); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java index 08fdf5fe51..5544a18ee0 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskInstanceServiceTest.java @@ -32,9 +32,11 @@ import org.apache.dolphinscheduler.common.enums.UserType; import org.apache.dolphinscheduler.common.utils.DateUtils; import org.apache.dolphinscheduler.dao.entity.ProcessInstance; import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskInstance; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; +import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.service.process.ProcessService; @@ -81,6 +83,9 @@ public class TaskInstanceServiceTest { @Mock UsersService usersService; + @Mock + TaskDefinitionMapper taskDefinitionMapper; + @Test public void queryTaskListPaging() { long projectCode = 1L; @@ -249,6 +254,9 @@ public class TaskInstanceServiceTest { // test task not found when(projectService.checkProjectAndAuth(user, project, projectCode)).thenReturn(mockSuccess); when(taskInstanceMapper.selectById(Mockito.anyInt())).thenReturn(null); + TaskDefinition taskDefinition = new TaskDefinition(); + taskDefinition.setProjectCode(projectCode); + when(taskDefinitionMapper.queryByCode(task.getTaskCode())).thenReturn(taskDefinition); Map taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND, taskNotFoundRes.get(Constants.STATUS));