Skip to content

Commit

Permalink
Added rule condition for not a holiday (#2043)
Browse files Browse the repository at this point in the history
Signed-off-by: Sönke Küper <soenkekueper@gmx.de>
  • Loading branch information
soenkekueper authored Feb 6, 2021
1 parent 74c4c23 commit 65218f8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
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));
}
}

0 comments on commit 65218f8

Please sign in to comment.