Skip to content

Commit

Permalink
Merge pull request #46 from hmcts/RET-3179-Configure-Court-Specific-C…
Browse files Browse the repository at this point in the history
…alendars

RET-3179 configure court specific calendars
  • Loading branch information
nagaraju-deekonda committed Jun 22, 2023
2 parents 8ca5bc1 + ea2eb98 commit f4bf4e2
Show file tree
Hide file tree
Showing 3 changed files with 313 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/main/resources/privilege-calendar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"division": "england-and-wales",
"events": [
{
"title": "Christmas Day",
"date": "2022-12-25",
"notes": "",
"bunting": true,
"working_day": false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ else ""</text>
<text>5000</text>
</outputEntry>
<outputEntry id="LiteralExpression_1mzeeq8">
<text></text>
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1ua5utw">
Expand All @@ -639,7 +639,7 @@ then 1000
else 5000</text>
</outputEntry>
<outputEntry id="LiteralExpression_1uusq1d">
<text></text>
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0j1v09c">
Expand All @@ -666,7 +666,7 @@ else 5000</text>
<text>500</text>
</outputEntry>
<outputEntry id="LiteralExpression_1lezcx4">
<text></text>
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0bz90wb">
Expand All @@ -690,7 +690,143 @@ then 100
else 500</text>
</outputEntry>
<outputEntry id="LiteralExpression_0ry9gq0">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1rmrxfm">
<inputEntry id="UnaryTests_157mvkf">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_1huasai">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_0lq8mjx">
<text>"calculatedDates"</text>
</outputEntry>
<outputEntry id="LiteralExpression_1tnw3lm">
<text>"nextHearingDate,dueDate,priorityDate"</text>
</outputEntry>
<outputEntry id="LiteralExpression_13crvik">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_108ksv2">
<inputEntry id="UnaryTests_08hi4x5">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_0vu6bym">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_0nmpsln">
<text>"dueDateOrigin"</text>
</outputEntry>
<outputEntry id="LiteralExpression_1wxj3ej">
<text>now()</text>
</outputEntry>
<outputEntry id="LiteralExpression_1cg2n4r">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0h2yrh9">
<inputEntry id="UnaryTests_038hb47">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_01q40qe">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_14j9rg6">
<text>"dueDateTime"</text>
</outputEntry>
<outputEntry id="LiteralExpression_0w4y7mn">
<text>time("16:00")</text>
</outputEntry>
<outputEntry id="LiteralExpression_1t5kkwb">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_1026abf">
<inputEntry id="UnaryTests_1o2htjd">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_1cwow0d">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_14n7190">
<text>"dueDateNonWorkingCalendar"</text>
</outputEntry>
<outputEntry id="LiteralExpression_1luowkm">
<text>"https://www.gov.uk/bank-holidays/england-and-wales.json, https://raw.githubusercontent.com/hmcts/civil-wa-task-configuration/master/src/main/resources/privilege-calendar.json"</text>
</outputEntry>
<outputEntry id="LiteralExpression_1gnav2w">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0er605q">
<inputEntry id="UnaryTests_1trxdv7">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_0rfhv46">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_16fy0p8">
<text>"dueDateNonWorkingDaysOfWeek"</text>
</outputEntry>
<outputEntry id="LiteralExpression_0kyhrww">
<text>"SATURDAY,SUNDAY"</text>
</outputEntry>
<outputEntry id="LiteralExpression_0npgbuk">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_02liz3k">
<inputEntry id="UnaryTests_1p4tpwc">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_133dqw8">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_1bjqbre">
<text>"dueDateSkipNonWorkingDays"</text>
</outputEntry>
<outputEntry id="LiteralExpression_0mc8otd">
<text>"false"</text>
</outputEntry>
<outputEntry id="LiteralExpression_10c00lk">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0urorrj">
<inputEntry id="UnaryTests_09um5yv">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_0ibvt4r">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_03fcwgl">
<text>"dueDateMustBeWorkingDay"</text>
</outputEntry>
<outputEntry id="LiteralExpression_11thm6q">
<text>"No"</text>
</outputEntry>
<outputEntry id="LiteralExpression_1027th9">
<text>false</text>
</outputEntry>
</rule>
<rule id="DecisionRule_0xrz5gi">
<inputEntry id="UnaryTests_1ub6lnr">
<text></text>
</inputEntry>
<inputEntry id="UnaryTests_0ox5ilk">
<text></text>
</inputEntry>
<outputEntry id="LiteralExpression_0uy7dph">
<text>"priorityDateOriginRef"</text>
</outputEntry>
<outputEntry id="LiteralExpression_0dkr2h7">
<text>"dueDate"</text>
</outputEntry>
<outputEntry id="LiteralExpression_1tt1zjs">
<text>false</text>
</outputEntry>
</rule>
</decisionTable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.gov.hmcts.et.taskconfiguration.dmn;

import lombok.Builder;
import lombok.Value;
import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl;
import org.camunda.bpm.engine.variable.VariableMap;
Expand All @@ -8,10 +10,15 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import uk.gov.hmcts.et.taskconfiguration.DmnDecisionTableBaseUnitTest;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -27,6 +34,10 @@

class EmploymentTaskConfigurationTest extends DmnDecisionTableBaseUnitTest {

private static final String DEFAULT_CALENDAR = "https://www.gov.uk/bank-holidays/england-and-wales.json";
private static final String EXTRA_TEST_CALENDAR = "https://raw.githubusercontent.com/hmcts/"
+ "ia-task-configuration/master/src/test/resources/extra-non-working-day-calendar.json";

@BeforeAll
public static void initialization() {
CURRENT_DMN_DECISION_TABLE = WA_TASK_CONFIGURATION_ET_EW;
Expand Down Expand Up @@ -383,6 +394,12 @@ void when_taskId_then_return_priority(String taskType,
}

public static Stream<Arguments> priority_ScenarioProvider() {

List<Map<String, String>> defaultDatePriority = List.of(Map.of(
"name", "priorityDateOriginRef",
"value", "dueDate"
));

List<Map<String, String>> defaultMajorPriority = List.of(Map.of(
"name", "majorPriority",
"value", "5000"
Expand Down Expand Up @@ -448,10 +465,154 @@ void should_return_request_value_when_role_assignment_id_exists_in_task_attribut
)));
}

@ParameterizedTest
@MethodSource("nameAndValueScenarioProvider")
void when_caseData_and_taskType_then_return_expected_name_and_value_rows(Scenario scenario) {
VariableMap inputVariables = new VariableMapImpl();
inputVariables.putValue("caseData", scenario.caseData);
inputVariables.putValue("taskAttributes", scenario.getTaskAttributes());

List<Map<String, Object>> expected = getExpectedValues(scenario);

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);

assertThat(dmnDecisionTableResult.getResultList().size(), is(expected.size()));
}

@Value
@Builder
private static class Scenario {
Map<String, Object> caseData;
Map<String, Object> taskAttributes;
String expectedCaseNameValue;
String expectedAppealTypeValue;
String expectedRegionValue;
String expectedLocationValue;
String expectedLocationNameValue;
String expectedCaseManagementCategoryValue;
String expectedWorkType;
String expectedRoleCategory;
String expectedDescriptionValue;
String expectedReconfigureValue;
String expectedDueDateOrigin;
String expectedDueDateTime;
String expectedDueDateIntervalDays;
}

private static Stream<Scenario> nameAndValueScenarioProvider() {
String dateOrigin = ZonedDateTime.now(ZoneId.of("UTC")).toString();
Scenario givenSomeCaseDataAndTaskTypeIsEmptyThenExpectNoWorkTypeRuleScenario =
Scenario.builder()
.caseData(Map.of(
"appellantGivenNames", "some appellant given names",
"appellantFamilyName", "some appellant family name",
"caseManagementCategory","Employment"
)
)
.expectedCaseNameValue("some appellant given names some appellant family name")
.expectedCaseManagementCategoryValue("Employment")
.expectedDueDateOrigin(dateOrigin)
.build();

return Stream.of(
givenSomeCaseDataAndTaskTypeIsEmptyThenExpectNoWorkTypeRuleScenario
);
}

private List<Map<String, Object>> getExpectedValues(Scenario scenario) {
List<Map<String, Object>> rules = new ArrayList<>();
getExpectedValueWithReconfigure(
rules,
"caseName",
scenario.getExpectedCaseNameValue(),
scenario.getExpectedReconfigureValue()
);
getExpectedValue(rules, "caseManagementCategory", "Employment");
getExpectedValue(rules, "dueDateOrigin", scenario.getExpectedDueDateOrigin());
getExpectedValue(rules, "dueDateTime", scenario.getExpectedDueDateTime());
getExpectedValue(rules, "dueDateNonWorkingCalendar", DEFAULT_CALENDAR + ", " + EXTRA_TEST_CALENDAR);
getExpectedValue(rules, "priorityDateOriginRef", "dueDate");
getExpectedValue(rules, "dueDateNonWorkingDaysOfWeek", "SATURDAY,SUNDAY");
getExpectedValue(rules, "dueDateSkipNonWorkingDays", "false");
getExpectedValue(rules, "dueDateMustBeWorkingDay", "No");
getExpectedValue(rules, "calculatedDates", "nextHearingDate,dueDate,priorityDate");
return rules;
}

private void getExpectedValue(List<Map<String, Object>> rules, String name, String value) {
Map<String, Object> rule = new HashMap<>();
rule.put("name", name);
rule.put("value", value);
rule.put("canReconfigure", false);
rules.add(rule);
}

private void getExpectedValueWithReconfigure(List<Map<String, Object>> rules, String name, String value,
String reconfigure) {
Map<String, Object> rule = new HashMap<>();
rule.put("name", name);
rule.put("value", value);
rule.put("canReconfigure", Boolean.valueOf(reconfigure));
rules.add(rule);
}

private boolean validNow(ZonedDateTime expected, ZonedDateTime actual) {
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC"));
return actual != null
&& (expected.isEqual(actual) || expected.isBefore(actual))
&& (now.isEqual(actual) || now.isAfter(actual));
}

@Test
void when_any_task_then_return_expected_non_working_days_of_week_config() {
VariableMap inputVariables = new VariableMapImpl();

inputVariables.putValue("taskAttributes", Map.of("taskType", "draftCaseCreated"));

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "dueDateNonWorkingDaysOfWeek",
"value", "SATURDAY,SUNDAY",
"canReconfigure", false
)));
}

@ParameterizedTest
@CsvSource({
"draftCaseCreated"
})
void when_taskId_then_return_due_date_skip_non_working_days_false(String taskType) {
VariableMap inputVariables = new VariableMapImpl();

inputVariables.putValue("taskAttributes", Map.of("taskType", taskType));

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);

List<Map<String, Object>> dueDateSkipNonWorkingDaysResultList = dmnDecisionTableResult.getResultList().stream()
.filter((r) -> r.containsValue("dueDateSkipNonWorkingDays"))
.collect(Collectors.toList());

assertEquals(1, dueDateSkipNonWorkingDaysResultList.size());

assertEquals(Map.of(
"name", "dueDateSkipNonWorkingDays",
"value", "false",
"canReconfigure", false
), dueDateSkipNonWorkingDaysResultList.get(0));
}

private ZonedDateTime parseCamundaTimestamp(String datetime) {
String[] parts = datetime.split("[Z+]");
String zone = datetime.substring(datetime.indexOf("[") + 1, datetime.lastIndexOf("]"));
return ZonedDateTime.of(LocalDateTime.parse(parts[0]), ZoneId.of(zone));
}

@Test
void if_this_test_fails_needs_updating_with_your_changes() {
//The purpose of this test is to prevent adding new rows without being tested
DmnDecisionTableImpl logic = (DmnDecisionTableImpl) decision.getDecisionLogic();
assertThat(logic.getRules().size(), is(34));

assertThat(logic.getRules().size(), is(42));
}
}

0 comments on commit f4bf4e2

Please sign in to comment.