|
|
@ -82,29 +82,29 @@ public class TaskInstanceServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void queryTaskListPaging() { |
|
|
|
public void queryTaskListPaging() { |
|
|
|
String projectName = "project_test1"; |
|
|
|
long projectCode = 1L; |
|
|
|
User loginUser = getAdminUser(); |
|
|
|
User loginUser = getAdminUser(); |
|
|
|
|
|
|
|
Project project = getProject(projectCode); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode); |
|
|
|
|
|
|
|
|
|
|
|
//project auth fail
|
|
|
|
//project auth fail
|
|
|
|
when(projectMapper.queryByName(projectName)).thenReturn(null); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, "project_test1")).thenReturn(result); |
|
|
|
Map<String, Object> proejctAuthFailRes = taskInstanceService.queryTaskListPaging(loginUser, "project_test1", 0, "", "", |
|
|
|
Map<String, Object> projectAuthFailRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 0, "", "", |
|
|
|
"test_user", "2019-02-26 19:48:00", "2019-02-26 19:48:22", "", null, "", 1, 20); |
|
|
|
"test_user", "2019-02-26 19:48:00", "2019-02-26 19:48:22", "", null, "", 1, 20); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, proejctAuthFailRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, projectAuthFailRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// data parameter check
|
|
|
|
// data parameter check
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
Project project = getProject(projectName); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectMapper.queryByName(Mockito.anyString())).thenReturn(project); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
Map<String, Object> dataParameterRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
Map<String, Object> dataParameterRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
|
|
|
|
"test_user", "20200101 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"test_user", "20200101 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, dataParameterRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, dataParameterRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//project
|
|
|
|
//project
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00"); |
|
|
|
Date start = DateUtils.getScheduleDate("2020-01-01 00:00:00"); |
|
|
|
Date end = DateUtils.getScheduleDate("2020-01-02 00:00:00"); |
|
|
|
Date end = DateUtils.getScheduleDate("2020-01-02 00:00:00"); |
|
|
|
ProcessInstance processInstance = getProcessInstance(); |
|
|
|
ProcessInstance processInstance = getProcessInstance(); |
|
|
@ -113,8 +113,8 @@ public class TaskInstanceServiceTest { |
|
|
|
Page<TaskInstance> pageReturn = new Page<>(1, 10); |
|
|
|
Page<TaskInstance> pageReturn = new Page<>(1, 10); |
|
|
|
taskInstanceList.add(taskInstance); |
|
|
|
taskInstanceList.add(taskInstance); |
|
|
|
pageReturn.setRecords(taskInstanceList); |
|
|
|
pageReturn.setRecords(taskInstanceList); |
|
|
|
when(projectMapper.queryByName(Mockito.anyString())).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); |
|
|
|
when(projectService.checkProjectAndAuth(loginUser, project, project.getName())).thenReturn(result); |
|
|
|
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); |
|
|
|
when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); |
|
|
|
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); |
|
|
|
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); |
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
@ -122,38 +122,38 @@ public class TaskInstanceServiceTest { |
|
|
|
when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); |
|
|
|
when(usersService.queryUser(processInstance.getExecutorId())).thenReturn(loginUser); |
|
|
|
when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())).thenReturn(processInstance); |
|
|
|
when(processService.findProcessInstanceDetailById(taskInstance.getProcessInstanceId())).thenReturn(processInstance); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> successRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
Map<String, Object> successRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
"test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//executor name empty
|
|
|
|
//executor name empty
|
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); |
|
|
|
eq(0), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); |
|
|
|
Map<String, Object> executorEmptyRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
Map<String, Object> executorEmptyRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
"", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.SUCCESS, executorEmptyRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, executorEmptyRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//executor null
|
|
|
|
//executor null
|
|
|
|
when(usersService.queryUser(loginUser.getId())).thenReturn(null); |
|
|
|
when(usersService.queryUser(loginUser.getId())).thenReturn(null); |
|
|
|
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1); |
|
|
|
when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(-1); |
|
|
|
Map<String, Object> executorNullRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
Map<String, Object> executorNullRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
"test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"test_user", "2020-01-01 00:00:00", "2020-01-02 00:00:00", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.SUCCESS, executorNullRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, executorNullRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//start/end date null
|
|
|
|
//start/end date null
|
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); |
|
|
|
eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); |
|
|
|
Map<String, Object> executorNullDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
Map<String, Object> executorNullDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
"", null, null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"", null, null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.SUCCESS, executorNullDateRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, executorNullDateRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
//start date error format
|
|
|
|
//start date error format
|
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
when(taskInstanceMapper.queryTaskInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1), eq(""), eq(""), eq(""), |
|
|
|
eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); |
|
|
|
eq(0), Mockito.any(), eq("192.168.xx.xx"), any(), any())).thenReturn(pageReturn); |
|
|
|
Map<String, Object> executorErrorStartDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
Map<String, Object> executorErrorStartDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
"", "error date", null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"", "error date", null, "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, executorErrorStartDateRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, executorErrorStartDateRes.get(Constants.STATUS)); |
|
|
|
Map<String, Object> executorErrorEndDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectName, 1, "", "", |
|
|
|
Map<String, Object> executorErrorEndDateRes = taskInstanceService.queryTaskListPaging(loginUser, projectCode, 1, "", "", |
|
|
|
"", null, "error date", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
"", null, "error date", "", ExecutionStatus.SUCCESS, "192.168.xx.xx", 1, 20); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, executorErrorEndDateRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, executorErrorEndDateRes.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
@ -174,14 +174,14 @@ public class TaskInstanceServiceTest { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* get mock Project |
|
|
|
* get mock Project |
|
|
|
* |
|
|
|
* |
|
|
|
* @param projectName projectName |
|
|
|
* @param projectCode projectCode |
|
|
|
* @return Project |
|
|
|
* @return Project |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Project getProject(String projectName) { |
|
|
|
private Project getProject(long projectCode) { |
|
|
|
Project project = new Project(); |
|
|
|
Project project = new Project(); |
|
|
|
project.setCode(1L); |
|
|
|
project.setCode(projectCode); |
|
|
|
project.setId(1); |
|
|
|
project.setId(1); |
|
|
|
project.setName(projectName); |
|
|
|
project.setName("project_test1"); |
|
|
|
project.setUserId(1); |
|
|
|
project.setUserId(1); |
|
|
|
return project; |
|
|
|
return project; |
|
|
|
} |
|
|
|
} |
|
|
@ -228,44 +228,54 @@ public class TaskInstanceServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void forceTaskSuccess() { |
|
|
|
public void forceTaskSuccess() { |
|
|
|
User user = getAdminUser(); |
|
|
|
User user = getAdminUser(); |
|
|
|
String projectName = "test"; |
|
|
|
long projectCode = 1L; |
|
|
|
Project project = getProject(projectName); |
|
|
|
Project project = getProject(projectCode); |
|
|
|
int taskId = 1; |
|
|
|
int taskId = 1; |
|
|
|
TaskInstance task = getTaskInstance(); |
|
|
|
TaskInstance task = getTaskInstance(); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> mockSuccess = new HashMap<>(5); |
|
|
|
Map<String, Object> mockSuccess = new HashMap<>(5); |
|
|
|
putMsg(mockSuccess, Status.SUCCESS); |
|
|
|
putMsg(mockSuccess, Status.SUCCESS); |
|
|
|
when(projectMapper.queryByName(projectName)).thenReturn(project); |
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
|
|
|
|
|
|
|
// user auth failed
|
|
|
|
// user auth failed
|
|
|
|
Map<String, Object> mockFailure = new HashMap<>(5); |
|
|
|
Map<String, Object> mockFailure = new HashMap<>(5); |
|
|
|
putMsg(mockFailure, Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectName); |
|
|
|
putMsg(mockFailure, Status.USER_NO_OPERATION_PROJECT_PERM, user.getUserName(), projectCode); |
|
|
|
when(projectService.checkProjectAndAuth(user, project, projectName)).thenReturn(mockFailure); |
|
|
|
when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(mockFailure); |
|
|
|
Map<String, Object> authFailRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); |
|
|
|
Map<String, Object> authFailRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); |
|
|
|
Assert.assertNotSame(Status.SUCCESS, authFailRes.get(Constants.STATUS)); |
|
|
|
Assert.assertNotSame(Status.SUCCESS, authFailRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// test task not found
|
|
|
|
// test task not found
|
|
|
|
when(projectService.checkProjectAndAuth(user, project, projectName)).thenReturn(mockSuccess); |
|
|
|
when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(mockSuccess); |
|
|
|
when(taskInstanceMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
when(taskInstanceMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
Map<String, Object> taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); |
|
|
|
Map<String, Object> taskNotFoundRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); |
|
|
|
Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND, taskNotFoundRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND, taskNotFoundRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// test task instance state error
|
|
|
|
// test task instance state error
|
|
|
|
task.setState(ExecutionStatus.SUCCESS); |
|
|
|
task.setState(ExecutionStatus.SUCCESS); |
|
|
|
when(taskInstanceMapper.selectById(1)).thenReturn(task); |
|
|
|
when(taskInstanceMapper.selectById(1)).thenReturn(task); |
|
|
|
Map<String, Object> taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
|
|
|
when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(result); |
|
|
|
|
|
|
|
Map<String, Object> taskStateErrorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); |
|
|
|
Assert.assertEquals(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskStateErrorRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.TASK_INSTANCE_STATE_OPERATION_ERROR, taskStateErrorRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// test error
|
|
|
|
// test error
|
|
|
|
task.setState(ExecutionStatus.FAILURE); |
|
|
|
task.setState(ExecutionStatus.FAILURE); |
|
|
|
when(taskInstanceMapper.updateById(task)).thenReturn(0); |
|
|
|
when(taskInstanceMapper.updateById(task)).thenReturn(0); |
|
|
|
Map<String, Object> errorRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
|
|
|
when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(result); |
|
|
|
|
|
|
|
Map<String, Object> errorRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); |
|
|
|
Assert.assertEquals(Status.FORCE_TASK_SUCCESS_ERROR, errorRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.FORCE_TASK_SUCCESS_ERROR, errorRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
// test success
|
|
|
|
// test success
|
|
|
|
task.setState(ExecutionStatus.FAILURE); |
|
|
|
task.setState(ExecutionStatus.FAILURE); |
|
|
|
when(taskInstanceMapper.updateById(task)).thenReturn(1); |
|
|
|
when(taskInstanceMapper.updateById(task)).thenReturn(1); |
|
|
|
Map<String, Object> successRes = taskInstanceService.forceTaskSuccess(user, projectName, taskId); |
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
|
|
|
when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
|
|
|
when(projectService.checkProjectAndAuth(user, project, project.getName())).thenReturn(result); |
|
|
|
|
|
|
|
Map<String, Object> successRes = taskInstanceService.forceTaskSuccess(user, projectCode, taskId); |
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |