@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.api.service ;
package org.apache.dolphinscheduler.api.service ;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.* ;
import static org.powermock.api.mockito.PowerMockito.mock ;
import static org.powermock.api.mockito.PowerMockito.mock ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.enums.Status ;
@ -147,13 +148,13 @@ public class ProcessDefinitionServiceTest {
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
//project not found
//project not found
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionList ( loginUser , projectCode ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionList ( loginUser , projectCode ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
//project check auth success
//project check auth success
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
List < ProcessDefinition > resourceList = new ArrayList < > ( ) ;
List < ProcessDefinition > resourceList = new ArrayList < > ( ) ;
resourceList . add ( getProcessDefinition ( ) ) ;
resourceList . add ( getProcessDefinition ( ) ) ;
Mockito . when ( processDefineMapper . queryAllDefinitionList ( project . getCode ( ) ) ) . thenReturn ( resourceList ) ;
Mockito . when ( processDefineMapper . queryAllDefinitionList ( project . getCode ( ) ) ) . thenReturn ( resourceList ) ;
@ -177,13 +178,13 @@ public class ProcessDefinitionServiceTest {
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
//project not found
//project not found
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Result map = processDefinitionService . queryProcessDefinitionListPaging ( loginUser , projectCode , "" , 1 , 5 , 0 ) ;
Result map = processDefinitionService . queryProcessDefinitionListPaging ( loginUser , projectCode , "" , 1 , 5 , 0 ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND . getCode ( ) , ( int ) map . getCode ( ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND . getCode ( ) , ( int ) map . getCode ( ) ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
loginUser . setId ( 1 ) ;
loginUser . setId ( 1 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Page < ProcessDefinition > page = new Page < > ( 1 , 10 ) ;
Page < ProcessDefinition > page = new Page < > ( 1 , 10 ) ;
page . setTotal ( 30 ) ;
page . setTotal ( 30 ) ;
Mockito . when ( processDefineMapper . queryDefineListPaging (
Mockito . when ( processDefineMapper . queryDefineListPaging (
@ -216,13 +217,13 @@ public class ProcessDefinitionServiceTest {
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
//project check auth fail
//project check auth fail
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByCode ( loginUser , 1L , 1L ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByCode ( loginUser , 1L , 1L ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
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 ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
DagData dagData = new DagData ( getProcessDefinition ( ) , null , null ) ;
DagData dagData = new DagData ( getProcessDefinition ( ) , null , null ) ;
Mockito . when ( processService . genDagData ( Mockito . any ( ) ) ) . thenReturn ( dagData ) ;
Mockito . when ( processService . genDagData ( Mockito . any ( ) ) ) . thenReturn ( dagData ) ;
@ -232,7 +233,7 @@ public class ProcessDefinitionServiceTest {
//instance exit
//instance exit
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( getProcessDefinition ( ) ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( getProcessDefinition ( ) ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Mockito . when ( tenantMapper . queryById ( 1 ) ) . thenReturn ( tenant ) ;
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 ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
@ -253,13 +254,13 @@ public class ProcessDefinitionServiceTest {
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
//project check auth fail
//project check auth fail
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByName ( loginUser , projectCode , "test_def" ) ;
Map < String , Object > map = processDefinitionService . queryProcessDefinitionByName ( loginUser , projectCode , "test_def" ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
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 ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Mockito . when ( processDefineMapper . queryByDefineName ( project . getCode ( ) , "test_def" ) ) . thenReturn ( null ) ;
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" ) ;
@ -268,7 +269,7 @@ public class ProcessDefinitionServiceTest {
//instance exit
//instance exit
Mockito . when ( processDefineMapper . queryByDefineName ( project . getCode ( ) , "test" ) ) . thenReturn ( getProcessDefinition ( ) ) ;
Mockito . when ( processDefineMapper . queryByDefineName ( project . getCode ( ) , "test" ) ) . thenReturn ( getProcessDefinition ( ) ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionByName ( loginUser , projectCode , "test" ) ;
Map < String , Object > successRes = processDefinitionService . queryProcessDefinitionByName ( loginUser , projectCode , "test" ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , successRes . get ( Constants . STATUS ) ) ;
}
}
@ -283,7 +284,7 @@ public class ProcessDefinitionServiceTest {
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_BATCH_COPY ) ) . thenReturn ( result ) ;
// copy project definition ids empty test
// 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 ) ;
@ -291,7 +292,7 @@ public class ProcessDefinitionServiceTest {
// project check auth fail
// project check auth fail
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_BATCH_COPY ) ) . thenReturn ( result ) ;
Map < String , Object > map1 = processDefinitionService . batchCopyProcessDefinition (
Map < String , Object > map1 = processDefinitionService . batchCopyProcessDefinition (
loginUser , projectCode , String . valueOf ( project . getId ( ) ) , 2L ) ;
loginUser , projectCode , String . valueOf ( project . getId ( ) ) , 2L ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map1 . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map1 . get ( Constants . STATUS ) ) ;
@ -300,7 +301,7 @@ public class ProcessDefinitionServiceTest {
projectCode = 2L ;
projectCode = 2L ;
Project project1 = getProject ( projectCode ) ;
Project project1 = getProject ( projectCode ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project1 ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project1 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_BATCH_COPY ) ) . thenReturn ( result ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
ProcessDefinition definition = getProcessDefinition ( ) ;
ProcessDefinition definition = getProcessDefinition ( ) ;
@ -331,8 +332,8 @@ public class ProcessDefinitionServiceTest {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project1 , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project1 , projectCode , TASK_DEFINITION_MOVE ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project2 , projectCode2 ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project2 , projectCode2 , TASK_DEFINITION_MOVE ) ) . thenReturn ( result ) ;
ProcessDefinition definition = getProcessDefinition ( ) ;
ProcessDefinition definition = getProcessDefinition ( ) ;
definition . setVersion ( 1 ) ;
definition . setVersion ( 1 ) ;
@ -362,20 +363,20 @@ public class ProcessDefinitionServiceTest {
//project check auth fail
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION_DELETE ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . deleteProcessDefinitionByCode ( loginUser , projectCode , 6L ) ;
Map < String , Object > map = processDefinitionService . deleteProcessDefinitionByCode ( loginUser , projectCode , 6L ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
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 ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION_DELETE ) ) . thenReturn ( result ) ;
Mockito . when ( processDefineMapper . queryByCode ( 1L ) ) . thenReturn ( null ) ;
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 ) ) ;
Assert . assertEquals ( Status . PROCESS_DEFINE_NOT_EXIST , instanceNotExitRes . get ( Constants . STATUS ) ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION_DELETE ) ) . thenReturn ( result ) ;
//user no auth
//user no auth
loginUser . setUserType ( UserType . GENERAL_USER ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
@ -385,7 +386,6 @@ public class ProcessDefinitionServiceTest {
//process definition online
//process definition online
loginUser . setUserType ( UserType . ADMIN_USER ) ;
loginUser . setUserType ( UserType . ADMIN_USER ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
processDefinition . setReleaseState ( ReleaseState . ONLINE ) ;
processDefinition . setReleaseState ( ReleaseState . ONLINE ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Map < String , Object > dfOnlineRes = processDefinitionService . deleteProcessDefinitionByCode ( loginUser , projectCode , 46L ) ;
Map < String , Object > dfOnlineRes = processDefinitionService . deleteProcessDefinitionByCode ( loginUser , projectCode , 46L ) ;
@ -395,7 +395,6 @@ public class ProcessDefinitionServiceTest {
processDefinition . setReleaseState ( ReleaseState . OFFLINE ) ;
processDefinition . setReleaseState ( ReleaseState . OFFLINE ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionCode ( 46L ) ) . thenReturn ( getSchedule ( ) ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionCode ( 46L ) ) . thenReturn ( getSchedule ( ) ) ;
Mockito . when ( scheduleMapper . deleteById ( 46 ) ) . thenReturn ( 1 ) ;
Mockito . when ( scheduleMapper . deleteById ( 46 ) ) . thenReturn ( 1 ) ;
Mockito . when ( processDefineMapper . deleteById ( processDefinition . getId ( ) ) ) . thenReturn ( 1 ) ;
Mockito . when ( processDefineMapper . deleteById ( processDefinition . getId ( ) ) ) . thenReturn ( 1 ) ;
@ -407,7 +406,6 @@ public class ProcessDefinitionServiceTest {
Schedule schedule = getSchedule ( ) ;
Schedule schedule = getSchedule ( ) ;
schedule . setReleaseState ( ReleaseState . ONLINE ) ;
schedule . setReleaseState ( ReleaseState . ONLINE ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionCode ( 46L ) ) . thenReturn ( schedule ) ;
Mockito . when ( scheduleMapper . queryByProcessDefinitionCode ( 46L ) ) . thenReturn ( schedule ) ;
Map < String , Object > schedulerOnlineRes = processDefinitionService . deleteProcessDefinitionByCode ( loginUser , projectCode , 46L ) ;
Map < String , Object > schedulerOnlineRes = processDefinitionService . deleteProcessDefinitionByCode ( loginUser , projectCode , 46L ) ;
Assert . assertEquals ( Status . SCHEDULE_CRON_STATE_ONLINE , schedulerOnlineRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SCHEDULE_CRON_STATE_ONLINE , schedulerOnlineRes . get ( Constants . STATUS ) ) ;
@ -419,7 +417,6 @@ public class ProcessDefinitionServiceTest {
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 ( scheduleMapper . queryByProcessDefinitionCode ( 46L ) ) . thenReturn ( getSchedule ( ) ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
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 ) ) ;
Assert . assertEquals ( Status . SUCCESS , deleteSuccess . get ( Constants . STATUS ) ) ;
}
}
@ -438,7 +435,7 @@ public class ProcessDefinitionServiceTest {
//project check auth fail
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , null ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . releaseProcessDefinition ( loginUser , projectCode ,
Map < String , Object > map = processDefinitionService . releaseProcessDefinition ( loginUser , projectCode ,
6 , ReleaseState . OFFLINE ) ;
6 , ReleaseState . OFFLINE ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
@ -482,7 +479,7 @@ public class ProcessDefinitionServiceTest {
//project check auth fail
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , null ) ) . thenReturn ( result ) ;
Map < String , Object > map = processDefinitionService . verifyProcessDefinitionName ( loginUser ,
Map < String , Object > map = processDefinitionService . verifyProcessDefinitionName ( loginUser ,
projectCode , "test_pdf" ) ;
projectCode , "test_pdf" ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . PROJECT_NOT_FOUND , map . get ( Constants . STATUS ) ) ;
@ -525,7 +522,7 @@ public class ProcessDefinitionServiceTest {
//project check auth fail
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , null ) ) . thenReturn ( result ) ;
//process definition not exist
//process definition not exist
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( null ) ;
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 ) ;
@ -553,7 +550,7 @@ public class ProcessDefinitionServiceTest {
//project check auth fail
//project check auth fail
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , null ) ) . thenReturn ( result ) ;
//process definition not exist
//process definition not exist
String defineCodes = "46" ;
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 ( ) ) ;
@ -587,7 +584,7 @@ public class ProcessDefinitionServiceTest {
Project project = getProject ( projectCode ) ;
Project project = getProject ( projectCode ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_DEFINITION ) ) . thenReturn ( result ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
List < ProcessDefinition > processDefinitionList = new ArrayList < > ( ) ;
List < ProcessDefinition > processDefinitionList = new ArrayList < > ( ) ;
processDefinitionList . add ( processDefinition ) ;
processDefinitionList . add ( processDefinition ) ;
@ -598,28 +595,51 @@ public class ProcessDefinitionServiceTest {
@Test
@Test
public void testViewTree ( ) {
public void testViewTree ( ) {
User loginUser = new User ( ) ;
loginUser . setId ( 1 ) ;
loginUser . setTenantId ( 1 ) ;
loginUser . setUserType ( UserType . ADMIN_USER ) ;
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
//process definition not exist
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
Map < String , Object > processDefinitionNullRes = processDefinitionService . viewTree ( 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 ) ) ;
Assert . assertEquals ( Status . PROCESS_DEFINE_NOT_EXIST , processDefinitionNullRes . get ( Constants . STATUS ) ) ;
//task instance not exist
//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 ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Mockito . when ( processService . genDagGraph ( processDefinition ) ) . thenReturn ( new DAG < > ( ) ) ;
Mockito . when ( processService . genDagGraph ( processDefinition ) ) . thenReturn ( new DAG < > ( ) ) ;
Map < String , Object > taskNullRes = processDefinitionService . viewTree ( processDefinition . getProjectCode ( ) , 46 , 10 ) ;
Map < String , Object > taskNullRes = processDefinitionService . viewTree ( loginUser , processDefinition . getProjectCode ( ) , 46 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , taskNullRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , taskNullRes . get ( Constants . STATUS ) ) ;
//task instance exist
//task instance exist
Map < String , Object > taskNotNuLLRes = processDefinitionService . viewTree ( processDefinition . getProjectCode ( ) , 46 , 10 ) ;
Map < String , Object > taskNotNuLLRes = processDefinitionService . viewTree ( loginUser , processDefinition . getProjectCode ( ) , 46 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , taskNotNuLLRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , taskNotNuLLRes . get ( Constants . STATUS ) ) ;
}
}
@Test
@Test
public void testSubProcessViewTree ( ) {
public void testSubProcessViewTree ( ) {
User loginUser = new User ( ) ;
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . ADMIN_USER ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
ProcessDefinition processDefinition = getProcessDefinition ( ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Mockito . when ( processDefineMapper . queryByCode ( 46L ) ) . thenReturn ( processDefinition ) ;
Project project1 = getProject ( 1 ) ;
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , Status . SUCCESS ) ;
Mockito . when ( projectMapper . queryByCode ( 1 ) ) . thenReturn ( project1 ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project1 , 1 , WORKFLOW_TREE_VIEW ) ) . thenReturn ( result ) ;
Mockito . when ( processService . genDagGraph ( processDefinition ) ) . thenReturn ( new DAG < > ( ) ) ;
Mockito . when ( processService . genDagGraph ( processDefinition ) ) . thenReturn ( new DAG < > ( ) ) ;
Map < String , Object > taskNotNuLLRes = processDefinitionService . viewTree ( processDefinition . getProjectCode ( ) , 46 , 10 ) ;
Map < String , Object > taskNotNuLLRes = processDefinitionService . viewTree ( loginUser , processDefinition . getProjectCode ( ) , 46 , 10 ) ;
Assert . assertEquals ( Status . SUCCESS , taskNotNuLLRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , taskNotNuLLRes . get ( Constants . STATUS ) ) ;
}
}
@ -635,7 +655,7 @@ public class ProcessDefinitionServiceTest {
long projectCode = 1L ;
long projectCode = 1L ;
Project project = getProject ( projectCode ) ;
Project project = getProject ( projectCode ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode , WORKFLOW_UPDATE ) ) . thenReturn ( result ) ;
Map < String , Object > updateResult = processDefinitionService . updateProcessDefinition ( loginUser , projectCode , "test" , 1 ,
Map < String , Object > updateResult = processDefinitionService . updateProcessDefinition ( loginUser , projectCode , "test" , 1 ,
"" , "" , "" , 0 , "root" , null , null , ProcessExecutionTypeEnum . PARALLEL ) ;
"" , "" , "" , 0 , "root" , null , null , ProcessExecutionTypeEnum . PARALLEL ) ;
@ -656,8 +676,6 @@ public class ProcessDefinitionServiceTest {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND ) ;
putMsg ( result , Status . PROJECT_NOT_FOUND ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( getProject ( projectCode ) ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( result ) ;
processDefinitionService . batchExportProcessDefinitionByCodes (
processDefinitionService . batchExportProcessDefinitionByCodes (
loginUser , projectCode , "1" , null ) ;
loginUser , projectCode , "1" , null ) ;
@ -666,7 +684,6 @@ public class ProcessDefinitionServiceTest {
Map < String , Object > checkResult = new HashMap < > ( ) ;
Map < String , Object > checkResult = new HashMap < > ( ) ;
checkResult . put ( Constants . STATUS , Status . SUCCESS ) ;
checkResult . put ( Constants . STATUS , Status . SUCCESS ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , projectCode ) ) . thenReturn ( checkResult ) ;
HttpServletResponse response = mock ( HttpServletResponse . class ) ;
HttpServletResponse response = mock ( HttpServletResponse . class ) ;
DagData dagData = new DagData ( getProcessDefinition ( ) , null , null ) ;
DagData dagData = new DagData ( getProcessDefinition ( ) , null , null ) ;
@ -704,12 +721,16 @@ public class ProcessDefinitionServiceTest {
Mockito . when ( dataSourceMapper . queryDataSourceByNameAndUserId ( userId , "mysql_1" ) ) . thenReturn ( dataSource ) ;
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 . 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 . 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 . when ( processService . saveTaskRelation ( Mockito . same ( loginUser ) , Mockito . eq ( projectCode ) , Mockito . anyLong ( ) ,
Mockito . eq ( 1 ) , Mockito . notNull ( ) , Mockito . notNull ( ) , Mockito . anyBoolean ( ) ) ) . thenReturn ( 0 ) ;
Mockito . eq ( 1 ) , Mockito . notNull ( ) , Mockito . notNull ( ) , Mockito . anyBoolean ( ) ) ) . thenReturn ( 0 ) ;
result = processDefinitionService . importSqlProcessDefinition ( loginUser , projectCode , mockMultipartFile ) ;
Map < String , Object > result = processDefinitionService . importSqlProcessDefinition ( loginUser , projectCode , mockMultipartFile ) ;
Assert . assertEquals ( result . get ( Constants . STATUS ) , Status . SUCCESS ) ;
Assert . assertEquals ( result . get ( Constants . STATUS ) , Status . SUCCESS ) ;
}
}