|
|
|
@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.service;
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import org.apache.dolphinscheduler.api.ApiApplicationServer; |
|
|
|
|
import org.apache.dolphinscheduler.api.dto.ProcessMeta; |
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
@ -99,7 +100,7 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
"\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryProccessDefinitionList() throws Exception { |
|
|
|
|
public void testQueryProccessDefinitionList() { |
|
|
|
|
String projectName = "project_test1"; |
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
@ -111,15 +112,23 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
|
|
|
|
|
|
//project not found
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map = processDefinitionService.queryProccessDefinitionList(loginUser,"project_test1"); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
logger.info(JSON.toJSONString(map)); |
|
|
|
|
|
|
|
|
|
//project check auth success
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
List<ProcessDefinition> resourceList = new ArrayList<>(); |
|
|
|
|
resourceList.add(getProcessDefinition()); |
|
|
|
|
Mockito.when(processDefineMapper.queryAllDefinitionList(project.getId())).thenReturn(resourceList); |
|
|
|
|
Map<String, Object> checkSuccessRes = processDefinitionService.queryProccessDefinitionList(loginUser,"project_test1"); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryProcessDefinitionListPagingTest() throws Exception { |
|
|
|
|
public void testQueryProcessDefinitionListPaging() { |
|
|
|
|
String projectName = "project_test1"; |
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
@ -132,12 +141,46 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
|
|
|
|
|
|
//project not found
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, "project_test1", "",1, 5,0); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryProccessDefinitionById() { |
|
|
|
|
String projectName = "project_test1"; |
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
|
Project project = getProject(projectName); |
|
|
|
|
|
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.queryProccessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 1); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
logger.info(JSON.toJSONString(map)); |
|
|
|
|
|
|
|
|
|
//project check auth success, instance not exist
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
Mockito.when(processDefineMapper.selectById(1)).thenReturn(null); |
|
|
|
|
Map<String, Object> instanceNotexitRes = processDefinitionService.queryProccessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 1); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//instance exit
|
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition()); |
|
|
|
|
Map<String, Object> successRes = processDefinitionService.queryProccessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -150,14 +193,115 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map = processDefinitionService.deleteProcessDefinitionById(loginUser, "project_test1", 6); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//project check auth success, instance not exist
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
Mockito.when(processDefineMapper.selectById(1)).thenReturn(null); |
|
|
|
|
Map<String, Object> instanceNotexitRes = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 1); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
|
//user no auth
|
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); |
|
|
|
|
Map<String, Object> userNoAuthRes = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, userNoAuthRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//process definition online
|
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
processDefinition.setReleaseState(ReleaseState.ONLINE); |
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); |
|
|
|
|
Map<String, Object> dfOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_STATE_ONLINE, dfOnlineRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//scheduler list elements > 1
|
|
|
|
|
processDefinition.setReleaseState(ReleaseState.OFFLINE); |
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(processDefinition); |
|
|
|
|
List<Schedule> schedules = new ArrayList<>(); |
|
|
|
|
schedules.add(getSchedule()); |
|
|
|
|
schedules.add(getSchedule()); |
|
|
|
|
Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); |
|
|
|
|
Map<String, Object> schedulerGreaterThanOneRes = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, schedulerGreaterThanOneRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//scheduler online
|
|
|
|
|
schedules.clear(); |
|
|
|
|
Schedule schedule = getSchedule(); |
|
|
|
|
schedule.setReleaseState(ReleaseState.ONLINE); |
|
|
|
|
schedules.add(schedule); |
|
|
|
|
Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); |
|
|
|
|
Map<String, Object> schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.SCHEDULE_CRON_STATE_ONLINE, schedulerOnlineRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//delete fail
|
|
|
|
|
schedules.clear(); |
|
|
|
|
schedule.setReleaseState(ReleaseState.OFFLINE); |
|
|
|
|
schedules.add(schedule); |
|
|
|
|
Mockito.when(scheduleMapper.queryByProcessDefinitionId(46)).thenReturn(schedules); |
|
|
|
|
Mockito.when(processDefineMapper.deleteById(46)).thenReturn(0); |
|
|
|
|
Map<String, Object> deleteFail = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR, deleteFail.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//delte success
|
|
|
|
|
Mockito.when(processDefineMapper.deleteById(46)).thenReturn(1); |
|
|
|
|
Map<String, Object> deleteSuccess = processDefinitionService.deleteProcessDefinitionById(loginUser, |
|
|
|
|
"project_test1", 46); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testReleaseProcessDefinition() { |
|
|
|
|
String projectName = "project_test1"; |
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
|
Project project = getProject(projectName); |
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser,project,projectName)).thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", |
|
|
|
|
6, ReleaseState.OFFLINE.getCode()); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS)); |
|
|
|
|
logger.info(JSON.toJSONString(map)); |
|
|
|
|
|
|
|
|
|
//project check auth success, processs definition online
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectName); |
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition()); |
|
|
|
|
Mockito.when(processDefineMapper.updateById(getProcessDefinition())).thenReturn(1); |
|
|
|
|
Map<String, Object> onlineRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", |
|
|
|
|
46, ReleaseState.ONLINE.getCode()); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//process definition offline
|
|
|
|
|
List<Schedule> schedules = new ArrayList<>(); |
|
|
|
|
Schedule schedule = getSchedule(); |
|
|
|
|
schedules.add(schedule); |
|
|
|
|
Mockito.when(scheduleMapper.selectAllByProcessDefineArray(new int[]{46})).thenReturn(schedules); |
|
|
|
|
Mockito.when(scheduleMapper.updateById(schedule)).thenReturn(1); |
|
|
|
|
Map<String, Object> offlineRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", |
|
|
|
|
46, ReleaseState.OFFLINE.getCode()); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, offlineRes.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)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|