|
|
@ -17,6 +17,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.plugin.task.api.parser; |
|
|
|
package org.apache.dolphinscheduler.plugin.task.api.parser; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.enums.CommandType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.CommandType; |
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils; |
|
|
@ -30,9 +32,9 @@ import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
public class TimePlaceholderUtilsTest { |
|
|
|
public class TimePlaceholderUtilsTest { |
|
|
|
|
|
|
|
|
|
|
|
Date date = DateUtils.parse("2022-08-26 00:00:00", "yyyy-MM-dd HH:mm:ss"); |
|
|
|
private Date date = DateUtils.parse("2022-08-26 00:00:00", "yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date, null); |
|
|
|
private Map<String, String> timeParams = BusinessTimeUtils.getBusinessTime(CommandType.COMPLEMENT_DATA, date, null); |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void timePlaceHolderForThisDay() { |
|
|
|
public void timePlaceHolderForThisDay() { |
|
|
@ -40,10 +42,10 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String thisDate = "$[this_day(yyyyMMdd)]"; |
|
|
|
String thisDate = "$[this_day(yyyyMMdd)]"; |
|
|
|
|
|
|
|
|
|
|
|
String thisDayTime = ParameterUtils.convertParameterPlaceholders(thisDay, timeParams); |
|
|
|
String thisDayTime = ParameterUtils.convertParameterPlaceholders(thisDay, timeParams); |
|
|
|
Assertions.assertEquals(thisDayTime, "2022-08-26"); |
|
|
|
assertEquals(thisDayTime, "2022-08-26"); |
|
|
|
|
|
|
|
|
|
|
|
String thisDateTime = ParameterUtils.convertParameterPlaceholders(thisDate, timeParams); |
|
|
|
String thisDateTime = ParameterUtils.convertParameterPlaceholders(thisDate, timeParams); |
|
|
|
Assertions.assertEquals(thisDateTime, "20220826"); |
|
|
|
assertEquals(thisDateTime, "20220826"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -51,10 +53,10 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String lastDay = "$[last_day(yyyy-MM-dd)]"; |
|
|
|
String lastDay = "$[last_day(yyyy-MM-dd)]"; |
|
|
|
String lastDate = "$[last_day(yyyyMMdd)]"; |
|
|
|
String lastDate = "$[last_day(yyyyMMdd)]"; |
|
|
|
String lastDayTime = ParameterUtils.convertParameterPlaceholders(lastDay, timeParams); |
|
|
|
String lastDayTime = ParameterUtils.convertParameterPlaceholders(lastDay, timeParams); |
|
|
|
Assertions.assertEquals(lastDayTime, "2022-08-25"); |
|
|
|
assertEquals(lastDayTime, "2022-08-25"); |
|
|
|
|
|
|
|
|
|
|
|
String lastDateTime = ParameterUtils.convertParameterPlaceholders(lastDate, timeParams); |
|
|
|
String lastDateTime = ParameterUtils.convertParameterPlaceholders(lastDate, timeParams); |
|
|
|
Assertions.assertEquals(lastDateTime, "20220825"); |
|
|
|
assertEquals(lastDateTime, "20220825"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -64,20 +66,20 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String yearWeekDay = "$[year_week(yyyyMMdd)]"; |
|
|
|
String yearWeekDay = "$[year_week(yyyyMMdd)]"; |
|
|
|
|
|
|
|
|
|
|
|
String yearWeekDateTime = ParameterUtils.convertParameterPlaceholders(yearWeekDate, timeParams); |
|
|
|
String yearWeekDateTime = ParameterUtils.convertParameterPlaceholders(yearWeekDate, timeParams); |
|
|
|
Assertions.assertEquals(yearWeekDateTime, "2022-34"); |
|
|
|
assertEquals(yearWeekDateTime, "2022-34"); |
|
|
|
|
|
|
|
|
|
|
|
String yearWeekDayTime = ParameterUtils.convertParameterPlaceholders(yearWeekDay, timeParams); |
|
|
|
String yearWeekDayTime = ParameterUtils.convertParameterPlaceholders(yearWeekDay, timeParams); |
|
|
|
Assertions.assertEquals(yearWeekDayTime, "202234"); |
|
|
|
assertEquals(yearWeekDayTime, "202234"); |
|
|
|
|
|
|
|
|
|
|
|
// Start the week on Friday
|
|
|
|
// Start the week on Friday
|
|
|
|
String yearWeekDateAny = "$[year_week(yyyy-MM-dd,5)]"; |
|
|
|
String yearWeekDateAny = "$[year_week(yyyy-MM-dd,5)]"; |
|
|
|
String yearWeekDayAny = "$[year_week(yyyyMMdd,5)]"; |
|
|
|
String yearWeekDayAny = "$[year_week(yyyyMMdd,5)]"; |
|
|
|
|
|
|
|
|
|
|
|
String yearWeekDateAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDateAny, timeParams); |
|
|
|
String yearWeekDateAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDateAny, timeParams); |
|
|
|
Assertions.assertEquals(yearWeekDateAnyTime, "2022-35"); |
|
|
|
assertEquals(yearWeekDateAnyTime, "2022-35"); |
|
|
|
|
|
|
|
|
|
|
|
String yearWeekDayAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDayAny, timeParams); |
|
|
|
String yearWeekDayAnyTime = ParameterUtils.convertParameterPlaceholders(yearWeekDayAny, timeParams); |
|
|
|
Assertions.assertEquals(yearWeekDayAnyTime, "202235"); |
|
|
|
assertEquals(yearWeekDayAnyTime, "202235"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -86,10 +88,10 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String monthFirstDay = "$[month_first_day(yyyyMMdd,-1)]"; |
|
|
|
String monthFirstDay = "$[month_first_day(yyyyMMdd,-1)]"; |
|
|
|
|
|
|
|
|
|
|
|
String monthFirstDateTime = ParameterUtils.convertParameterPlaceholders(monthFirstDate, timeParams); |
|
|
|
String monthFirstDateTime = ParameterUtils.convertParameterPlaceholders(monthFirstDate, timeParams); |
|
|
|
Assertions.assertEquals(monthFirstDateTime, "2022-07-01"); |
|
|
|
assertEquals(monthFirstDateTime, "2022-07-01"); |
|
|
|
|
|
|
|
|
|
|
|
String monthFirstDayTime = ParameterUtils.convertParameterPlaceholders(monthFirstDay, timeParams); |
|
|
|
String monthFirstDayTime = ParameterUtils.convertParameterPlaceholders(monthFirstDay, timeParams); |
|
|
|
Assertions.assertEquals(monthFirstDayTime, "20220701"); |
|
|
|
assertEquals(monthFirstDayTime, "20220701"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -98,10 +100,10 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String monthLastDay = "$[month_last_day(yyyyMMdd,-1)]"; |
|
|
|
String monthLastDay = "$[month_last_day(yyyyMMdd,-1)]"; |
|
|
|
|
|
|
|
|
|
|
|
String monthLastDateTime = ParameterUtils.convertParameterPlaceholders(monthLastDate, timeParams); |
|
|
|
String monthLastDateTime = ParameterUtils.convertParameterPlaceholders(monthLastDate, timeParams); |
|
|
|
Assertions.assertEquals(monthLastDateTime, "2022-07-31"); |
|
|
|
assertEquals(monthLastDateTime, "2022-07-31"); |
|
|
|
|
|
|
|
|
|
|
|
String monthLastDayTime = ParameterUtils.convertParameterPlaceholders(monthLastDay, timeParams); |
|
|
|
String monthLastDayTime = ParameterUtils.convertParameterPlaceholders(monthLastDay, timeParams); |
|
|
|
Assertions.assertEquals(monthLastDayTime, "20220731"); |
|
|
|
assertEquals(monthLastDayTime, "20220731"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -110,10 +112,10 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String weekFirstDay = "$[week_first_day(yyyyMMdd,0)]"; |
|
|
|
String weekFirstDay = "$[week_first_day(yyyyMMdd,0)]"; |
|
|
|
|
|
|
|
|
|
|
|
String weekFirstDateTime = ParameterUtils.convertParameterPlaceholders(weekFirstDate, timeParams); |
|
|
|
String weekFirstDateTime = ParameterUtils.convertParameterPlaceholders(weekFirstDate, timeParams); |
|
|
|
Assertions.assertEquals(weekFirstDateTime, "2022-08-22"); |
|
|
|
assertEquals(weekFirstDateTime, "2022-08-22"); |
|
|
|
|
|
|
|
|
|
|
|
String weekFirstDayTime = ParameterUtils.convertParameterPlaceholders(weekFirstDay, timeParams); |
|
|
|
String weekFirstDayTime = ParameterUtils.convertParameterPlaceholders(weekFirstDay, timeParams); |
|
|
|
Assertions.assertEquals(weekFirstDayTime, "20220822"); |
|
|
|
assertEquals(weekFirstDayTime, "20220822"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -122,9 +124,17 @@ public class TimePlaceholderUtilsTest { |
|
|
|
String weekLastDay = "$[week_last_day(yyyyMMdd,0)]"; |
|
|
|
String weekLastDay = "$[week_last_day(yyyyMMdd,0)]"; |
|
|
|
|
|
|
|
|
|
|
|
String weekLastDateTime = ParameterUtils.convertParameterPlaceholders(weekLastDate, timeParams); |
|
|
|
String weekLastDateTime = ParameterUtils.convertParameterPlaceholders(weekLastDate, timeParams); |
|
|
|
Assertions.assertEquals(weekLastDateTime, "2022-08-28"); |
|
|
|
assertEquals(weekLastDateTime, "2022-08-28"); |
|
|
|
|
|
|
|
|
|
|
|
String weekLastDayTime = ParameterUtils.convertParameterPlaceholders(weekLastDay, timeParams); |
|
|
|
String weekLastDayTime = ParameterUtils.convertParameterPlaceholders(weekLastDay, timeParams); |
|
|
|
Assertions.assertEquals(weekLastDayTime, "20220828"); |
|
|
|
assertEquals(weekLastDayTime, "20220828"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void getPlaceHolderTime() { |
|
|
|
|
|
|
|
IllegalArgumentException illegalArgumentException = Assertions.assertThrows(IllegalArgumentException.class, |
|
|
|
|
|
|
|
() -> TimePlaceholderUtils.getPlaceHolderTime("$[week_last_day(yyyy-MM-dd,0) - 1]", new Date())); |
|
|
|
|
|
|
|
assertEquals("Unsupported placeholder expression: $[week_last_day(yyyy-MM-dd,0) - 1]", |
|
|
|
|
|
|
|
illegalArgumentException.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|