Skip to content

Commit

Permalink
add UT for (#15676)
Browse files Browse the repository at this point in the history
  • Loading branch information
wustlz committed Mar 12, 2024
1 parent dc142f7 commit a26b825
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@
import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao;
import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao;
import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager;
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.DataType;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.DqTaskState;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.ExecuteSqlType;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.InputType;
import org.apache.dolphinscheduler.plugin.task.api.enums.dp.OptionSourceType;
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
import org.apache.dolphinscheduler.service.cron.CronUtilsTest;
import org.apache.dolphinscheduler.service.exceptions.CronParseException;
Expand All @@ -89,6 +91,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -532,6 +535,31 @@ public void getDqExecuteSql() {
Assertions.assertNotNull(processService.getDqExecuteSql(1));
}

@Test
public void testSetGlobalParamIfCommanded() {
ProcessDefinition processDefinition = new ProcessDefinition();
String globalParams = "[{\"prop\":\"global_param\",\"value\":\"4\",\"direct\":\"IN\",\"type\":\"VARCHAR\"},{\"prop\":\"O_ERRCODE\",\"value\":\"\",\"direct\":\"OUT\",\"type\":\"VARCHAR\"}]";
processDefinition.setGlobalParams(globalParams);
Map<String, String> globalParamMap = processDefinition.getGlobalParamMap();
Assertions.assertTrue(globalParamMap.size() == 2);
Assertions.assertTrue(processDefinition.getGlobalParamList().size() == 2);

HashMap<String, String> startParams = new HashMap<>();
String expectValue = "6";
startParams.put("global_param", expectValue);
HashMap<String, String> commandParams = new HashMap<>();
commandParams.put(CMD_PARAM_START_PARAMS, JSONUtils.toJsonString(startParams));
Map<String, Property> mockStartParams = new HashMap<>();

mockStartParams.put("global_param", new Property("global_param", Direct.IN,
org.apache.dolphinscheduler.plugin.task.api.enums.DataType.VARCHAR, startParams.get("global_param")));
when(curingGlobalParamsService.parseWorkflowStartParam(commandParams)).thenReturn(mockStartParams);

processService.setGlobalParamIfCommanded(processDefinition, commandParams);
Assertions.assertTrue(globalParamMap.get("global_param").equals(expectValue));
Assertions.assertTrue(globalParamMap.containsKey("O_ERRCODE"));
}

private List<DqRuleInputEntry> getRuleInputEntryList() {
List<DqRuleInputEntry> list = new ArrayList<>();

Expand Down

0 comments on commit a26b825

Please sign in to comment.