@ -37,6 +37,7 @@ import org.apache.dolphinscheduler.service.process.ProcessService;
import java.text.MessageFormat ;
import java.text.MessageFormat ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import org.junit.Assert ;
import org.junit.Assert ;
@ -49,7 +50,6 @@ import org.mockito.junit.MockitoJUnitRunner;
@RunWith ( MockitoJUnitRunner . class )
@RunWith ( MockitoJUnitRunner . class )
public class TaskDefinitionServiceImplTest {
public class TaskDefinitionServiceImplTest {
String taskDefinitionJson = "{\n"
String taskDefinitionJson = "{\n"
+ " \"type\": \"SQL\",\n"
+ " \"type\": \"SQL\",\n"
+ " \"id\": \"tasks-27297\",\n"
+ " \"id\": \"tasks-27297\",\n"
@ -132,16 +132,34 @@ public class TaskDefinitionServiceImplTest {
putMsg ( result , Status . SUCCESS , projectCode ) ;
putMsg ( result , Status . SUCCESS , projectCode ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
Mockito . when ( projectService . checkProjectAndAuth ( loginUser , project , project . getName ( ) ) ) . thenReturn ( result ) ;
TaskNode taskNode = JSONUtils . parseObject ( taskDefinitionJson , TaskNode . class ) ;
String createTaskDefinitionJson = "[{\n"
+ "\"name\": \"test12111\",\n"
Mockito . when ( processService . saveTaskDefinition ( Mockito . eq ( loginUser )
+ "\"description\": \"test\",\n"
, Mockito . eq ( project . getCode ( ) )
+ "\"taskType\": \"SHELL\",\n"
, Mockito . eq ( taskNode )
+ "\"flag\": 0,\n"
, Mockito . any ( TaskDefinition . class ) ) )
+ "\"taskParams\": \n"
. thenReturn ( 1 ) ;
+ "\"{\\\"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
Map < String , Object > relation = taskDefinitionService
. createTaskDefinition ( loginUser , projectCode , taskDefinitionJson ) ;
. createTaskDefinition ( loginUser , projectCode , crea teT askDefinitionJson) ;
Assert . assertEquals ( Status . SUCCESS , relation . get ( Constants . STATUS ) ) ;
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
@Test
public void switchVersion ( ) {
public void switchVersion ( ) {
int version = 1 ;
int version = 1 ;