Search in sources :

Example 1 with MisleadingRule

use of org.kie.dmn.validation.dtanalysis.model.MisleadingRule in project drools by kiegroup.

the class MisleadingRulesTest method testMisleadingRules.

@Test
public void testMisleadingRules() {
    List<DMNMessage> validate = validator.validate(getReader("MisleadingRules.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_BA703D04-803A-44AA-8A31-F5EEDD4FD54E");
    assertThat(analysis.getGaps(), hasSize(0));
    // assert OVERLAPs count.
    assertThat(analysis.getOverlaps(), hasSize(1));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(4, 2), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null)), Interval.newFromBounds(new Bound("M", RangeBoundary.CLOSED, null), new Bound("M", RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(1));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
    // MisleadingRules count.
    assertThat(analysis.getMisleadingRules(), hasSize(1));
    List<MisleadingRule> misleadingRules = Arrays.asList(new MisleadingRule(4, 2));
    assertThat(misleadingRules, hasSize(1));
    assertThat(analysis.getMisleadingRules(), contains(misleadingRules.toArray()));
    assertTrue("It should contain at least 1 DMNMessage for the MisleadingRule", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MISLEADING_RULE)));
    assertTrue("This test case is not a Masked rule example", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MASKED_RULE)));
}
Also used : Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DMNMessage(org.kie.dmn.api.core.DMNMessage) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Interval(org.kie.dmn.validation.dtanalysis.model.Interval) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) List(java.util.List) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Matchers.contains(org.hamcrest.Matchers.contains) MisleadingRule(org.kie.dmn.validation.dtanalysis.model.MisleadingRule) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DMNMessage(org.kie.dmn.api.core.DMNMessage) MisleadingRule(org.kie.dmn.validation.dtanalysis.model.MisleadingRule) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 2 with MisleadingRule

use of org.kie.dmn.validation.dtanalysis.model.MisleadingRule in project drools by kiegroup.

the class StringWithoutEnumNoGapTest method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("stringWithoutEnumNoGap.dmn"), VALIDATE_COMPILATION, VALIDATE_MODEL, ANALYZE_DECISION_TABLE);
    // no gap but no enum "skip Gap analysis" message, (omit 2 overlaps DROOLS-5363), 2 masked, (omit 2 misleading as redundant with Masked).
    assertThat(validate, hasSize(3));
    debugValidatorMsg(validate);
    DTAnalysis analysis = getAnalysis(validate, "_8b48d1c9-265c-47aa-9378-7f11d55dfe55");
    assertThat(analysis.getGaps(), hasSize(0));
    // assert OVERLAPs count.
    assertThat(analysis.getOverlaps(), hasSize(2));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(1, 3), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound("EU", RangeBoundary.CLOSED, null), new Bound("EU", RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("18"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null))))), new Overlap(Arrays.asList(3, 2), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound("US", RangeBoundary.CLOSED, null), new Bound("US", RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("21"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(2));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
    // MaskedRules count.
    assertThat(analysis.getMaskedRules(), hasSize(2));
    List<MaskedRule> maskedRules = Arrays.asList(new MaskedRule(1, 3), new MaskedRule(2, 3));
    assertThat(maskedRules, hasSize(2));
    assertThat(analysis.getMaskedRules(), contains(maskedRules.toArray()));
    assertTrue("It should contain DMNMessage for the MaskedRule", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MASKED_RULE)));
    // MisleadingRules are duplicate of Masked, so are no longer displayed.
    assertThat(analysis.getMisleadingRules(), hasSize(2));
    List<MisleadingRule> misleadingRules = Arrays.asList(new MisleadingRule(3, 1), new MisleadingRule(3, 2));
    assertThat(misleadingRules, hasSize(2));
    assertThat(analysis.getMisleadingRules(), containsInAnyOrder(misleadingRules.toArray()));
    assertTrue("It should NOT contain DMNMessage for the MisleadingRule", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MISLEADING_RULE)));
}
Also used : Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DMNMessage(org.kie.dmn.api.core.DMNMessage) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Interval(org.kie.dmn.validation.dtanalysis.model.Interval) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BigDecimal(java.math.BigDecimal) List(java.util.List) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) MisleadingRule(org.kie.dmn.validation.dtanalysis.model.MisleadingRule) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) MaskedRule(org.kie.dmn.validation.dtanalysis.model.MaskedRule) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) MisleadingRule(org.kie.dmn.validation.dtanalysis.model.MisleadingRule) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) BigDecimal(java.math.BigDecimal) MaskedRule(org.kie.dmn.validation.dtanalysis.model.MaskedRule) DMNMessage(org.kie.dmn.api.core.DMNMessage) Test(org.junit.Test)

Aggregations

Arrays (java.util.Arrays)2 List (java.util.List)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Matchers.contains (org.hamcrest.Matchers.contains)2 Matchers.hasSize (org.hamcrest.Matchers.hasSize)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Test (org.junit.Test)2 DMNMessage (org.kie.dmn.api.core.DMNMessage)2 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)2 RangeBoundary (org.kie.dmn.feel.runtime.Range.RangeBoundary)2 ANALYZE_DECISION_TABLE (org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE)2 VALIDATE_COMPILATION (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION)2 Bound (org.kie.dmn.validation.dtanalysis.model.Bound)2 DTAnalysis (org.kie.dmn.validation.dtanalysis.model.DTAnalysis)2 Hyperrectangle (org.kie.dmn.validation.dtanalysis.model.Hyperrectangle)2 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)2 MisleadingRule (org.kie.dmn.validation.dtanalysis.model.MisleadingRule)2 Overlap (org.kie.dmn.validation.dtanalysis.model.Overlap)2 BigDecimal (java.math.BigDecimal)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1