diff --git a/kie-dmn/kie-dmn-validation/src/main/java/org/kie/dmn/validation/dtanalysis/model/DTAnalysis.java b/kie-dmn/kie-dmn-validation/src/main/java/org/kie/dmn/validation/dtanalysis/model/DTAnalysis.java index 00e720a65d2..acf6c180621 100644 --- a/kie-dmn/kie-dmn-validation/src/main/java/org/kie/dmn/validation/dtanalysis/model/DTAnalysis.java +++ b/kie-dmn/kie-dmn-validation/src/main/java/org/kie/dmn/validation/dtanalysis/model/DTAnalysis.java @@ -269,7 +269,7 @@ private Collection check1stNFViolationAsMessages() { } for (Collection duplicateRulesTuple : getDuplicateRulesTuples()) { results.add(new DMNDTAnalysisMessage(this, - Severity.ERROR, + sourceDT.getHitPolicy() == HitPolicy.COLLECT ? Severity.WARN : Severity.ERROR, MsgUtil.createMessage(Msg.DTANALYSIS_1STNFVIOLATION_DUPLICATE_RULES, duplicateRulesTuple), Msg.DTANALYSIS_1STNFVIOLATION_DUPLICATE_RULES.getType(), duplicateRulesTuple)); diff --git a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/dtanalysis/Check1stNFViolationTest.java b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/dtanalysis/Check1stNFViolationTest.java index c1473c19712..26ceeaf89d9 100644 --- a/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/dtanalysis/Check1stNFViolationTest.java +++ b/kie-dmn/kie-dmn-validation/src/test/java/org/kie/dmn/validation/dtanalysis/Check1stNFViolationTest.java @@ -21,14 +21,15 @@ import java.util.List; import org.junit.Test; +import org.kie.api.builder.Message.Level; import org.kie.dmn.api.core.DMNMessage; import org.kie.dmn.api.core.DMNMessageType; import org.kie.dmn.validation.dtanalysis.model.DTAnalysis; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE; @@ -82,4 +83,19 @@ public void testCheck1stNFViolationDuplicateNoSubsumption() { assertTrue("No message about subsumption", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_SUBSUMPTION_RULE))); } + + @Test + public void testCheck1stNFViolationCollect() { + List validate = validator.validate(getReader("DT1stNFViolationCollect.dmn"), ANALYZE_DECISION_TABLE); + + DTAnalysis analysisDuplicate = getAnalysis(validate, "_4237d55b-2589-48a5-8183-f9f4e0e00c07"); + assertThat(analysisDuplicate.is1stNFViolation(), is(true)); + assertThat(analysisDuplicate.getDuplicateRulesTuples(), hasSize(2)); + assertTrue("It should contain DMNMessage(s) for the 1st NF Violation", + validate.stream().anyMatch(p -> p.getSourceId().equals("_4237d55b-2589-48a5-8183-f9f4e0e00c07") && p.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION))); + assertTrue("Being a C table, DMNMessage(s) for the 1st NF Violation are of type Warning", + validate.stream() + .filter(p -> p.getSourceId().equals("_4237d55b-2589-48a5-8183-f9f4e0e00c07") && p.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION)) + .allMatch(p -> p.getLevel() == Level.WARNING)); + } } diff --git a/kie-dmn/kie-dmn-validation/src/test/resources/org/kie/dmn/validation/dtanalysis/DT1stNFViolationCollect.dmn b/kie-dmn/kie-dmn-validation/src/test/resources/org/kie/dmn/validation/dtanalysis/DT1stNFViolationCollect.dmn new file mode 100644 index 00000000000..aad8a277d8b --- /dev/null +++ b/kie-dmn/kie-dmn-validation/src/test/resources/org/kie/dmn/validation/dtanalysis/DT1stNFViolationCollect.dmn @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + Amount + + + + + Type + + + + + + + + + <1000 + + + "Personal" + + + "Application Review" + + + 1 + + + duration("P3D") + + + + + + + + <1000 + + + "Personal" + + + "Credit Check" + + + 2 + + + duration("P1D") + + + + + + + + <1000 + + + "Personal" + + + "Final Approval" + + + 3 + + + duration("P3D") + + + + + + + + >=1000 + + + "Personal" + + + "Application Review" + + + 1 + + + duration("P4D") + + + + + + + + >=1000 + + + "Personal" + + + "Credit Check" + + + 2 + + + duration("P1D") + + + + + + + + >=1000 + + + "Personal" + + + "Risk Evaluation" + + + 3 + + + duration("P3D") + + + + + + + + >=1000 + + + "Personal" + + + "Application Review" + + + 4 + + + duration("P4D") + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file