Skip to content

Commit

Permalink
Merge pull request #158 from hmcts/FPET-1052
Browse files Browse the repository at this point in the history
FPET-1052-added test cases for all exception record dmn
  • Loading branch information
priteshkr authored Jul 29, 2024
2 parents b9cf0df + 608888a commit 3414f7f
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ public enum DmnDecisionTable {
WA_TASK_CONFIGS("wa-task-configuration-privatelaw-prlapps", "wa-task-configuration-privatelaw-prlapps.dmn"),
WA_TASK_INITIATION("wa-task-initiation-privatelaw-prlapps", "wa-task-initiation-privatelaw-prlapps.dmn"),
WA_TASK_PERMISSION("wa-task-permissions-privatelaw-prlapps", "wa-task-permissions-privatelaw-prlapps.dmn"),
WA_TASK_TASKTYPEFILTER("wa-task-types-privatelaw-prlapps", "wa-task-types-privatelaw-prlapps.dmn");
WA_TASK_TASKTYPEFILTER("wa-task-types-privatelaw-prlapps", "wa-task-types-privatelaw-prlapps.dmn"),

WA_TASK_COMPLETION_EXCEPTION_RECORD("wa-task-completion-privatelaw-privatelaw_exceptionrecord",
"wa-task-completion-privatelaw-privatelaw_exceptionrecord.dmn"),
WA_TASK_CONFIGS_EXCEPTION_RECORD("wa-task-configuration-privatelaw-privatelaw_exceptionrecord",
"wa-task-configuration-privatelaw-privatelaw_exceptionrecord.dmn"),
WA_TASK_INITIATION_EXCEPTION_RECORD("wa-task-initiation-privatelaw-privatelaw_exceptionrecord",
"wa-task-initiation-privatelaw-privatelaw_exceptionrecord.dmn"),
WA_TASK_PERMISSION_EXCEPTION_RECORD("wa-task-permissions-privatelaw-privatelaw_exceptionrecord",
"wa-task-permissions-privatelaw-privatelaw_exceptionrecord.dmn"),
WA_TASK_TASKTYPEFILTER_EXCEPTION_RECORD("wa-task-types-privatelaw-privatelaw_exceptionrecord",
"wa-task-types-privatelaw-privatelaw_exceptionrecord.dmn");

@JsonValue
private final String key;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package uk.gov.hmcts.reform.prl.taskconfiguration.dmn;

import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.BeforeAll;
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.MethodSource;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTableBaseUnitTest;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTable.WA_TASK_COMPLETION_EXCEPTION_RECORD;

class CamundaTaskCompletionForExceptionRecordTest extends DmnDecisionTableBaseUnitTest {

@BeforeAll
public static void initialization() {
CURRENT_DMN_DECISION_TABLE = WA_TASK_COMPLETION_EXCEPTION_RECORD;
}

static Stream<Arguments> scenarioProvider() {

return Stream.of(
Arguments.of(
"createException",
asList(
Map.of(
"taskType", "reviewExceptionBulkScanRecord",
"completionMode", "Auto"
)
)
)
);
}

@ParameterizedTest(name = "event id: {0} post event state: {1}")
@MethodSource("scenarioProvider")
void event_ids_should_evaluate_dmn(String eventId, List<Map<String, String>> expectation) {

VariableMap inputVariables = new VariableMapImpl();
inputVariables.putValue("eventId", eventId);

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);
MatcherAssert.assertThat(dmnDecisionTableResult.getResultList(), is(expectation));
}

@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.getInputs().size(), is(1));
assertThat(logic.getOutputs().size(), is(2));
assertThat(logic.getRules().size(), is(1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package uk.gov.hmcts.reform.prl.taskconfiguration.dmn;


import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTable;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTableBaseUnitTest;

import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CamundaTaskConfigurationForExceptionRecordTest extends DmnDecisionTableBaseUnitTest {

@BeforeAll
public static void initialization() {
CURRENT_DMN_DECISION_TABLE = DmnDecisionTable.WA_TASK_CONFIGS_EXCEPTION_RECORD;
}

@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.getInputs().size(), is(2));
assertThat(logic.getOutputs().size(), is(3));
assertThat(logic.getRules().size(), is(6));
}

@Test
void when_given_task_type_then_return_dueDateIntervalDays() {
VariableMap inputVariables = new VariableMapImpl();
inputVariables.putValue("taskType", "reviewExceptionBulkScanRecord");

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "dueDateIntervalDays",
"value", "1"
)));

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "majorPriority",
"value", "1000"
)));

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "workType",
"value", "routine_work"
)));

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "roleCategory",
"value", "ADMIN"
)));

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "roleCategory",
"value", "CTSC"
)));

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"name", "description",
"value", "[Review Exception Record Documents](/cases/case-details/${[CASE_REFERENCE]}"
+ "/trigger/attachToExistingCase/attachToExistingCase1)"
)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package uk.gov.hmcts.reform.prl.taskconfiguration.dmn;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.junit.jupiter.api.BeforeAll;
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.MethodSource;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTable;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTableBaseUnitTest;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

class CamundaTaskInitiationForExceptionRecordTest extends DmnDecisionTableBaseUnitTest {

@BeforeAll
public static void initialization() {
CURRENT_DMN_DECISION_TABLE = DmnDecisionTable.WA_TASK_INITIATION_EXCEPTION_RECORD;
}

@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.getInputs().size(), is(3));
assertThat(logic.getOutputs().size(), is(4));
assertThat(logic.getRules().size(), is(1));
}

static Stream<Arguments> scenarioProvider() {

return Stream.of(
Arguments.of(
"createException",
null,
mapAdditionalData("{\n"
+ " \"Data\":{\n"
+ " \"poBoxJurisdiction\":\"" + "PRIVATELAW" + "\"\n"
+ " }"
+ "}"),
singletonList(
Map.of(
"taskId", "reviewExceptionBulkScanRecord",
"name", "Review Exceptional Record from Bulk Scan",
"processCategories", "bulkScanExceptionalRecord"
)
)
)
);
}

@ParameterizedTest(name = "event id: {0} post event state: {1} additional data: {2}")
@MethodSource("scenarioProvider")
void given_multiple_event_ids_should_evaluate_dmn(String eventId,
String postEventState,
Map<String, Object> map,
List<Map<String, String>> expectation) {

VariableMap inputVariables = new VariableMapImpl();
inputVariables.putValue("eventId", eventId);
inputVariables.putValue("postEventState", postEventState);
inputVariables.putValue("AdditionalData", map);

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);

assertThat(dmnDecisionTableResult.getResultList(), is(expectation));
}

private static Map<String, Object> mapAdditionalData(String additionalData) {
ObjectMapper mapper = new ObjectMapper();
try {
TypeReference<HashMap<String, Object>> typeRef = new TypeReference<>() {
};
return mapper.readValue(additionalData, typeRef);
} catch (IOException exp) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,6 @@ void given_multiple_event_ids_should_evaluate_dmn(String eventId,
inputVariables.putValue("additionalData", map);

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);
System.out.println(dmnDecisionTableResult);

assertThat(dmnDecisionTableResult.getResultList(), is(expectation));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package uk.gov.hmcts.reform.prl.taskconfiguration.dmn;

import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
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.MethodSource;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTableBaseUnitTest;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTable.WA_TASK_PERMISSION_EXCEPTION_RECORD;

class CamundaTaskPermissionForExceptionRecordTest extends DmnDecisionTableBaseUnitTest {


@BeforeAll
public static void initialization() {
CURRENT_DMN_DECISION_TABLE = WA_TASK_PERMISSION_EXCEPTION_RECORD;
}

/*
important: permissions rules in the DMN are in order, in case you can't find why your test fails.
*/
@ParameterizedTest
@MethodSource("scenarioProvider")
void given_taskType_and_CaseData_when_evaluate_then_returns_expected_rules(
String taskType,

List<Map<String, Serializable>> expectedRules) {

VariableMap inputVariables = new VariableMapImpl();
inputVariables.putValue("taskAttributes", Map.of("taskType", taskType));

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);
Assertions.assertEquals(expectedRules, dmnDecisionTableResult);
}

static Stream<Arguments> scenarioProvider() {
return Stream.of(
Arguments.of(
"reviewExceptionBulkScanRecord",
List.of(
Map.of(
"authorisations","SKILL:ABA5:CHECKAPPLICATIONFL401",
"roleCategory", "ADMIN",
"name", "hearing-centre-admin",
"autoAssignable", false,
"value", "Read,Own,CompleteOwn,CancelOwn,UnclaimAssign,Claim,Unclaim,UnassignClaim"
),
Map.of(
"roleCategory", "CTSC",
"authorisations","SKILL:ABA5:CHECKAPPLICATIONC100",
"autoAssignable", false,
"name", "ctsc",
"value", "Read,Own,CompleteOwn,CancelOwn,UnclaimAssign,Claim,Unclaim,UnassignClaim"

)
)
)
);
}

@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.getInputs().size(), is(2));
assertThat(logic.getOutputs().size(), is(7));
assertThat(logic.getRules().size(), is(2));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package uk.gov.hmcts.reform.prl.taskconfiguration.dmn;

import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.dmn.engine.impl.DmnDecisionTableImpl;
import org.camunda.bpm.engine.variable.VariableMap;
import org.camunda.bpm.engine.variable.impl.VariableMapImpl;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTable;
import uk.gov.hmcts.reform.prl.taskconfiguration.DmnDecisionTableBaseUnitTest;

import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CamundaTaskTypeFilterForExceptionRecordTest extends DmnDecisionTableBaseUnitTest {

@BeforeAll
public static void initialization() {
CURRENT_DMN_DECISION_TABLE = DmnDecisionTable.WA_TASK_TASKTYPEFILTER_EXCEPTION_RECORD;
}

@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.getInputs().size(), is(1));
assertThat(logic.getOutputs().size(), is(2));
assertThat(logic.getRules().size(), is(1));
}

@Test
void given_taskType_and_CaseData_when_evaluate_then_returns_expected_rules() {

VariableMap inputVariables = new VariableMapImpl();

DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables);

assertTrue(dmnDecisionTableResult.getResultList().contains(Map.of(
"taskTypeId", "reviewExceptionBulkScanRecord",
"taskTypeName", "Review Private Law Exception Record Message"
)));
}
}

0 comments on commit 3414f7f

Please sign in to comment.