generated from hmcts/ia-task-configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from hmcts/FPET-1052
FPET-1052-added test cases for all exception record dmn
- Loading branch information
Showing
7 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...v/hmcts/reform/prl/taskconfiguration/dmn/CamundaTaskCompletionForExceptionRecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...mcts/reform/prl/taskconfiguration/dmn/CamundaTaskConfigurationForExceptionRecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
))); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...v/hmcts/reform/prl/taskconfiguration/dmn/CamundaTaskInitiationForExceptionRecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...v/hmcts/reform/prl/taskconfiguration/dmn/CamundaTaskPermissionForExceptionRecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...v/hmcts/reform/prl/taskconfiguration/dmn/CamundaTaskTypeFilterForExceptionRecordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
))); | ||
} | ||
} |