Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-9546] Add tests for BusinessCalendar Calculations #1839

Merged
merged 1 commit into from Jan 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -246,6 +246,74 @@ public void testCalculateTimeDaysHoursMinutesHolidays() {
assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result));
}

@Test
public void testCalculateHoursSimulatedSLAHolidaysAndWeekend() {
Properties config = new Properties();
config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2020-12-18");
config.setProperty(BusinessCalendarImpl.START_HOUR, "8");
config.setProperty(BusinessCalendarImpl.END_HOUR, "17");
config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "9");
String expectedDate = "2020-12-22 09:39:57";

SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndSeconds("2020-12-16 13:09:57").getTime());
BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock);

Date result = businessCal.calculateBusinessTimeAsDate("23h30m");

assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm:ss", result));
}

@Test
public void testCalculateHoursSimulatedSLAHolidaysTodayAndWeekend() {
Properties config = new Properties();
config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2020-12-16");
config.setProperty(BusinessCalendarImpl.START_HOUR, "8");
config.setProperty(BusinessCalendarImpl.END_HOUR, "17");
config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "9");
String expectedDate = "2020-12-21 13:30";

SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndSeconds("2020-12-16 15:13:50").getTime());
BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock);

Date result = businessCal.calculateBusinessTimeAsDate("23h30m");

assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result));
}

@Test
public void testCalculateHoursSimulatedSLAHolidaysTodayAndWeekendTomorrow() {
Properties config = new Properties();
config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2020-12-18");
config.setProperty(BusinessCalendarImpl.START_HOUR, "8");
config.setProperty(BusinessCalendarImpl.END_HOUR, "17");
config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "9");
String expectedDate = "2020-12-23 13:30";

SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndSeconds("2020-12-18 15:13:50").getTime());
BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock);

Date result = businessCal.calculateBusinessTimeAsDate("23h30m");

assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result));
}

@Test
public void testCalculateHoursSimulatedSLAHolidaysNotConsecutive() {
Properties config = new Properties();
config.setProperty(BusinessCalendarImpl.HOLIDAYS, "2020-12-22");
config.setProperty(BusinessCalendarImpl.START_HOUR, "8");
config.setProperty(BusinessCalendarImpl.END_HOUR, "17");
config.setProperty(BusinessCalendarImpl.HOURS_PER_DAY, "9");
String expectedDate = "2020-12-24 13:30";

SessionPseudoClock clock = new StaticPseudoClock(parseToDateWithTimeAndSeconds("2020-12-19 15:13:50").getTime());
BusinessCalendarImpl businessCal = new BusinessCalendarImpl(config, clock);

Date result = businessCal.calculateBusinessTimeAsDate("23h30m");

assertEquals(expectedDate, formatDate("yyyy-MM-dd HH:mm", result));
}

@Test
public void testCalculateTimeDaysHoursMinutesSingleDayHolidays() {
Properties config = new Properties();
Expand Down Expand Up @@ -449,6 +517,19 @@ private Date parseToDateWithTime(String dateString) {
}
}

private Date parseToDateWithTimeAndSeconds(String dateString) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date testTime;
try {
testTime = sdf.parse(dateString);

return testTime;
} catch (ParseException e) {
return null;
}
}

private Date parseToDateWithTimeAndMillis(String dateString) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

Expand Down