|
42 | 42 | import org.apache.dolphinscheduler.common.model.TaskNodeRelation; |
43 | 43 | import org.apache.dolphinscheduler.common.utils.DateUtils; |
44 | 44 | import org.apache.dolphinscheduler.common.utils.JSONUtils; |
| 45 | +import org.apache.dolphinscheduler.dao.AlertDao; |
45 | 46 | import org.apache.dolphinscheduler.dao.entity.DependentResultTaskInstanceContext; |
46 | 47 | import org.apache.dolphinscheduler.dao.entity.Project; |
47 | 48 | import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
56 | 57 | import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; |
57 | 58 | import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
58 | 59 | import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
| 60 | +import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; |
59 | 61 | import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
60 | 62 | import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper; |
61 | 63 | import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionMapper; |
62 | 64 | import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; |
63 | 65 | import org.apache.dolphinscheduler.dao.repository.TaskInstanceContextDao; |
64 | 66 | import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; |
65 | 67 | import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; |
| 68 | +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceMapDao; |
66 | 69 | import org.apache.dolphinscheduler.extract.master.command.RunWorkflowCommandParam; |
67 | 70 | import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager; |
68 | 71 | import org.apache.dolphinscheduler.plugin.task.api.enums.DataType; |
69 | 72 | import org.apache.dolphinscheduler.plugin.task.api.enums.DependResult; |
70 | 73 | import org.apache.dolphinscheduler.plugin.task.api.enums.Direct; |
71 | 74 | import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; |
72 | 75 | import org.apache.dolphinscheduler.plugin.task.api.model.Property; |
| 76 | +import org.apache.dolphinscheduler.service.expand.CuringParamsService; |
73 | 77 | import org.apache.dolphinscheduler.service.model.TaskNode; |
74 | 78 | import org.apache.dolphinscheduler.service.process.ProcessService; |
75 | 79 |
|
76 | 80 | import java.io.IOException; |
77 | 81 | import java.text.MessageFormat; |
78 | 82 | import java.util.ArrayList; |
| 83 | +import java.util.Calendar; |
79 | 84 | import java.util.Date; |
80 | 85 | import java.util.HashMap; |
81 | 86 | import java.util.List; |
@@ -145,6 +150,21 @@ public class WorkflowInstanceServiceTest { |
145 | 150 | @Mock |
146 | 151 | private TaskInstanceContextDao taskInstanceContextDao; |
147 | 152 |
|
| 153 | + @Mock |
| 154 | + TaskInstanceMapper taskInstanceMapper; |
| 155 | + |
| 156 | + @Mock |
| 157 | + CuringParamsService curingGlobalParamsService; |
| 158 | + |
| 159 | + @Mock |
| 160 | + TaskInstanceService taskInstanceService; |
| 161 | + |
| 162 | + @Mock |
| 163 | + WorkflowInstanceMapDao workflowInstanceMapDao; |
| 164 | + |
| 165 | + @Mock |
| 166 | + AlertDao alertDao; |
| 167 | + |
148 | 168 | private String shellJson = "[{\"name\":\"\",\"preTaskCode\":0,\"preTaskVersion\":0,\"postTaskCode\":123456789," |
149 | 169 | + "\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"},{\"name\":\"\",\"preTaskCode\":123456789," |
150 | 170 | + "\"preTaskVersion\":1,\"postTaskCode\":123451234,\"postTaskVersion\":1,\"conditionType\":0,\"conditionParams\":\"{}\"}]"; |
@@ -768,6 +788,89 @@ public void testViewVariables() { |
768 | 788 | Assertions.assertEquals(Status.WORKFLOW_INSTANCE_NOT_EXIST, processNotExist.get(Constants.STATUS)); |
769 | 789 | } |
770 | 790 |
|
| 791 | + @Test |
| 792 | + public void testViewVariables_WithTimePlaceholders() { |
| 793 | + String globalParamsJson = "[{\"prop\":\"biz_date\",\"value\":\"$[yyyyMMdd]\",\"type\":\"VARCHAR\"}," + |
| 794 | + "{\"prop\":\"env\",\"value\":\"${ENV_TYPE}\",\"type\":\"VARCHAR\"}]"; |
| 795 | + |
| 796 | + WorkflowInstance workflowInstance = getProcessInstance(); |
| 797 | + workflowInstance.setId(1); |
| 798 | + workflowInstance.setCommandType(CommandType.SCHEDULER); |
| 799 | + |
| 800 | + Calendar calendar = Calendar.getInstance(); |
| 801 | + calendar.set(2026, Calendar.MARCH, 13, 10, 0, 0); |
| 802 | + workflowInstance.setScheduleTime(calendar.getTime()); |
| 803 | + workflowInstance.setGlobalParams(globalParamsJson); |
| 804 | + workflowInstance.setWorkflowDefinitionCode(100L); |
| 805 | + |
| 806 | + when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance); |
| 807 | + |
| 808 | + WorkflowDefinition workflowDefinition = new WorkflowDefinition(); |
| 809 | + workflowDefinition.setCode(100L); |
| 810 | + workflowDefinition.setProjectCode(1L); |
| 811 | + when(workflowDefinitionMapper.queryByCode(100L)).thenReturn(workflowDefinition); |
| 812 | + |
| 813 | + Map<String, Object> result = workflowInstanceService.viewVariables(1L, 1); |
| 814 | + |
| 815 | + Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
| 816 | + |
| 817 | + Map<String, Object> dataList = (Map<String, Object>) result.get(Constants.DATA_LIST); |
| 818 | + Assertions.assertNotNull(dataList); |
| 819 | + |
| 820 | + List<Property> globalParams = (List<Property>) dataList.get(Constants.GLOBAL_PARAMS); |
| 821 | + Assertions.assertNotNull(globalParams); |
| 822 | + Assertions.assertEquals(2, globalParams.size()); |
| 823 | + |
| 824 | + Property dateParam = globalParams.stream() |
| 825 | + .filter(p -> "biz_date".equals(p.getProp())) |
| 826 | + .findFirst() |
| 827 | + .orElse(null); |
| 828 | + Assertions.assertNotNull(dateParam); |
| 829 | + Assertions.assertEquals("20260313", dateParam.getValue(), |
| 830 | + "Time placeholder $[yyyyMMdd] should be replaced with schedule time"); |
| 831 | + |
| 832 | + Property envParam = globalParams.stream() |
| 833 | + .filter(p -> "env".equals(p.getProp())) |
| 834 | + .findFirst() |
| 835 | + .orElse(null); |
| 836 | + Assertions.assertNotNull(envParam); |
| 837 | + } |
| 838 | + |
| 839 | + @Test |
| 840 | + public void testViewVariables_InstanceNotFound() { |
| 841 | + when(workflowInstanceMapper.queryDetailById(999)).thenReturn(null); |
| 842 | + |
| 843 | + Map<String, Object> result = workflowInstanceService.viewVariables(1L, 999); |
| 844 | + |
| 845 | + Assertions.assertEquals(Status.WORKFLOW_INSTANCE_NOT_EXIST, result.get(Constants.STATUS)); |
| 846 | + Assertions.assertNull(result.get(Constants.DATA_LIST)); |
| 847 | + } |
| 848 | + |
| 849 | + @Test |
| 850 | + public void testViewVariables_EmptyGlobalParams() { |
| 851 | + WorkflowInstance workflowInstance = getProcessInstance(); |
| 852 | + workflowInstance.setId(2); |
| 853 | + workflowInstance.setCommandType(CommandType.START_PROCESS); |
| 854 | + workflowInstance.setScheduleTime(new Date()); |
| 855 | + workflowInstance.setGlobalParams(""); |
| 856 | + workflowInstance.setWorkflowDefinitionCode(101L); |
| 857 | + |
| 858 | + when(workflowInstanceMapper.queryDetailById(2)).thenReturn(workflowInstance); |
| 859 | + |
| 860 | + WorkflowDefinition workflowDefinition = new WorkflowDefinition(); |
| 861 | + workflowDefinition.setCode(101L); |
| 862 | + workflowDefinition.setProjectCode(1L); |
| 863 | + when(workflowDefinitionMapper.queryByCode(101L)).thenReturn(workflowDefinition); |
| 864 | + |
| 865 | + Map<String, Object> result = workflowInstanceService.viewVariables(1L, 2); |
| 866 | + |
| 867 | + Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
| 868 | + |
| 869 | + Map<String, Object> dataList = (Map<String, Object>) result.get(Constants.DATA_LIST); |
| 870 | + List<Property> globalParams = (List<Property>) dataList.get(Constants.GLOBAL_PARAMS); |
| 871 | + Assertions.assertTrue(globalParams.isEmpty(), "Global params list should be empty when input is empty string"); |
| 872 | + } |
| 873 | + |
771 | 874 | @Test |
772 | 875 | public void testViewGantt() throws Exception { |
773 | 876 | WorkflowInstance workflowInstance = getProcessInstance(); |
|
0 commit comments