@ -37,6 +37,7 @@ import org.apache.dolphinscheduler.service.process.ProcessService;
import java.text.MessageFormat ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import org.junit.Assert ;
@ -49,7 +50,6 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith ( MockitoJUnitRunner . class )
public class TaskDefinitionServiceImplTest {
String taskDefinitionJson = "{\n"
+ " \"type\": \"SQL\",\n"
+ " \"id\": \"tasks-27297\",\n"
@ -132,16 +132,34 @@ public class TaskDefinitionServiceImplTest {
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
TaskNode taskNode = JSONUtils . parseObject ( taskDefinitionJson , TaskNode . class ) ;
Mockito . when ( processService . saveTaskDefinition ( Mockito . eq ( loginUser )
, Mockito . eq ( project . getCode ( ) )
, Mockito . eq ( taskNode )
, Mockito . any ( TaskDefinition . class ) ) )
. thenReturn ( 1 ) ;
String createTaskDefinitionJson = "[{\n"
+ "\"name\": \"test12111\",\n"
+ "\"description\": \"test\",\n"
+ "\"taskType\": \"SHELL\",\n"
+ "\"flag\": 0,\n"
+ "\"taskParams\": \n"
+ "\"{\\\"resourceList\\\":[],\n"
+ "\\\"localParams\\\":[],\n"
+ "\\\"rawScript\\\":\\\"echo 11\\\",\n"
+ "\\\"conditionResult\\\":\n"
+ "{\\\"successNode\\\":[\\\"\\\"],\n"
+ "\\\"failedNode\\\":[\\\"\\\"]},\n"
+ "\\\"dependence\\\":{}}\",\n"
+ "\"taskPriority\": 0,\n"
+ "\"workerGroup\": \"default\",\n"
+ "\"failRetryTimes\": 0,\n"
+ "\"failRetryInterval\": 1,\n"
+ "\"timeoutFlag\": 1, \n"
+ "\"timeoutNotifyStrategy\": 0,\n"
+ "\"timeout\": 0, \n"
+ "\"delayTime\": 0,\n"
+ "\"resourceIds\":\"\" \n"
+ "}] " ;
List < TaskDefinition > taskDefinitions = JSONUtils . toList ( createTaskDefinitionJson , TaskDefinition . class ) ;
Mockito . when ( taskDefinitionMapper . batchInsert ( Mockito . anyList ( ) ) ) . thenReturn ( 1 ) ;
Mockito . when ( taskDefinitionLogMapper . batchInsert ( Mockito . anyList ( ) ) ) . thenReturn ( 1 ) ;
Map < String , Object > relation = taskDefinitionService
. createTaskDefinition ( loginUser , projectCode , taskDefinitionJson ) ;
. createTaskDefinition ( loginUser , projectCode , crea teT askDefinitionJson) ;
Assert . assertEquals ( Status . SUCCESS , relation . get ( Constants . STATUS ) ) ;
@ -201,38 +219,6 @@ public class TaskDefinitionServiceImplTest {
}
@Test
public void updateTaskDefinition ( ) {
long projectCode = 1L ;
Project project = getProject ( projectCode ) ;
Mockito . when ( projectMapper . queryByCode ( projectCode ) ) . thenReturn ( project ) ;
User loginUser = new User ( ) ;
loginUser . setId ( - 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
Map < String , Object > result = new HashMap < > ( ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
TaskNode taskNode = JSONUtils . parseObject ( taskDefinitionJson , TaskNode . class ) ;
Mockito . when ( processService . updateTaskDefinition ( Mockito . eq ( loginUser )
, Mockito . eq ( project . getCode ( ) )
, Mockito . eq ( taskNode )
, Mockito . any ( TaskDefinition . class ) ) )
. thenReturn ( 1 ) ;
Mockito . when ( taskDefinitionMapper . queryByDefinitionCode ( 11L ) )
. thenReturn ( new TaskDefinition ( ) ) ;
Map < String , Object > relation = taskDefinitionService
. updateTaskDefinition ( loginUser , projectCode , 11L , taskDefinitionJson ) ;
Assert . assertEquals ( Status . SUCCESS , relation . get ( Constants . STATUS ) ) ;
}
@Test
public void switchVersion ( ) {
int version = 1 ;