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

Added rule condition for not a holiday #2043

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class EphemerisModuleHandlerFactory extends BaseModuleHandlerFactory impl
private final Logger logger = LoggerFactory.getLogger(EphemerisModuleHandlerFactory.class);

private static final Collection<String> TYPES = List.of(EphemerisConditionHandler.HOLIDAY_MODULE_TYPE_ID,
EphemerisConditionHandler.WEEKEND_MODULE_TYPE_ID, EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID,
EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID);
EphemerisConditionHandler.NOT_HOLIDAY_MODULE_TYPE_ID, EphemerisConditionHandler.WEEKEND_MODULE_TYPE_ID,
EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID, EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID);

private final EphemerisManager ephemerisManager;

Expand Down Expand Up @@ -73,6 +73,7 @@ public Collection<String> getTypes() {
if (module instanceof Condition) {
switch (moduleTypeUID) {
case EphemerisConditionHandler.HOLIDAY_MODULE_TYPE_ID:
case EphemerisConditionHandler.NOT_HOLIDAY_MODULE_TYPE_ID:
case EphemerisConditionHandler.WEEKEND_MODULE_TYPE_ID:
case EphemerisConditionHandler.WEEKDAY_MODULE_TYPE_ID:
case EphemerisConditionHandler.DAYSET_MODULE_TYPE_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
public class EphemerisConditionHandler extends BaseModuleHandler<Condition> implements ConditionHandler {

public static final String HOLIDAY_MODULE_TYPE_ID = "ephemeris.HolidayCondition";
public static final String NOT_HOLIDAY_MODULE_TYPE_ID = "ephemeris.NotHolidayCondition";
public static final String WEEKEND_MODULE_TYPE_ID = "ephemeris.WeekendCondition";
public static final String WEEKDAY_MODULE_TYPE_ID = "ephemeris.WeekdayCondition";
public static final String DAYSET_MODULE_TYPE_ID = "ephemeris.DaysetCondition";
Expand Down Expand Up @@ -65,6 +66,8 @@ public boolean isSatisfied(Map<String, Object> inputs) {
switch (module.getTypeUID()) {
case HOLIDAY_MODULE_TYPE_ID:
return ephemerisManager.isBankHoliday(target);
case NOT_HOLIDAY_MODULE_TYPE_ID:
return !ephemerisManager.isBankHoliday(target);
case WEEKEND_MODULE_TYPE_ID:
return ephemerisManager.isWeekend(target);
case WEEKDAY_MODULE_TYPE_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
}
]
},
{
"uid": "ephemeris.NotHolidayCondition",
"label": "it is not a holiday",
"description": "Checks if the current day is not a holiday.",
"configDescriptions": [
{
"name": "offset",
"type": "INTEGER",
"label": "Offset",
"description": "Today +/- offset days (+1 = tomorrow, -1 = yesterday).",
"default": 0,
"stepsize": 1,
"required": false
}
]
},
{
"uid": "ephemeris.WeekendCondition",
"label": "it is a weekend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,34 @@ public void testFactoryCreatesModuleHandlerForWeekdayCondition() {
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));
}

@Test
public void testFactoryCreatesModuleHandlerForHolidayCondition() {
when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.HOLIDAY_MODULE_TYPE_ID);

when(moduleMock.getConfiguration()).thenReturn(new Configuration());
ModuleHandler handler = factory.internalCreate(moduleMock, "My first rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));

when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("offset", 5)));
handler = factory.internalCreate(moduleMock, "My second rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));
}

@Test
public void testFactoryCreatesModuleHandlerForNotHolidayCondition() {
when(moduleMock.getTypeUID()).thenReturn(EphemerisConditionHandler.NOT_HOLIDAY_MODULE_TYPE_ID);

when(moduleMock.getConfiguration()).thenReturn(new Configuration());
ModuleHandler handler = factory.internalCreate(moduleMock, "My first rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));

when(moduleMock.getConfiguration()).thenReturn(new Configuration(Map.of("offset", 5)));
handler = factory.internalCreate(moduleMock, "My second rule");
assertThat(handler, is(notNullValue()));
assertThat(handler, instanceOf(EphemerisConditionHandler.class));
}
}