|
|
|
@ -25,14 +25,13 @@ import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationCon
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_IMPORT; |
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_TREE_VIEW; |
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.WORKFLOW_UPDATE; |
|
|
|
|
|
|
|
|
|
import static org.powermock.api.mockito.PowerMockito.mock; |
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
import org.apache.dolphinscheduler.api.exceptions.ServiceException; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.ProcessDefinitionServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.FailureStrategy; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.Priority; |
|
|
|
@ -59,6 +58,8 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.model.PageListingResult; |
|
|
|
|
import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao; |
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
import org.apache.dolphinscheduler.spi.enums.DbType; |
|
|
|
|
|
|
|
|
@ -92,8 +93,6 @@ import org.mockito.Mockito;
|
|
|
|
|
import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.google.common.collect.ImmutableSet; |
|
|
|
|
import com.google.common.collect.Lists; |
|
|
|
|
|
|
|
|
@ -103,17 +102,19 @@ import com.google.common.collect.Lists;
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
|
public class ProcessDefinitionServiceTest { |
|
|
|
|
|
|
|
|
|
private static final String taskRelationJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," |
|
|
|
|
+ "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," |
|
|
|
|
+ "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; |
|
|
|
|
private static final String taskRelationJson = |
|
|
|
|
"[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," |
|
|
|
|
+ "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," |
|
|
|
|
+ "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; |
|
|
|
|
|
|
|
|
|
private static final String taskDefinitionJson = "[{\"code\":123456789,\"name\":\"test1\",\"version\":1,\"description\":\"\",\"delayTime\":0,\"taskType\":\"SHELL\"," |
|
|
|
|
+ "\"taskParams\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"dependence\":{},\"conditionResult\":{\"successNode\":[],\"failedNode\":[]},\"waitStartTimeout\":{}," |
|
|
|
|
+ "\"switchResult\":{}},\"flag\":\"YES\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":1,\"timeoutFlag\":\"CLOSE\"," |
|
|
|
|
+ "\"timeoutNotifyStrategy\":null,\"timeout\":0,\"environmentCode\":-1},{\"code\":123451234,\"name\":\"test2\",\"version\":1,\"description\":\"\",\"delayTime\":0,\"taskType\":\"SHELL\"," |
|
|
|
|
+ "\"taskParams\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 2\",\"dependence\":{},\"conditionResult\":{\"successNode\":[],\"failedNode\":[]},\"waitStartTimeout\":{}," |
|
|
|
|
+ "\"switchResult\":{}},\"flag\":\"YES\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":1,\"timeoutFlag\":\"CLOSE\"," |
|
|
|
|
+ "\"timeoutNotifyStrategy\":\"WARN\",\"timeout\":0,\"environmentCode\":-1}]"; |
|
|
|
|
private static final String taskDefinitionJson = |
|
|
|
|
"[{\"code\":123456789,\"name\":\"test1\",\"version\":1,\"description\":\"\",\"delayTime\":0,\"taskType\":\"SHELL\"," |
|
|
|
|
+ "\"taskParams\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"dependence\":{},\"conditionResult\":{\"successNode\":[],\"failedNode\":[]},\"waitStartTimeout\":{}," |
|
|
|
|
+ "\"switchResult\":{}},\"flag\":\"YES\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":1,\"timeoutFlag\":\"CLOSE\"," |
|
|
|
|
+ "\"timeoutNotifyStrategy\":null,\"timeout\":0,\"environmentCode\":-1},{\"code\":123451234,\"name\":\"test2\",\"version\":1,\"description\":\"\",\"delayTime\":0,\"taskType\":\"SHELL\"," |
|
|
|
|
+ "\"taskParams\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 2\",\"dependence\":{},\"conditionResult\":{\"successNode\":[],\"failedNode\":[]},\"waitStartTimeout\":{}," |
|
|
|
|
+ "\"switchResult\":{}},\"flag\":\"YES\",\"taskPriority\":\"MEDIUM\",\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":1,\"timeoutFlag\":\"CLOSE\"," |
|
|
|
|
+ "\"timeoutNotifyStrategy\":\"WARN\",\"timeout\":0,\"environmentCode\":-1}]"; |
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
|
private ProcessDefinitionServiceImpl processDefinitionService; |
|
|
|
@ -121,6 +122,9 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
@Mock |
|
|
|
|
private ProcessDefinitionMapper processDefineMapper; |
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
private ProcessDefinitionDao processDefinitionDao; |
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
private ProcessTaskRelationMapper processTaskRelationMapper; |
|
|
|
|
|
|
|
|
@ -133,6 +137,9 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
@Mock |
|
|
|
|
private ScheduleMapper scheduleMapper; |
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
private SchedulerService schedulerService; |
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
private ProcessService processService; |
|
|
|
|
|
|
|
|
@ -161,18 +168,21 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
|
|
|
|
|
//project not found
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
// project not found
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//project check auth success
|
|
|
|
|
// project check auth success
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
List<ProcessDefinition> resourceList = new ArrayList<>(); |
|
|
|
|
resourceList.add(getProcessDefinition()); |
|
|
|
|
Mockito.when(processDefineMapper.queryAllDefinitionList(project.getCode())).thenReturn(resourceList); |
|
|
|
|
Map<String, Object> checkSuccessRes = processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); |
|
|
|
|
Map<String, Object> checkSuccessRes = |
|
|
|
|
processDefinitionService.queryProcessDefinitionList(loginUser, projectCode); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, checkSuccessRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -180,38 +190,45 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
public void testQueryProcessDefinitionListPaging() { |
|
|
|
|
long projectCode = 1L; |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
|
|
|
|
|
|
|
|
|
Project project = getProject(projectCode); |
|
|
|
|
|
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
|
|
|
|
|
//project not found
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Result map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, "", "", 1, 5, 0); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND.getCode(), (int) map.getCode()); |
|
|
|
|
// project not found
|
|
|
|
|
try { |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(null); |
|
|
|
|
Mockito.doThrow(new ServiceException(Status.PROJECT_NOT_EXIST)).when(projectService) |
|
|
|
|
.checkProjectAndAuthThrowException(loginUser, null, WORKFLOW_DEFINITION); |
|
|
|
|
processDefinitionService.queryProcessDefinitionListPaging(loginUser, projectCode, "", "", 1, 5, 0); |
|
|
|
|
} catch (ServiceException serviceException) { |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_EXIST.getCode(), serviceException.getCode().intValue()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
loginUser.setId(1); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Page<ProcessDefinition> page = new Page<>(1, 10); |
|
|
|
|
page.setTotal(30); |
|
|
|
|
Mockito.when(processDefineMapper.queryDefineListPaging( |
|
|
|
|
Mockito.any(IPage.class) |
|
|
|
|
, Mockito.eq("") |
|
|
|
|
, Mockito.eq(loginUser.getId()) |
|
|
|
|
, Mockito.eq(project.getCode()) |
|
|
|
|
, Mockito.anyBoolean())).thenReturn(page); |
|
|
|
|
|
|
|
|
|
Result map1 = processDefinitionService.queryProcessDefinitionListPaging( |
|
|
|
|
loginUser, 1L, "", "",1, 10, loginUser.getId()); |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), map1.getMsg()); |
|
|
|
|
Mockito.doNothing().when(projectService).checkProjectAndAuthThrowException(loginUser, project, |
|
|
|
|
WORKFLOW_DEFINITION); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
PageListingResult<ProcessDefinition> pageListingResult = PageListingResult.<ProcessDefinition>builder() |
|
|
|
|
.records(Collections.emptyList()) |
|
|
|
|
.currentPage(1) |
|
|
|
|
.pageSize(10) |
|
|
|
|
.totalCount(30) |
|
|
|
|
.build(); |
|
|
|
|
Mockito.when(processDefinitionDao.listingProcessDefinition( |
|
|
|
|
Mockito.eq(0), |
|
|
|
|
Mockito.eq(10), |
|
|
|
|
Mockito.eq(""), |
|
|
|
|
Mockito.eq(1), |
|
|
|
|
Mockito.eq(project.getCode()))).thenReturn(pageListingResult); |
|
|
|
|
|
|
|
|
|
PageInfo<ProcessDefinition> pageInfo = processDefinitionService.queryProcessDefinitionListPaging( |
|
|
|
|
loginUser, project.getCode(), "", "", 1, 0, 10); |
|
|
|
|
|
|
|
|
|
Assert.assertNotNull(pageInfo); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -230,26 +247,31 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
// project check auth fail
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.queryProcessDefinitionByCode(loginUser, 1L, 1L); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//project check auth success, instance not exist
|
|
|
|
|
// project check auth success, instance not exist
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
DagData dagData = new DagData(getProcessDefinition(), null, null); |
|
|
|
|
Mockito.when(processService.genDagData(Mockito.any())).thenReturn(dagData); |
|
|
|
|
|
|
|
|
|
Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 1L); |
|
|
|
|
Map<String, Object> instanceNotexitRes = |
|
|
|
|
processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 1L); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//instance exit
|
|
|
|
|
// instance exit
|
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(getProcessDefinition()); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(tenant); |
|
|
|
|
Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Map<String, Object> successRes = |
|
|
|
|
processDefinitionService.queryProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -267,24 +289,31 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); |
|
|
|
|
// project check auth fail
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> map = |
|
|
|
|
processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//project check auth success, instance not exist
|
|
|
|
|
// project check auth success, instance not exist
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test_def")).thenReturn(null); |
|
|
|
|
|
|
|
|
|
Map<String, Object> instanceNotExitRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); |
|
|
|
|
Map<String, Object> instanceNotExitRes = |
|
|
|
|
processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test_def"); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//instance exit
|
|
|
|
|
Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test")).thenReturn(getProcessDefinition()); |
|
|
|
|
// instance exit
|
|
|
|
|
Mockito.when(processDefineMapper.queryByDefineName(project.getCode(), "test")) |
|
|
|
|
.thenReturn(getProcessDefinition()); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test"); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> successRes = |
|
|
|
|
processDefinitionService.queryProcessDefinitionByName(loginUser, projectCode, "test"); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -298,15 +327,18 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_BATCH_COPY)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_BATCH_COPY)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
|
|
|
|
|
// copy project definition ids empty test
|
|
|
|
|
Map<String, Object> map = processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, StringUtils.EMPTY, 2L); |
|
|
|
|
Map<String, Object> map = |
|
|
|
|
processDefinitionService.batchCopyProcessDefinition(loginUser, projectCode, StringUtils.EMPTY, 2L); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINITION_CODES_IS_EMPTY, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
// project check auth fail
|
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_BATCH_COPY)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_BATCH_COPY)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> map1 = processDefinitionService.batchCopyProcessDefinition( |
|
|
|
|
loginUser, projectCode, String.valueOf(project.getId()), 2L); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map1.get(Constants.STATUS)); |
|
|
|
@ -315,13 +347,15 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
projectCode = 2L; |
|
|
|
|
Project project1 = getProject(projectCode); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project1); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_BATCH_COPY)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_BATCH_COPY)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
|
processDefinitionList.add(definition); |
|
|
|
|
Set<Long> definitionCodes = Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); |
|
|
|
|
Set<Long> definitionCodes = |
|
|
|
|
Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); |
|
|
|
|
Mockito.when(processService.saveProcessDefine(loginUser, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); |
|
|
|
|
Map<String, Object> map3 = processDefinitionService.batchCopyProcessDefinition( |
|
|
|
@ -346,17 +380,21 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode, TASK_DEFINITION_MOVE)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectCode2, TASK_DEFINITION_MOVE)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode, TASK_DEFINITION_MOVE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project2, projectCode2, TASK_DEFINITION_MOVE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
|
|
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
|
definition.setVersion(1); |
|
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
|
processDefinitionList.add(definition); |
|
|
|
|
Set<Long> definitionCodes = Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); |
|
|
|
|
Set<Long> definitionCodes = |
|
|
|
|
Arrays.stream("46".split(Constants.COMMA)).map(Long::parseLong).collect(Collectors.toSet()); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCodes(definitionCodes)).thenReturn(processDefinitionList); |
|
|
|
|
Mockito.when(processService.saveProcessDefine(loginUser, definition, Boolean.TRUE, Boolean.TRUE)).thenReturn(2); |
|
|
|
|
Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, 46L)).thenReturn(getProcessTaskRelation(projectCode)); |
|
|
|
|
Mockito.when(processTaskRelationMapper.queryByProcessCode(projectCode, 46L)) |
|
|
|
|
.thenReturn(getProcessTaskRelation(projectCode)); |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
|
|
|
|
|
Map<String, Object> successRes = processDefinitionService.batchMoveProcessDefinition( |
|
|
|
@ -374,77 +412,95 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
// project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION_DELETE)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION_DELETE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 6L); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//project check auth success, instance not exist
|
|
|
|
|
// project check auth success, instance not exist
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION_DELETE)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION_DELETE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(1L)).thenReturn(null); |
|
|
|
|
Map<String, Object> instanceNotExitRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 1L); |
|
|
|
|
Map<String, Object> instanceNotExitRes = |
|
|
|
|
processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 1L); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, instanceNotExitRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION_DELETE)).thenReturn(result); |
|
|
|
|
//user no auth
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION_DELETE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
// user no auth
|
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
|
Map<String, Object> userNoAuthRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Map<String, Object> userNoAuthRes = |
|
|
|
|
processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM, userNoAuthRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//process definition online
|
|
|
|
|
// process definition online
|
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
processDefinition.setReleaseState(ReleaseState.ONLINE); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
|
Throwable exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L)); |
|
|
|
|
String formatter = MessageFormat.format(Status.PROCESS_DEFINE_STATE_ONLINE.getMsg(), processDefinition.getName()); |
|
|
|
|
Throwable exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
() -> processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L)); |
|
|
|
|
String formatter = |
|
|
|
|
MessageFormat.format(Status.PROCESS_DEFINE_STATE_ONLINE.getMsg(), processDefinition.getName()); |
|
|
|
|
Assertions.assertEquals(formatter, exception.getMessage()); |
|
|
|
|
|
|
|
|
|
//scheduler list elements > 1
|
|
|
|
|
// scheduler list elements > 1
|
|
|
|
|
processDefinition.setReleaseState(ReleaseState.OFFLINE); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); |
|
|
|
|
Mockito.when(scheduleMapper.deleteById(46)).thenReturn(1); |
|
|
|
|
Mockito.when(processDefineMapper.deleteById(processDefinition.getId())).thenReturn(1); |
|
|
|
|
Mockito.when(processTaskRelationMapper.deleteByCode(project.getCode(), processDefinition.getCode())).thenReturn(1); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())).thenReturn(Collections.emptySet()); |
|
|
|
|
Map<String, Object> schedulerGreaterThanOneRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Mockito.when(processTaskRelationMapper.deleteByCode(project.getCode(), processDefinition.getCode())) |
|
|
|
|
.thenReturn(1); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) |
|
|
|
|
.thenReturn(Collections.emptySet()); |
|
|
|
|
Map<String, Object> schedulerGreaterThanOneRes = |
|
|
|
|
processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, schedulerGreaterThanOneRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//scheduler online
|
|
|
|
|
// scheduler online
|
|
|
|
|
Schedule schedule = getSchedule(); |
|
|
|
|
schedule.setReleaseState(ReleaseState.ONLINE); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(schedule); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())).thenReturn(Collections.emptySet()); |
|
|
|
|
Map<String, Object> schedulerOnlineRes = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) |
|
|
|
|
.thenReturn(Collections.emptySet()); |
|
|
|
|
Map<String, Object> schedulerOnlineRes = |
|
|
|
|
processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.SCHEDULE_CRON_STATE_ONLINE, schedulerOnlineRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//process used by other task, sub process
|
|
|
|
|
// process used by other task, sub process
|
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
TaskMainInfo taskMainInfo = getTaskMainInfo().get(0); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())).thenReturn(ImmutableSet.copyOf(getTaskMainInfo())); |
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, () -> processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L)); |
|
|
|
|
formatter = MessageFormat.format(Status.DELETE_PROCESS_DEFINITION_USE_BY_OTHER_FAIL.getMsg(), String.format("%s:%s", taskMainInfo.getProcessDefinitionName(), taskMainInfo.getTaskName())); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) |
|
|
|
|
.thenReturn(ImmutableSet.copyOf(getTaskMainInfo())); |
|
|
|
|
exception = Assertions.assertThrows(ServiceException.class, |
|
|
|
|
() -> processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L)); |
|
|
|
|
formatter = MessageFormat.format(Status.DELETE_PROCESS_DEFINITION_USE_BY_OTHER_FAIL.getMsg(), |
|
|
|
|
String.format("%s:%s", taskMainInfo.getProcessDefinitionName(), taskMainInfo.getTaskName())); |
|
|
|
|
Assertions.assertEquals(formatter, exception.getMessage()); |
|
|
|
|
|
|
|
|
|
//delete success
|
|
|
|
|
// delete success
|
|
|
|
|
schedule.setReleaseState(ReleaseState.OFFLINE); |
|
|
|
|
Mockito.when(processDefineMapper.deleteById(46)).thenReturn(1); |
|
|
|
|
Mockito.when(scheduleMapper.deleteById(schedule.getId())).thenReturn(1); |
|
|
|
|
Mockito.when(processTaskRelationMapper.deleteByCode(project.getCode(), processDefinition.getCode())).thenReturn(1); |
|
|
|
|
Mockito.when(processTaskRelationMapper.deleteByCode(project.getCode(), processDefinition.getCode())) |
|
|
|
|
.thenReturn(1); |
|
|
|
|
Mockito.when(scheduleMapper.queryByProcessDefinitionCode(46L)).thenReturn(getSchedule()); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())).thenReturn(Collections.emptySet()); |
|
|
|
|
Mockito.when(workFlowLineageService.queryTaskDepOnProcess(project.getCode(), processDefinition.getCode())) |
|
|
|
|
.thenReturn(Collections.emptySet()); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Map<String, Object> deleteSuccess = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Map<String, Object> deleteSuccess = |
|
|
|
|
processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, deleteSuccess.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -459,10 +515,10 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
// project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,null)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, null)).thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.releaseProcessDefinition(loginUser, projectCode, |
|
|
|
|
6, ReleaseState.OFFLINE); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); |
|
|
|
@ -503,23 +559,25 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
// project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.PROJECT_NOT_FOUND, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_CREATE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser, |
|
|
|
|
projectCode, "test_pdf", 0); |
|
|
|
|
Assert.assertEquals(Status.PROJECT_NOT_FOUND, map.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//project check auth success, process not exist
|
|
|
|
|
// project check auth success, process not exist
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(null); |
|
|
|
|
Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, |
|
|
|
|
projectCode, "test_pdf", 0); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//process exist
|
|
|
|
|
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")).thenReturn(getProcessDefinition()); |
|
|
|
|
// process exist
|
|
|
|
|
Mockito.when(processDefineMapper.verifyByDefineName(project.getCode(), "test_pdf")) |
|
|
|
|
.thenReturn(getProcessDefinition()); |
|
|
|
|
Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, |
|
|
|
|
projectCode, "test_pdf", 0); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINITION_NAME_EXIST, processExistRes.get(Constants.STATUS)); |
|
|
|
@ -532,7 +590,8 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
|
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); |
|
|
|
|
|
|
|
|
|
Map<String, Object> taskEmptyRes = processDefinitionService.checkProcessNodeList(taskRelationJson, taskDefinitionLogs); |
|
|
|
|
Map<String, Object> taskEmptyRes = |
|
|
|
|
processDefinitionService.checkProcessNodeList(taskRelationJson, taskDefinitionLogs); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DAG_IS_EMPTY, taskEmptyRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -546,21 +605,23 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
// project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,null)).thenReturn(result); |
|
|
|
|
//process definition not exist
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, null)).thenReturn(result); |
|
|
|
|
// process definition not exist
|
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(null); |
|
|
|
|
Map<String, Object> processDefinitionNullRes = processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); |
|
|
|
|
Map<String, Object> processDefinitionNullRes = |
|
|
|
|
processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//success
|
|
|
|
|
// success
|
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(processService.genDagData(Mockito.any())).thenReturn(new DagData(processDefinition, null, null)); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
|
Map<String, Object> dataNotValidRes = processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); |
|
|
|
|
Map<String, Object> dataNotValidRes = |
|
|
|
|
processDefinitionService.getTaskNodeListByDefinitionCode(loginUser, projectCode, 46L); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, dataNotValidRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -574,15 +635,17 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
|
|
//project check auth fail
|
|
|
|
|
// project check auth fail
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,null)).thenReturn(result); |
|
|
|
|
//process definition not exist
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, null)).thenReturn(result); |
|
|
|
|
// process definition not exist
|
|
|
|
|
String defineCodes = "46"; |
|
|
|
|
Set<Long> defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong).collect(Collectors.toSet()); |
|
|
|
|
Set<Long> defineCodeSet = Lists.newArrayList(defineCodes.split(Constants.COMMA)).stream().map(Long::parseLong) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCodes(defineCodeSet)).thenReturn(null); |
|
|
|
|
Map<String, Object> processNotExistRes = processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, defineCodes); |
|
|
|
|
Map<String, Object> processNotExistRes = |
|
|
|
|
processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, defineCodes); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processNotExistRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
@ -597,7 +660,8 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
projects.add(project1); |
|
|
|
|
Mockito.when(projectMapper.queryProjectCreatedAndAuthorizedByUserId(loginUser.getId())).thenReturn(projects); |
|
|
|
|
|
|
|
|
|
Map<String, Object> successRes = processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, defineCodes); |
|
|
|
|
Map<String, Object> successRes = |
|
|
|
|
processDefinitionService.getNodeListMapByDefinitionCodes(loginUser, projectCode, defineCodes); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -611,12 +675,14 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Project project = getProject(projectCode); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode,WORKFLOW_DEFINITION)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_DEFINITION)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
|
List<ProcessDefinition> processDefinitionList = new ArrayList<>(); |
|
|
|
|
processDefinitionList.add(processDefinition); |
|
|
|
|
Mockito.when(processDefineMapper.queryAllDefinitionList(projectCode)).thenReturn(processDefinitionList); |
|
|
|
|
Map<String, Object> successRes = processDefinitionService.queryAllProcessDefinitionByProjectCode(loginUser, projectCode); |
|
|
|
|
Map<String, Object> successRes = |
|
|
|
|
processDefinitionService.queryAllProcessDefinitionByProjectCode(loginUser, projectCode); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -626,28 +692,32 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
loginUser.setId(1); |
|
|
|
|
loginUser.setTenantId(1); |
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
long projectCode = 1; |
|
|
|
|
long projectCode = 1; |
|
|
|
|
Project project1 = getProject(projectCode); |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode, WORKFLOW_TREE_VIEW)).thenReturn(result); |
|
|
|
|
//process definition not exist
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode, WORKFLOW_TREE_VIEW)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
// process definition not exist
|
|
|
|
|
ProcessDefinition processDefinition = getProcessDefinition(); |
|
|
|
|
Map<String, Object> processDefinitionNullRes = processDefinitionService.viewTree(loginUser,processDefinition.getProjectCode(),46, 10); |
|
|
|
|
Map<String, Object> processDefinitionNullRes = |
|
|
|
|
processDefinitionService.viewTree(loginUser, processDefinition.getProjectCode(), 46, 10); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_DEFINE_NOT_EXIST, processDefinitionNullRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//task instance not existproject
|
|
|
|
|
// task instance not existproject
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(1)).thenReturn(project1); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); |
|
|
|
|
Mockito.when(processDefineMapper.queryByCode(46L)).thenReturn(processDefinition); |
|
|
|
|
Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); |
|
|
|
|
Map<String, Object> taskNullRes = processDefinitionService.viewTree(loginUser,processDefinition.getProjectCode(),46, 10); |
|
|
|
|
Map<String, Object> taskNullRes = |
|
|
|
|
processDefinitionService.viewTree(loginUser, processDefinition.getProjectCode(), 46, 10); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, taskNullRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//task instance exist
|
|
|
|
|
Map<String, Object> taskNotNuLLRes = processDefinitionService.viewTree(loginUser,processDefinition.getProjectCode(),46, 10); |
|
|
|
|
// task instance exist
|
|
|
|
|
Map<String, Object> taskNotNuLLRes = |
|
|
|
|
processDefinitionService.viewTree(loginUser, processDefinition.getProjectCode(), 46, 10); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -666,7 +736,8 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, 1, WORKFLOW_TREE_VIEW)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
Mockito.when(processService.genDagGraph(processDefinition)).thenReturn(new DAG<>()); |
|
|
|
|
Map<String, Object> taskNotNuLLRes = processDefinitionService.viewTree(loginUser,processDefinition.getProjectCode(), 46, 10); |
|
|
|
|
Map<String, Object> taskNotNuLLRes = |
|
|
|
|
processDefinitionService.viewTree(loginUser, processDefinition.getProjectCode(), 46, 10); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, taskNotNuLLRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -682,10 +753,12 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
long projectCode = 1L; |
|
|
|
|
Project project = getProject(projectCode); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_UPDATE)).thenReturn(result); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode, WORKFLOW_UPDATE)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
|
|
|
|
|
Map<String, Object> updateResult = processDefinitionService.updateProcessDefinition(loginUser, projectCode, "test", 1, |
|
|
|
|
"", "", "", 0, "root", null,"",null, ProcessExecutionTypeEnum.PARALLEL); |
|
|
|
|
Map<String, Object> updateResult = |
|
|
|
|
processDefinitionService.updateProcessDefinition(loginUser, projectCode, "test", 1, |
|
|
|
|
"", "", "", 0, "root", null, "", null, ProcessExecutionTypeEnum.PARALLEL); |
|
|
|
|
Assert.assertEquals(Status.DATA_IS_NOT_VALID, updateResult.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -732,14 +805,17 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
outputStream.putNextEntry(new ZipEntry("import_sql/")); |
|
|
|
|
|
|
|
|
|
outputStream.putNextEntry(new ZipEntry("import_sql/a.sql")); |
|
|
|
|
outputStream.write("-- upstream: start_auto_dag\n-- datasource: mysql_1\nselect 1;".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
outputStream.write( |
|
|
|
|
"-- upstream: start_auto_dag\n-- datasource: mysql_1\nselect 1;".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
|
|
|
|
outputStream.putNextEntry(new ZipEntry("import_sql/b.sql")); |
|
|
|
|
outputStream.write("-- name: start_auto_dag\n-- datasource: mysql_1\nselect 1;".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
outputStream |
|
|
|
|
.write("-- name: start_auto_dag\n-- datasource: mysql_1\nselect 1;".getBytes(StandardCharsets.UTF_8)); |
|
|
|
|
|
|
|
|
|
outputStream.close(); |
|
|
|
|
|
|
|
|
|
MockMultipartFile mockMultipartFile = new MockMultipartFile("import_sql.zip", byteArrayOutputStream.toByteArray()); |
|
|
|
|
MockMultipartFile mockMultipartFile = |
|
|
|
|
new MockMultipartFile("import_sql.zip", byteArrayOutputStream.toByteArray()); |
|
|
|
|
|
|
|
|
|
DataSource dataSource = Mockito.mock(DataSource.class); |
|
|
|
|
Mockito.when(dataSource.getId()).thenReturn(1); |
|
|
|
@ -747,16 +823,21 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
|
|
|
|
|
Mockito.when(dataSourceMapper.queryDataSourceByNameAndUserId(userId, "mysql_1")).thenReturn(dataSource); |
|
|
|
|
|
|
|
|
|
long projectCode = 1001; |
|
|
|
|
long projectCode = 1001; |
|
|
|
|
Project project1 = getProject(projectCode); |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
result.put(Constants.STATUS, Status.SUCCESS); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode, WORKFLOW_IMPORT)).thenReturn(result); |
|
|
|
|
Mockito.when(processService.saveTaskDefine(Mockito.same(loginUser), Mockito.eq(projectCode), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(2); |
|
|
|
|
Mockito.when(processService.saveProcessDefine(Mockito.same(loginUser), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(1); |
|
|
|
|
Mockito.when(processService.saveTaskRelation(Mockito.same(loginUser), Mockito.eq(projectCode), Mockito.anyLong(), |
|
|
|
|
Mockito.eq(1), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())).thenReturn(0); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project1, projectCode, WORKFLOW_IMPORT)) |
|
|
|
|
.thenReturn(result); |
|
|
|
|
Mockito.when(processService.saveTaskDefine(Mockito.same(loginUser), Mockito.eq(projectCode), Mockito.notNull(), |
|
|
|
|
Mockito.anyBoolean())).thenReturn(2); |
|
|
|
|
Mockito.when(processService.saveProcessDefine(Mockito.same(loginUser), Mockito.notNull(), Mockito.notNull(), |
|
|
|
|
Mockito.anyBoolean())).thenReturn(1); |
|
|
|
|
Mockito.when( |
|
|
|
|
processService.saveTaskRelation(Mockito.same(loginUser), Mockito.eq(projectCode), Mockito.anyLong(), |
|
|
|
|
Mockito.eq(1), Mockito.notNull(), Mockito.notNull(), Mockito.anyBoolean())) |
|
|
|
|
.thenReturn(0); |
|
|
|
|
result = processDefinitionService.importSqlProcessDefinition(loginUser, projectCode, mockMultipartFile); |
|
|
|
|
|
|
|
|
|
Assert.assertEquals(result.get(Constants.STATUS), Status.SUCCESS); |
|
|
|
|