@ -44,6 +44,7 @@ import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.entity.ProcessData ;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition ;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance ;
import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation ;
import org.apache.dolphinscheduler.dao.entity.Project ;
import org.apache.dolphinscheduler.dao.entity.Schedule ;
import org.apache.dolphinscheduler.dao.entity.TaskInstance ;
@ -67,6 +68,8 @@ import java.util.Date;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Set ;
import java.util.stream.Collectors ;
import javax.servlet.ServletOutputStream ;
import javax.servlet.http.HttpServletResponse ;
@ -253,55 +256,55 @@ public class ProcessDefinitionServiceTest {
@Test
public void testQueryProcessDefinitionList ( ) {
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Project project = getProject ( projectNam e ) ;
Project project = getProject ( projectCod e ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project not found
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionList ( loginUser , "project_test1" ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionList ( loginUser , projectCode ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
//project check auth success
putMsg ( result , Status . SUCCESS , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . 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 , "project_test1" ) ;
Map < String , Object > checkSuccessRes = processDefinitionService . queryProcessDefinitionList ( loginUser , projectCode ) ;
Assert . assertEquals ( Status . SUCCESS , checkSuccessRes . get ( Constants . STATUS ) ) ;
}
@Test
@SuppressWarnings ( "unchecked" )
public void testQueryProcessDefinitionListPaging ( ) {
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Project project = getProject ( projectNam e ) ;
Project project = getProject ( projectCod e ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project not found
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionListPaging ( loginUser , "project_test1" , "" , 1 , 5 , 0 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionListPaging ( loginUser , projectCode , "" , 1 , 5 , 0 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
putMsg ( result , Status . SUCCESS , projectNam e ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
loginUser . setId ( 1 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Page < ProcessDefinition > page = new Page < > ( 1 , 10 ) ;
page . setTotal ( 30 ) ;
Mockito . when ( processDefineMapper . queryDefineListPaging (
@ -312,229 +315,211 @@ public class ProcessDefinitionServiceTest {
, Mockito . anyBoolean ( ) ) ) . thenReturn ( page ) ;
Map < String , Object > map1 = processDefinitionService . queryProcessDefinitionListPaging (
loginUser , projectName , "" , 1 , 10 , loginUser . getId ( ) ) ;
loginUser , 1L , "" , 1 , 10 , loginUser . getId ( ) ) ;
Assert . assertEquals ( Status . SUCCESS , map1 . get ( Constants . STATUS ) ) ;
}
@Test
public void testQueryProcessDefinitionByCode ( ) {
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Project project = getProject ( projectNam e ) ;
Project project = getProject ( projectCod e ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project check auth fail
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByCode ( loginUser ,
"project_test1" , 1L ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByCode ( loginUser , 1L , 1L ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
//project check auth success, instance not exist
putMsg ( result , Status . SUCCESS , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
DagData dagData = new DagData ( getProcessDefinition ( ) , null , null ) ;
Mockito . when ( processService . genDagData ( Mockito . any ( ) ) ) . thenReturn ( dagData ) ;
Map < String , Object > instanceNotexitRes = processDefinitionService . queryProcessDefinitionByCode ( loginUser ,
"project_test1" , 1L ) ;
Map < String , Object > instanceNotexitRes = processDefinitionService . queryProcessDefinitionByCode ( loginUser , projectCode , 1L ) ;
Assert . assertEquals ( Status . PROCESS_DEFINE_NOT_EXIST , instanceNotexitRes . get ( Constants . STATUS ) ) ;
//instance exit
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( getProcessDefinition ( ) ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionByCode ( loginUser ,
"project_test1" , 46L ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionByCode ( loginUser , projectCode , 46L ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
@Test
public void testQueryProcessDefinitionByName ( ) {
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Project project = getProject ( projectNam e ) ;
Project project = getProject ( projectCod e ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
//project check auth fail
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByName ( loginUser ,
"project_test1" , "test_def" ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByName ( loginUser , projectCode , "test_def" ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
//project check auth success, instance not exist
putMsg ( result , Status . SUCCESS , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Mockito . when ( processDefineMapper . queryByDefineName ( project . getCode ( ) , "test_def" ) ) . thenReturn ( null ) ;
ProcessData processData = getProcessData ( ) ;
Mockito . when ( processService . genProcessData ( Mockito . any ( ) ) ) . thenReturn ( processData ) ;
Map < String , Object > instanceNotexitRes = processDefinitionService . queryProcessDefinitionByName ( loginUser ,
"project_test1" , "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 ( ) ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionByName ( loginUser ,
"project_test1" , "test" ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionByName ( loginUser , projectCode , "test" ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
@Test
public void testBatchCopyProcessDefinition ( ) {
String projectName = "project_test1" ;
Project project = getProject ( projectName ) ;
long projectCode = 1L ;
Project project = getProject ( projectCode ) ;
User loginUser = new User ( ) ;
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
// copy project definition ids empty test
Map < String , Object > map = processDefinitionService . batchCopyProcessDefinition ( loginUser , projectNam e , StringUtils . EMPTY , "project_test2" ) ;
Map < String , Object > map = processDefinitionService . batchCopyProcessDefinition ( loginUser , projectCod e , StringUtils . EMPTY , 2L ) ;
Assert . assertEquals ( Status . PROCESS_DEFINITION_CODES_IS_EMPTY , map . get ( Constants . STATUS ) ) ;
// project check auth fail
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map1 = processDefinitionService . batchCopyProcessDefinition (
loginUser , projectNam e , String . valueOf ( project . getId ( ) ) , "project_test2" ) ;
loginUser , projectCod e , String . valueOf ( project . getId ( ) ) , 2L ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map1 . get ( Constants . STATUS ) ) ;
// project check auth success, target project is null
Mockito . when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( getProject ( projectName ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , "project_test2" ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map2 = processDefinitionService . batchCopyProcessDefinition (
loginUser , projectName , String . valueOf ( project . getId ( ) ) , "project_test2" ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map2 . get ( Constants . STATUS ) ) ;
// project check auth success, target project name not equal project name, check auth target project fail
Project project1 = getProject ( projectName ) ;
Mockito . when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( project1 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
projectCode = 2L ;
Project project1 = getProject ( projectCode ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project1 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
// instance exit
putMsg ( result , Status . SUCCESS , projectCode ) ;
ProcessDefinition definition = getProcessDefinition ( ) ;
definition . setLocations ( "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ) ;
definition . setConnects ( "[]" ) ;
List < ProcessDefinition > processDefinitionList = new ArrayList < > ( ) ;
processDefinitionList . add ( definition ) ;
Set < Long > definitionCodes = Arrays . stream ( "46" . split ( Constants . COMMA ) ) . map ( Long : : parseLong ) . collect ( Collectors . toSet ( ) ) ;
Mockito . when ( processDefineMapper . queryByCodes ( definitionCodes ) ) . thenReturn ( processDefinitionList ) ;
Map < String , Object > map3 = processDefinitionService . batchCopyProcessDefinition (
loginUser , projectNam e , "46" , projectName ) ;
loginUser , projectCod e , "46" , 1L ) ;
Assert . assertEquals ( Status . COPY_PROCESS_DEFINITION_ERROR , map3 . get ( Constants . STATUS ) ) ;
}
@Test
public void testBatchMoveProcessDefinition ( ) {
String projectName = "project_test1" ;
Project project1 = getProject ( projectNam e ) ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project1 ) ;
long projectCode = 1L ;
Project project1 = getProject ( projectCod e ) ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project1 ) ;
String projectName2 = "project_test2" ;
Project project2 = getProject ( projectName2 ) ;
Mockito . when ( projectMapper . queryByName ( projectName2 ) ) . thenReturn ( project2 ) ;
int targetProjectId = 2 ;
Mockito . when ( projectMapper . queryDetailById ( targetProjectId ) ) . thenReturn ( getProjectById ( targetProjectId ) ) ;
Project project = getProject ( projectName ) ;
Project targetProject = getProjectById ( targetProjectId ) ;
long projectCode2 = 2L ;
Project project2 = getProject ( projectCode2 ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode2 ) ) . thenReturn ( project2 ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectName ) ;
Map < String , Object > result2 = new HashMap < > ( ) ;
putMsg ( result2 , Status . SUCCESS , targetProject . getName ( ) ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project2 , projectName2 ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project1 , project1 . getName ( ) ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project2 , project2 . getName ( ) ) ) . thenReturn ( result ) ;
ProcessDefinition definition = getProcessDefinition ( ) ;
definition . setLocations ( "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ) ;
definition . setConnects ( "[]" ) ;
List < ProcessDefinition > processDefinitionList = new ArrayList < > ( ) ;
processDefinitionList . add ( definition ) ;
Set < Long > definitionCodes = Arrays . stream ( "46" . split ( Constants . COMMA ) ) . map ( Long : : parseLong ) . collect ( Collectors . toSet ( ) ) ;
Mockito . when ( processDefineMapper . queryByCodes ( definitionCodes ) ) . thenReturn ( processDefinitionList ) ;
Mockito . when ( processTaskRelationMapper . queryByProcessCode ( projectCode , 46L ) ) . thenReturn ( getProcessTaskRelation ( projectCode , 46L ) ) ;
putMsg ( result , Status . SUCCESS ) ;
Map < String , Object > successRes = processDefinitionService . batchMoveProcessDefinition (
loginUser , "project_test1" , "46" , 2 ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
loginUser , projectCode , "46" , projectCode2 ) ;
Assert . assertEquals ( Status . MOVE_PROCESS_DEFINITION_ERROR , successRes . get ( Constants . STATUS ) ) ;
}
@Test
public void deleteProcessDefinitionByIdTest ( ) {
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Project project = getProject ( projectNam e ) ;
Project project = getProject ( projectCod e ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . deleteProcessDefinitionById ( loginUser , "project_test1" , 6 ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 6 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
//project check auth success, instance not exist
putMsg ( result , Status . SUCCESS , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Mockito . when ( processDefineMapper . selectById ( 1 ) ) . thenReturn ( null ) ;
Map < String , Object > instanceNotexitRes = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 1 ) ;
Assert . assertEquals ( Status . PROCESS_DEFINE_NOT_EXIST , instanceNotexitRes . get ( Constants . STATUS ) ) ;
Map < String , Object > instanceNotExitRes = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 1 ) ;
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 , project . getName ( ) ) ) . thenReturn ( result ) ;
//user no auth
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Mockito . when ( processDefineMapper . selectById ( 46 ) ) . thenReturn ( processDefinition ) ;
Map < String , Object > userNoAuthRes = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 46 ) ;
Map < String , Object > userNoAuthRes = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 46 ) ;
Assert . assertEquals ( Status . USER_NO_OPERATION_PERM , userNoAuthRes . get ( Constants . STATUS ) ) ;
//process definition online
loginUser . setUserType ( UserType . ADMIN_USER ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
processDefinition . setReleaseState ( ReleaseState . ONLINE ) ;
Mockito . when ( processDefineMapper . selectById ( 46 ) ) . thenReturn ( processDefinition ) ;
Map < String , Object > dfOnlineRes = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 46 ) ;
Map < String , Object > dfOnlineRes = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 46 ) ;
Assert . assertEquals ( Status . PROCESS_DEFINE_STATE_ONLINE , dfOnlineRes . get ( Constants . STATUS ) ) ;
//scheduler list elements > 1
processDefinition . setReleaseState ( ReleaseState . OFFLINE ) ;
Mockito . when ( processDefineMapper . selectById ( 46 ) ) . thenReturn ( processDefinition ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
List < Schedule > schedules = new ArrayList < > ( ) ;
schedules . add ( getSchedule ( ) ) ;
schedules . add ( getSchedule ( ) ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionId ( 46 ) ) . thenReturn ( schedules ) ;
Map < String , Object > schedulerGreaterThanOneRes = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 46 ) ;
Map < String , Object > schedulerGreaterThanOneRes = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 46 ) ;
Assert . assertEquals ( Status . DELETE_PROCESS_DEFINE_BY_ID_ERROR , schedulerGreaterThanOneRes . get ( Constants . STATUS ) ) ;
//scheduler online
@ -542,103 +527,104 @@ public class ProcessDefinitionServiceTest {
Schedule schedule = getSchedule ( ) ;
schedule . setReleaseState ( ReleaseState . ONLINE ) ;
schedules . add ( schedule ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionId ( 46 ) ) . thenReturn ( schedules ) ;
Map < String , Object > schedulerOnlineRes = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 46 ) ;
Map < String , Object > schedulerOnlineRes = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 46 ) ;
Assert . assertEquals ( Status . SCHEDULE_CRON_STATE_ONLINE , schedulerOnlineRes . get ( Constants . STATUS ) ) ;
//delete fail
schedules . clear ( ) ;
schedule . setReleaseState ( ReleaseState . OFFLINE ) ;
schedules . add ( schedule ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionId ( 46 ) ) . thenReturn ( schedules ) ;
Mockito . when ( processDefineMapper . deleteById ( 46 ) ) . thenReturn ( 0 ) ;
Map < String , Object > deleteFail = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 46 ) ;
Map < String , Object > deleteFail = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 46 ) ;
Assert . assertEquals ( Status . DELETE_PROCESS_DEFINE_BY_ID_ERROR , deleteFail . get ( Constants . STATUS ) ) ;
//delete success
Mockito . when ( processDefineMapper . deleteById ( 46 ) ) . thenReturn ( 1 ) ;
Map < String , Object > deleteSuccess = processDefinitionService . deleteProcessDefinitionById ( loginUser ,
"project_test1" , 46 ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Map < String , Object > deleteSuccess = processDefinitionService . deleteProcessDefinitionById ( loginUser , projectCode , 46 ) ;
Assert . assertEquals ( Status . SUCCESS , deleteSuccess . get ( Constants . STATUS ) ) ;
}
@Test
public void testReleaseProcessDefinition ( ) {
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( getProject ( projectName ) ) ;
Project project = getProject ( projectName ) ;
Project project = getProject ( projectCode ) ;
User loginUser = new User ( ) ;
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . releaseProcessDefinition ( loginUser , "project_test1" ,
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . releaseProcessDefinition ( loginUser , projectCode ,
6 , ReleaseState . OFFLINE ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
// project check auth success, processs definition online
putMsg ( result , Status . SUCCESS , projectNam e ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( getProcessDefinition ( ) ) ;
Map < String , Object > onlineRes = processDefinitionService . releaseProcessDefinition (
loginUser , "project_test1" , 46 , ReleaseState . ONLINE ) ;
loginUser , projectCode , 46 , ReleaseState . ONLINE ) ;
Assert . assertEquals ( Status . SUCCESS , onlineRes . get ( Constants . STATUS ) ) ;
// project check auth success, processs definition online
ProcessDefinition processDefinition1 = getProcessDefinition ( ) ;
processDefinition1 . setResourceIds ( "1,2" ) ;
Map < String , Object > onlineWithResourceRes = processDefinitionService . releaseProcessDefinition (
loginUser , "project_test1" , 46 , ReleaseState . ONLINE ) ;
loginUser , projectCode , 46 , ReleaseState . ONLINE ) ;
Assert . assertEquals ( Status . SUCCESS , onlineWithResourceRes . get ( Constants . STATUS ) ) ;
// release error code
Map < String , Object > failRes = processDefinitionService . releaseProcessDefinition (
loginUser , "project_test1" , 46 , ReleaseState . getEnum ( 2 ) ) ;
loginUser , projectCode , 46 , ReleaseState . getEnum ( 2 ) ) ;
Assert . assertEquals ( Status . REQUEST_PARAMS_NOT_VALID_ERROR , failRes . get ( Constants . STATUS ) ) ;
}
@Test
public void testVerifyProcessDefinitionName ( ) {
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
long projectCode = 1L ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Project project = getProject ( projectNam e ) ;
Project project = getProject ( projectCod e ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectNam e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT , projectCod e ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . verifyProcessDefinitionName ( loginUser ,
"project_test1" , "test_pdf" ) ;
projectCode , "test_pdf" ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUNT , map . get ( Constants . STATUS ) ) ;
//project check auth success, process not exist
putMsg ( result , Status . SUCCESS , projectNam e ) ;
putMsg ( result , Status . SUCCESS , projectCod e ) ;
Mockito . when ( processDefineMapper . verifyByDefineName ( project . getCode ( ) , "test_pdf" ) ) . thenReturn ( null ) ;
Map < String , Object > processNotExistRes = processDefinitionService . verifyProcessDefinitionName ( loginUser ,
"project_test1" , "test_pdf" ) ;
projectCode , "test_pdf" ) ;
Assert . assertEquals ( Status . SUCCESS , processNotExistRes . get ( Constants . STATUS ) ) ;
//process exist
Mockito . when ( processDefineMapper . verifyByDefineName ( project . getCode ( ) , "test_pdf" ) ) . thenReturn ( getProcessDefinition ( ) ) ;
Map < String , Object > processExistRes = processDefinitionService . verifyProcessDefinitionName ( loginUser ,
"project_test1" , "test_pdf" ) ;
projectCode , "test_pdf" ) ;
Assert . assertEquals ( Status . PROCESS_DEFINITION_NAME_EXIST , processExistRes . get ( Constants . STATUS ) ) ;
}
@Test
public void testCheckProcessNodeList ( ) {
Map < String , Object > dataNotValidRes = processDefinitionService . checkProcessNodeList ( null , "" ) ;
Assert . assertEquals ( Status . DATA_IS_NOT_VALID , dataNotValidRes . get ( Constants . STATUS ) ) ;
@ -721,26 +707,26 @@ public class ProcessDefinitionServiceTest {
}
@Test
public void testQueryProcessDefinitionAllByProjectId ( ) {
int projectId = 1 ;
Long projectCode = 2L ;
Project project = new Project ( ) ;
project . setId ( projectId ) ;
project . setCode ( projectCode ) ;
Mockito . when ( projectMapper . selectById ( projectId ) ) . thenReturn ( project ) ;
public void testQueryAllProcessDefinitionByProjectCode ( ) {
User loginUser = new User ( ) ;
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
long projectCode = 2L ;
Project project = getProject ( projectCode ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
List < ProcessDefinition > processDefinitionList = new ArrayList < > ( ) ;
processDefinitionList . add ( processDefinition ) ;
Project test = getProject ( "test" ) ;
Mockito . when ( projectMapper . selectById ( projectId ) ) . thenReturn ( test ) ;
Mockito . when ( processDefineMapper . queryAllDefinitionList ( test . getCode ( ) ) ) . thenReturn ( processDefinitionList ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionAllByProjectId ( projectId ) ;
Mockito . when ( processDefineMapper . queryAllDefinitionList ( projectCode ) ) . thenReturn ( processDefinitionList ) ;
Map < String , Object > successRes = processDefinitionService . queryAllProcessDefinitionByProjectCode ( loginUser , projectCode ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
@Test
public void testViewTree ( ) throws Exception {
public void testViewTree ( ) {
//process definition not exist
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
processDefinition . setProcessDefinitionJson ( SHELL_JSON ) ;
@ -892,9 +878,9 @@ public class ProcessDefinitionServiceTest {
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . ADMIN_USER ) ;
String currentProjectName = "testProject" ;
long currentProjectCode = 1L ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , currentProjectNam e ) ;
putMsg ( result , Status . SUCCESS , currentProjectCod e ) ;
ProcessDefinition shellDefinition2 = new ProcessDefinition ( ) ;
shellDefinition2 . setId ( 46 ) ;
@ -902,10 +888,10 @@ public class ProcessDefinitionServiceTest {
shellDefinition2 . setProjectId ( 2 ) ;
shellDefinition2 . setProcessDefinitionJson ( subProcessJson ) ;
Mockito . when ( projectMapper . queryByName ( currentProjectNam e ) ) . thenReturn ( getProject ( currentProjectNam e ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , getProject ( currentProjectName ) , currentProjectName ) ) . thenReturn ( result ) ;
Mockito . when ( projectMapper . queryByCode ( currentProjectCod e ) ) . thenReturn ( getProject ( currentProjectCod e ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , getProject ( currentProjectCode ) , "test" ) ) . thenReturn ( result ) ;
Map < String , Object > importProcessResult = processDefinitionService . importProcessDefinition ( loginUser , multipartFile , currentProjectNam e) ;
Map < String , Object > importProcessResult = processDefinitionService . importProcessDefinition ( loginUser , currentProjectCode , multipartFil e) ;
Assert . assertEquals ( Status . SUCCESS , importProcessResult . get ( Constants . STATUS ) ) ;
@ -923,13 +909,13 @@ public class ProcessDefinitionServiceTest {
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS ) ;
String projectName = "project_test1" ;
Project project = getProject ( projectNam e ) ;
long projectCode = 1L ;
Project project = getProject ( projectCod e ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
String sqlDependentJson = "{\n"
+ " \"globalParams\": [\n"
@ -1020,7 +1006,7 @@ public class ProcessDefinitionServiceTest {
+ " \"tenantId\": 1,\n"
+ " \"timeout\": 0\n"
+ "}" ;
Map < String , Object > updateResult = processDefinitionService . updateProcessDefinition ( loginUser , projectNam e , "test" , 1 ,
Map < String , Object > updateResult = processDefinitionService . updateProcessDefinition ( loginUser , projectCod e , "test" , 1 ,
"" , "" , "" , "" , 0 , "root" , sqlDependentJson ) ;
Assert . assertEquals ( Status . DATA_IS_NOT_VALID , updateResult . get ( Constants . STATUS ) ) ;
@ -1029,7 +1015,7 @@ public class ProcessDefinitionServiceTest {
@Test
public void testBatchExportProcessDefinitionByIds ( ) throws IOException {
processDefinitionService . batchExportProcessDefinitionByIds (
null , null , null , null ) ;
null , 1L , null , null ) ;
String processDefinitionJson = "{\"globalParams\":[],\"tasks\":[{\"conditionResult\":"
+ "{\"failedNode\":[\"\"],\"successNode\":[\"\"]},\"delayTime\":\"0\",\"dependence\":{}"
@ -1042,24 +1028,24 @@ public class ProcessDefinitionServiceTest {
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . ADMIN_USER ) ;
String projectName = "project_test1" ;
Project project = getProject ( projectNam e ) ;
long projectCode = 1L ;
Project project = getProject ( projectCod e ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUNT ) ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( getProject ( projectNam e ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( result ) ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( getProject ( projectCod e ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( result ) ;
processDefinitionService . batchExportProcessDefinitionByIds (
loginUser , projectNam e , "1" , null ) ;
loginUser , projectCod e , "1" , null ) ;
ProcessDefinition processDefinition = new ProcessDefinition ( ) ;
processDefinition . setId ( 1 ) ;
processDefinition . setProcessDefinitionJson ( processDefinitionJson ) ;
Map < String , Object > checkResult = new HashMap < > ( ) ;
checkResult . put ( Constants . STATUS , Status . SUCCESS ) ;
Mockito . when ( projectMapper . queryByName ( projectNam e ) ) . thenReturn ( project ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectName ) ) . thenReturn ( checkResult ) ;
Mockito . when ( projectMapper . queryByCode ( projectCod e ) ) . thenReturn ( project ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . get Name( ) ) ) . thenReturn ( checkResult ) ;
Mockito . when ( processDefineMapper . queryByDefineId ( 1 ) ) . thenReturn ( processDefinition ) ;
HttpServletResponse response = mock ( HttpServletResponse . class ) ;
@ -1069,7 +1055,7 @@ public class ProcessDefinitionServiceTest {
ServletOutputStream outputStream = mock ( ServletOutputStream . class ) ;
when ( response . getOutputStream ( ) ) . thenReturn ( outputStream ) ;
processDefinitionService . batchExportProcessDefinitionByIds (
loginUser , projectNam e , "1" , response ) ;
loginUser , projectCod e , "1" , response ) ;
Assert . assertNotNull ( processDefinitionService . exportProcessMetaData ( processDefinition ) ) ;
}
@ -1093,6 +1079,7 @@ public class ProcessDefinitionServiceTest {
private ProcessDefinition getProcessDefinition ( ) {
ProcessDefinition processDefinition = new ProcessDefinition ( ) ;
processDefinition . setId ( 46 ) ;
processDefinition . setProjectCode ( 1L ) ;
processDefinition . setName ( "test_pdf" ) ;
processDefinition . setProjectId ( 2 ) ;
processDefinition . setTenantId ( 1 ) ;
@ -1105,18 +1092,28 @@ public class ProcessDefinitionServiceTest {
/ * *
* get mock Project
*
* @param projectName projectNam e
* @param projectCode projectCod e
* @return Project
* /
private Project getProject ( String projectNam e) {
private Project getProject ( long projectCod e) {
Project project = new Project ( ) ;
project . setCode ( 1L ) ;
project . setCode ( projectCode ) ;
project . setId ( 1 ) ;
project . setName ( projectName ) ;
project . setName ( "test" ) ;
project . setUserId ( 1 ) ;
return project ;
}
private List < ProcessTaskRelation > getProcessTaskRelation ( long projectCode , long processCode ) {
List < ProcessTaskRelation > processTaskRelations = new ArrayList < > ( ) ;
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation ( ) ;
processTaskRelation . setProjectCode ( projectCode ) ;
processTaskRelation . setProcessDefinitionCode ( processCode ) ;
processTaskRelation . setProcessDefinitionVersion ( 1 ) ;
processTaskRelations . add ( processTaskRelation ) ;
return processTaskRelations ;
}
/ * *
* get mock Project
*