@ -109,24 +109,25 @@ public class ProcessInstanceServiceTest {
UsersService usersService ;
UsersService usersService ;
private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\","
private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\","
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"},"
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"},"
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\","
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\","
+ "\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\","
+ "\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\","
+ "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}" ;
+ "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}" ;
@Test
@Test
public void testQueryProcessInstanceList ( ) {
public void testQueryProcessInstanceList ( ) {
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 , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , "project_test1" ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryProcessInstanceList ( loginUser , projectNam e , 46 , "2020-01-01 00:00:00" ,
Map < String , Object > proejctAuthFailRes = processInstanceService . queryProcessInstanceList ( loginUser , projectCod e , 46 , "2020-01-01 00:00:00" ,
"2020-01-02 00:00:00" , "" , "test_user" , ExecutionStatus . SUBMITTED_SUCCESS ,
"2020-01-02 00:00:00" , "" , "test_user" , ExecutionStatus . SUBMITTED_SUCCESS ,
"192.168.xx.xx" , 1 , 10 ) ;
"192.168.xx.xx" , 1 , 10 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Date start = DateUtils . getScheduleDate ( "2020-01-01 00:00:00" ) ;
Date start = DateUtils . getScheduleDate ( "2020-01-01 00:00:00" ) ;
@ -138,67 +139,67 @@ public class ProcessInstanceServiceTest {
pageReturn . setRecords ( processInstanceList ) ;
pageReturn . setRecords ( processInstanceList ) ;
// 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 ( projectName ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( processDefineMapper . selectById ( Mockito . anyInt ( ) ) ) . thenReturn ( getProcessDefinition ( ) ) ;
when ( processDefineMapper . selectById ( Mockito . anyInt ( ) ) ) . thenReturn ( getProcessDefinition ( ) ) ;
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class )
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class )
, Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) ,
, Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) ,
eq ( "192.168.xx.xx" ) , Mockito . any ( ) , Mockito . any ( ) ) ) . thenReturn ( pageReturn ) ;
eq ( "192.168.xx.xx" ) , Mockito . any ( ) , Mockito . any ( ) ) ) . thenReturn ( pageReturn ) ;
Map < String , Object > dataParameterRes = processInstanceService . queryProcessInstanceList ( loginUser , projectNam e , 1 , "20200101 00:00:00" ,
Map < String , Object > dataParameterRes = processInstanceService . queryProcessInstanceList ( loginUser , projectCod e , 1 , "20200101 00:00:00" ,
"20200102 00:00:00" , "" , loginUser . getUserName ( ) , ExecutionStatus . SUBMITTED_SUCCESS ,
"20200102 00:00:00" , "" , loginUser . getUserName ( ) , ExecutionStatus . SUBMITTED_SUCCESS ,
"192.168.xx.xx" , 1 , 10 ) ;
"192.168.xx.xx" , 1 , 10 ) ;
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 auth success
//project auth success
putMsg ( result , Status . SUCCESS , projectNam e ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . 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 ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class ) , eq ( project . getCode ( ) ) , eq ( 1L ) , eq ( "" ) , eq ( - 1 ) , Mockito . any ( ) ,
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class ) , eq ( project . getCode ( ) ) , eq ( 1L ) , eq ( "" ) , eq ( - 1 ) , Mockito . any ( ) ,
eq ( "192.168.xx.xx" ) , eq ( start ) , eq ( end ) ) ) . thenReturn ( pageReturn ) ;
eq ( "192.168.xx.xx" ) , eq ( start ) , eq ( end ) ) ) . thenReturn ( pageReturn ) ;
when ( usersService . queryUser ( processInstance . getExecutorId ( ) ) ) . thenReturn ( loginUser ) ;
when ( usersService . queryUser ( processInstance . getExecutorId ( ) ) ) . thenReturn ( loginUser ) ;
Map < String , Object > successRes = processInstanceService . queryProcessInstanceList ( loginUser , projectNam e , 1 , "2020-01-01 00:00:00" ,
Map < String , Object > successRes = processInstanceService . queryProcessInstanceList ( loginUser , projectCod e , 1 , "2020-01-01 00:00:00" ,
"2020-01-02 00:00:00" , "" , loginUser . getUserName ( ) , ExecutionStatus . SUBMITTED_SUCCESS ,
"2020-01-02 00:00:00" , "" , loginUser . getUserName ( ) , ExecutionStatus . SUBMITTED_SUCCESS ,
"192.168.xx.xx" , 1 , 10 ) ;
"192.168.xx.xx" , 1 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
// data parameter empty
// data parameter empty
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class ) , eq ( project . getCode ( ) ) , eq ( 1L ) , eq ( "" ) , eq ( - 1 ) , Mockito . any ( ) ,
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class ) , eq ( project . getCode ( ) ) , eq ( 1L ) , eq ( "" ) , eq ( - 1 ) , Mockito . any ( ) ,
eq ( "192.168.xx.xx" ) , eq ( null ) , eq ( null ) ) ) . thenReturn ( pageReturn ) ;
eq ( "192.168.xx.xx" ) , eq ( null ) , eq ( null ) ) ) . thenReturn ( pageReturn ) ;
successRes = processInstanceService . queryProcessInstanceList ( loginUser , projectNam e , 1 , "" ,
successRes = processInstanceService . queryProcessInstanceList ( loginUser , projectCod e , 1 , "" ,
"" , "" , loginUser . getUserName ( ) , ExecutionStatus . SUBMITTED_SUCCESS ,
"" , "" , loginUser . getUserName ( ) , ExecutionStatus . SUBMITTED_SUCCESS ,
"192.168.xx.xx" , 1 , 10 ) ;
"192.168.xx.xx" , 1 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . 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 > executorExistRes = processInstanceService . queryProcessInstanceList ( loginUser , projectNam e , 1 , "2020-01-01 00:00:00" ,
Map < String , Object > executorExistRes = processInstanceService . queryProcessInstanceList ( loginUser , projectCod e , 1 , "2020-01-01 00:00:00" ,
"2020-01-02 00:00:00" , "" , "admin" , ExecutionStatus . SUBMITTED_SUCCESS ,
"2020-01-02 00:00:00" , "" , "admin" , ExecutionStatus . SUBMITTED_SUCCESS ,
"192.168.xx.xx" , 1 , 10 ) ;
"192.168.xx.xx" , 1 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , executorExistRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , executorExistRes . get ( Constants . STATUS ) ) ;
//executor name empty
//executor name empty
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class ) , eq ( project . getCode ( ) ) , eq ( 1L ) , eq ( "" ) , eq ( 0 ) , Mockito . any ( ) ,
when ( processInstanceMapper . queryProcessInstanceListPaging ( Mockito . any ( Page . class ) , eq ( project . getCode ( ) ) , eq ( 1L ) , eq ( "" ) , eq ( 0 ) , Mockito . any ( ) ,
eq ( "192.168.xx.xx" ) , eq ( start ) , eq ( end ) ) ) . thenReturn ( pageReturn ) ;
eq ( "192.168.xx.xx" ) , eq ( start ) , eq ( end ) ) ) . thenReturn ( pageReturn ) ;
Map < String , Object > executorEmptyRes = processInstanceService . queryProcessInstanceList ( loginUser , projectNam e , 1 , "2020-01-01 00:00:00" ,
Map < String , Object > executorEmptyRes = processInstanceService . queryProcessInstanceList ( loginUser , projectCod e , 1 , "2020-01-01 00:00:00" ,
"2020-01-02 00:00:00" , "" , "" , ExecutionStatus . SUBMITTED_SUCCESS ,
"2020-01-02 00:00:00" , "" , "" , ExecutionStatus . SUBMITTED_SUCCESS ,
"192.168.xx.xx" , 1 , 10 ) ;
"192.168.xx.xx" , 1 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , executorEmptyRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , executorEmptyRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testQueryTopNLongestRunningProcessInstance ( ) {
public void testQueryTopNLongestRunningProcessInstance ( ) {
String projectName = "project_test1" ;
long projectCode = 1L ;
User loginUser = getAdminUser ( ) ;
User loginUser = getAdminUser ( ) ;
Project project = getProject ( projectCode ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
int size = 10 ;
int size = 10 ;
String startTime = "2020-01-01 00:00:00" ;
String startTime = "2020-01-01 00:00:00" ;
String endTime = "2020-08-02 00:00:00" ;
String endTime = "2020-08-02 00:00:00" ;
@ -206,77 +207,76 @@ public class ProcessInstanceServiceTest {
Date end = DateUtils . getScheduleDate ( endTime ) ;
Date end = DateUtils . getScheduleDate ( endTime ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryTopNLongestRunningProcessInstance ( loginUser , projectNam e , size , startTime , endTime ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryTopNLongestRunningProcessInstance ( loginUser , projectCod e , size , startTime , endTime ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
//project auth success
//project auth success
putMsg ( result , Status . SUCCESS , projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Project project = getProject ( projectName ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . 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 ( usersService . queryUser ( processInstance . getExecutorId ( ) ) ) . thenReturn ( loginUser ) ;
when ( usersService . queryUser ( processInstance . getExecutorId ( ) ) ) . thenReturn ( loginUser ) ;
Map < String , Object > successRes = processInstanceService . queryTopNLongestRunningProcessInstance ( loginUser , projectNam e , size , startTime , endTime ) ;
Map < String , Object > successRes = processInstanceService . queryTopNLongestRunningProcessInstance ( loginUser , projectCod e , size , startTime , endTime ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testQueryProcessInstanceById ( ) {
public void testQueryProcessInstanceById ( ) {
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 , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryProcessInstanceById ( loginUser , projectNam e , 1 ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryProcessInstanceById ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
//project auth success
//project auth success
ProcessInstance processInstance = getProcessInstance ( ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Project project = getProject ( projectName ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
when ( processService . findProcessInstanceDetailById ( processInstance . getId ( ) ) ) . thenReturn ( processInstance ) ;
when ( processService . findProcessInstanceDetailById ( processInstance . getId ( ) ) ) . thenReturn ( processInstance ) ;
when ( processService . findProcessDefinition ( processInstance . getProcessDefinitionCode ( ) ,
when ( processService . findProcessDefinition ( processInstance . getProcessDefinitionCode ( ) ,
processInstance . getProcessDefinitionVersion ( ) ) ) . thenReturn ( processDefinition ) ;
processInstance . getProcessDefinitionVersion ( ) ) ) . thenReturn ( processDefinition ) ;
Map < String , Object > successRes = processInstanceService . queryProcessInstanceById ( loginUser , projectNam e , 1 ) ;
Map < String , Object > successRes = processInstanceService . queryProcessInstanceById ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
//worker group null
//worker group null
Map < String , Object > workerNullRes = processInstanceService . queryProcessInstanceById ( loginUser , projectNam e , 1 ) ;
Map < String , Object > workerNullRes = processInstanceService . queryProcessInstanceById ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUCCESS , workerNullRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , workerNullRes . get ( Constants . STATUS ) ) ;
//worker group exist
//worker group exist
WorkerGroup workerGroup = getWorkGroup ( ) ;
WorkerGroup workerGroup = getWorkGroup ( ) ;
Map < String , Object > workerExistRes = processInstanceService . queryProcessInstanceById ( loginUser , projectNam e , 1 ) ;
Map < String , Object > workerExistRes = processInstanceService . queryProcessInstanceById ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUCCESS , workerExistRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , workerExistRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testQueryTaskListByProcessId ( ) throws IOException {
public void testQueryTaskListByProcessId ( ) throws IOException {
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 , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryTaskListByProcessId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryTaskListByProcessId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
//project auth success
//project auth success
putMsg ( result , Status . SUCCESS , projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Project project = getProject ( projectName ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
processInstance . setState ( ExecutionStatus . SUCCESS ) ;
processInstance . setState ( ExecutionStatus . SUCCESS ) ;
TaskInstance taskInstance = new TaskInstance ( ) ;
TaskInstance taskInstance = new TaskInstance ( ) ;
@ -286,103 +286,107 @@ public class ProcessInstanceServiceTest {
Result res = new Result ( ) ;
Result res = new Result ( ) ;
res . setCode ( Status . SUCCESS . ordinal ( ) ) ;
res . setCode ( Status . SUCCESS . ordinal ( ) ) ;
res . setData ( "xxx" ) ;
res . setData ( "xxx" ) ;
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
when ( processService . findProcessInstanceDetailById ( processInstance . getId ( ) ) ) . thenReturn ( processInstance ) ;
when ( processService . findProcessInstanceDetailById ( processInstance . getId ( ) ) ) . thenReturn ( processInstance ) ;
when ( processService . findValidTaskListByProcessId ( processInstance . getId ( ) ) ) . thenReturn ( taskInstanceList ) ;
when ( processService . findValidTaskListByProcessId ( processInstance . getId ( ) ) ) . thenReturn ( taskInstanceList ) ;
when ( loggerService . queryLog ( taskInstance . getId ( ) , 0 , 4098 ) ) . thenReturn ( res ) ;
when ( loggerService . queryLog ( taskInstance . getId ( ) , 0 , 4098 ) ) . thenReturn ( res ) ;
Map < String , Object > successRes = processInstanceService . queryTaskListByProcessId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > successRes = processInstanceService . queryTaskListByProcessId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testParseLogForDependentResult ( ) throws IOException {
public void testParseLogForDependentResult ( ) throws IOException {
String logString = "[INFO] 2019-03-19 17:11:08.475 org.apache.dolphinscheduler.server.worker.log.TaskLogger:[172]"
String logString = "[INFO] 2019-03-19 17:11:08.475 org.apache.dolphinscheduler.server.worker.log.TaskLogger:[172]"
+ " - [taskAppId=TASK_223_10739_452334] dependent item complete :|| 223-ALL-day-last1Day,SUCCESS\n"
+ " - [taskAppId=TASK_223_10739_452334] dependent item complete :|| 223-ALL-day-last1Day,SUCCESS\n"
+ "[INFO] 2019-03-19 17:11:08.476 org.apache.dolphinscheduler.server.worker.runner.TaskScheduleThread:[172]"
+ "[INFO] 2019-03-19 17:11:08.476 org.apache.dolphinscheduler.server.worker.runner.TaskScheduleThread:[172]"
+ " - task : 223_10739_452334 exit status code : 0\n"
+ " - task : 223_10739_452334 exit status code : 0\n"
+ "[root@node2 current]# " ;
+ "[root@node2 current]# " ;
Map < String , DependResult > resultMap =
Map < String , DependResult > resultMap =
processInstanceService . parseLogForDependentResult ( logString ) ;
processInstanceService . parseLogForDependentResult ( logString ) ;
Assert . assertEquals ( 1 , resultMap . size ( ) ) ;
Assert . assertEquals ( 1 , resultMap . size ( ) ) ;
}
}
@Test
@Test
public void testQuerySubProcessInstanceByTaskId ( ) {
public void testQuerySubProcessInstanceByTaskId ( ) {
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 , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
//task null
//task null
Project project = getProject ( projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( processService . findTaskInstanceById ( 1 ) ) . thenReturn ( null ) ;
when ( processService . findTaskInstanceById ( 1 ) ) . thenReturn ( null ) ;
Map < String , Object > taskNullRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > taskNullRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . TASK_INSTANCE_NOT_EXISTS , taskNullRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . TASK_INSTANCE_NOT_EXISTS , taskNullRes . get ( Constants . STATUS ) ) ;
//task not sub process
//task not sub process
TaskInstance taskInstance = getTaskInstance ( ) ;
TaskInstance taskInstance = getTaskInstance ( ) ;
taskInstance . setTaskType ( TaskType . HTTP . getDesc ( ) ) ;
taskInstance . setTaskType ( TaskType . HTTP . getDesc ( ) ) ;
taskInstance . setProcessInstanceId ( 1 ) ;
taskInstance . setProcessInstanceId ( 1 ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
when ( processService . findTaskInstanceById ( 1 ) ) . thenReturn ( taskInstance ) ;
when ( processService . findTaskInstanceById ( 1 ) ) . thenReturn ( taskInstance ) ;
Map < String , Object > notSubprocessRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > notSubprocessRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE , notSubprocessRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . TASK_INSTANCE_NOT_SUB_WORKFLOW_INSTANCE , notSubprocessRes . get ( Constants . STATUS ) ) ;
//sub process not exist
//sub process not exist
TaskInstance subTask = getTaskInstance ( ) ;
TaskInstance subTask = getTaskInstance ( ) ;
subTask . setTaskType ( TaskType . SUB_PROCESS . getDesc ( ) ) ;
subTask . setTaskType ( TaskType . SUB_PROCESS . getDesc ( ) ) ;
subTask . setProcessInstanceId ( 1 ) ;
subTask . setProcessInstanceId ( 1 ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
when ( processService . findTaskInstanceById ( subTask . getId ( ) ) ) . thenReturn ( subTask ) ;
when ( processService . findTaskInstanceById ( subTask . getId ( ) ) ) . thenReturn ( subTask ) ;
when ( processService . findSubProcessInstance ( subTask . getProcessInstanceId ( ) , subTask . getId ( ) ) ) . thenReturn ( null ) ;
when ( processService . findSubProcessInstance ( subTask . getProcessInstanceId ( ) , subTask . getId ( ) ) ) . thenReturn ( null ) ;
Map < String , Object > subprocessNotExistRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > subprocessNotExistRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUB_PROCESS_INSTANCE_NOT_EXIST , subprocessNotExistRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUB_PROCESS_INSTANCE_NOT_EXIST , subprocessNotExistRes . get ( Constants . STATUS ) ) ;
//sub process exist
//sub process exist
ProcessInstance processInstance = getProcessInstance ( ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
when ( processService . findSubProcessInstance ( taskInstance . getProcessInstanceId ( ) , taskInstance . getId ( ) ) ) . thenReturn ( processInstance ) ;
when ( processService . findSubProcessInstance ( taskInstance . getProcessInstanceId ( ) , taskInstance . getId ( ) ) ) . thenReturn ( processInstance ) ;
Map < String , Object > subprocessExistRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > subprocessExistRes = processInstanceService . querySubProcessInstanceByTaskId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUCCESS , subprocessExistRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , subprocessExistRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testUpdateProcessInstance ( ) {
public void testUpdateProcessInstance ( ) {
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 , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . updateProcessInstance ( loginUser , projectNam e , 1 ,
Map < String , Object > proejctAuthFailRes = processInstanceService . updateProcessInstance ( loginUser , projectCod e , 1 ,
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
//process instance null
//process instance null
Project project = getProject ( projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( null ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( null ) ;
Map < String , Object > processInstanceNullRes = processInstanceService . updateProcessInstance ( loginUser , projectNam e , 1 ,
Map < String , Object > processInstanceNullRes = processInstanceService . updateProcessInstance ( loginUser , projectCod e , 1 ,
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_NOT_EXIST , processInstanceNullRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_NOT_EXIST , processInstanceNullRes . get ( Constants . STATUS ) ) ;
//process instance not finish
//process instance not finish
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
processInstance . setState ( ExecutionStatus . RUNNING_EXECUTION ) ;
processInstance . setState ( ExecutionStatus . RUNNING_EXECUTION ) ;
Map < String , Object > processInstanceNotFinishRes = processInstanceService . updateProcessInstance ( loginUser , projectName , 1 ,
putMsg ( result , Status . SUCCESS , projectCode ) ;
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
Map < String , Object > processInstanceNotFinishRes = processInstanceService . updateProcessInstance ( loginUser , projectCode , 1 ,
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_STATE_OPERATION_ERROR , processInstanceNotFinishRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_STATE_OPERATION_ERROR , processInstanceNotFinishRes . get ( Constants . STATUS ) ) ;
//process instance finish
//process instance finish
@ -402,82 +406,79 @@ public class ProcessInstanceServiceTest {
when ( processService . updateProcessInstance ( processInstance ) ) . thenReturn ( 1 ) ;
when ( processService . updateProcessInstance ( processInstance ) ) . thenReturn ( 1 ) ;
when ( processDefinitionService . checkProcessNodeList ( shellJson ) ) . thenReturn ( result ) ;
when ( processDefinitionService . checkProcessNodeList ( shellJson ) ) . thenReturn ( result ) ;
when ( processService . findProcessDefinition ( processInstance . getProcessDefinitionCode ( ) ,
when ( processService . findProcessDefinition ( processInstance . getProcessDefinitionCode ( ) ,
processInstance . getProcessDefinitionVersion ( ) ) ) . thenReturn ( processDefinition ) ;
processInstance . getProcessDefinitionVersion ( ) ) ) . thenReturn ( processDefinition ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Map < String , Object > processInstanceFinishRes = processInstanceService . updateProcessInstance ( loginUser , projectNam e , 1 ,
Map < String , Object > processInstanceFinishRes = processInstanceService . updateProcessInstance ( loginUser , projectCod e , 1 ,
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
Assert . assertEquals ( Status . UPDATE_PROCESS_INSTANCE_ERROR , processInstanceFinishRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . UPDATE_PROCESS_INSTANCE_ERROR , processInstanceFinishRes . get ( Constants . STATUS ) ) ;
//success
//success
when ( processService . saveProcessDefinition ( Mockito . any ( ) , Mockito . any ( ) ,
when ( processService . saveProcessDefinition ( Mockito . any ( ) , Mockito . any ( ) ,
Mockito . anyString ( ) , Mockito . anyString ( ) , Mockito . anyString ( ) ,
Mockito . anyString ( ) , Mockito . anyString ( ) , Mockito . anyString ( ) ,
Mockito . any ( ) , Mockito . any ( ) , Mockito . anyBoolean ( ) ) ) . thenReturn ( 1 ) ;
Mockito . any ( ) , Mockito . any ( ) , Mockito . anyBoolean ( ) ) ) . thenReturn ( 1 ) ;
when ( processService . findProcessDefinition ( 46L , 0 ) ) . thenReturn ( processDefinition ) ;
when ( processService . findProcessDefinition ( 46L , 0 ) ) . thenReturn ( processDefinition ) ;
putMsg ( result , Status . SUCCESS , projectNam e ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Map < String , Object > successRes = processInstanceService . updateProcessInstance ( loginUser , projectNam e , 1 ,
Map < String , Object > successRes = processInstanceService . updateProcessInstance ( loginUser , projectCod e , 1 ,
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
shellJson , "2020-02-21 00:00:00" , true , Flag . YES , "" ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testQueryParentInstanceBySubId ( ) {
public void testQueryParentInstanceBySubId ( ) {
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 , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project auth fail
//project auth fail
when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( null ) ;
when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > proejctAuthFailRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , proejctAuthFailRes . get ( Constants . STATUS ) ) ;
//process instance null
//process instance null
Project project = getProject ( projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( null ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( null ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > processInstanceNullRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectCode , 1 ) ;
Map < String , Object > processInstanceNullRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectName , 1 ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_NOT_EXIST , processInstanceNullRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_NOT_EXIST , processInstanceNullRes . get ( Constants . STATUS ) ) ;
//not sub process
//not sub process
ProcessInstance processInstance = getProcessInstance ( ) ;
ProcessInstance processInstance = getProcessInstance ( ) ;
processInstance . setIsSubProcess ( Flag . NO ) ;
processInstance . setIsSubProcess ( Flag . NO ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
Map < String , Object > notSubProcessRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > notSubProcessRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE , notSubProcessRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_NOT_SUB_PROCESS_INSTANCE , notSubProcessRes . get ( Constants . STATUS ) ) ;
//sub process
//sub process
processInstance . setIsSubProcess ( Flag . YES ) ;
processInstance . setIsSubProcess ( Flag . YES ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
when ( processService . findParentProcessInstance ( 1 ) ) . thenReturn ( null ) ;
when ( processService . findParentProcessInstance ( 1 ) ) . thenReturn ( null ) ;
Map < String , Object > subProcessNullRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > subProcessNullRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUB_PROCESS_INSTANCE_NOT_EXIST , subProcessNullRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUB_PROCESS_INSTANCE_NOT_EXIST , subProcessNullRes . get ( Constants . STATUS ) ) ;
//success
//success
putMsg ( result , Status . SUCCESS , projectCode ) ;
when ( processService . findParentProcessInstance ( 1 ) ) . thenReturn ( processInstance ) ;
when ( processService . findParentProcessInstance ( 1 ) ) . thenReturn ( processInstance ) ;
Map < String , Object > successRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectNam e , 1 ) ;
Map < String , Object > successRes = processInstanceService . queryParentInstanceBySubId ( loginUser , projectCod e , 1 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testDeleteProcessInstanceById ( ) {
public void testDeleteProcessInstanceById ( ) {
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
when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( null ) ;
when ( projectService . checkProjectAndAuth ( loginUser , null , projectName ) ) . thenReturn ( result ) ;
//process instance null
//process instance null
Project project = getProject ( projectName ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( project ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( null ) ;
when ( processService . findProcessInstanceDetailById ( 1 ) ) . thenReturn ( null ) ;
}
}
@ -503,8 +504,8 @@ public class ProcessInstanceServiceTest {
taskInstance . setStartTime ( new Date ( ) ) ;
taskInstance . setStartTime ( new Date ( ) ) ;
when ( processInstanceMapper . queryDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
when ( processInstanceMapper . queryDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
when ( processDefinitionLogMapper . queryByDefinitionCodeAndVersion (
when ( processDefinitionLogMapper . queryByDefinitionCodeAndVersion (
processInstance . getProcessDefinitionCode ( ) ,
processInstance . getProcessDefinitionCode ( ) ,
processInstance . getProcessDefinitionVersion ( )
processInstance . getProcessDefinitionVersion ( )
) ) . thenReturn ( new ProcessDefinitionLog ( ) ) ;
) ) . thenReturn ( new ProcessDefinitionLog ( ) ) ;
when ( processInstanceMapper . queryDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
when ( processInstanceMapper . queryDetailById ( 1 ) ) . thenReturn ( processInstance ) ;
when ( taskInstanceMapper . queryByInstanceIdAndName ( Mockito . anyInt ( ) , Mockito . any ( ) ) ) . thenReturn ( taskInstance ) ;
when ( taskInstanceMapper . queryByInstanceIdAndName ( Mockito . anyInt ( ) , Mockito . any ( ) ) ) . thenReturn ( taskInstance ) ;
@ -514,7 +515,7 @@ public class ProcessInstanceServiceTest {
}
}
when ( processService . genDagGraph ( Mockito . any ( ProcessDefinition . class ) ) )
when ( processService . genDagGraph ( Mockito . any ( ProcessDefinition . class ) ) )
. thenReturn ( graph ) ;
. thenReturn ( graph ) ;
Map < String , Object > successRes = processInstanceService . viewGantt ( 1 ) ;
Map < String , Object > successRes = processInstanceService . viewGantt ( 1 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
@ -536,14 +537,14 @@ public class ProcessInstanceServiceTest {
/ * *
/ * *
* get mock Project
* get mock Project
*
*
* @param projectName projectNam e
* @param projectCode projectCod e
* @return Project
* @return Project
* /
* /
private Project getProject ( String projectNam e) {
private Project getProject ( long projectCod e) {
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 ;
}
}