Search in sources :

Example 11 with DTAnalysis

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

the class SameMsgInAllAPITest method verify.

private void verify(List<DMNMessage> validate) {
    assertThat(validate, hasSize(5));
    DTAnalysis analysis = getAnalysis(validate, "_4771db14-e088-4d5a-8942-211c57ad0b42");
    assertThat(analysis.getGaps(), hasSize(3));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null)))), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("4"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("6"), RangeBoundary.OPEN, null)))), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("8"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("10"), RangeBoundary.CLOSED, null)))));
    assertThat(gaps, hasSize(3));
    // Assert GAPS
    assertThat(analysis.getGaps(), contains(gaps.toArray()));
    // assert OVERLAPs count.
    assertThat(analysis.getOverlaps(), hasSize(2));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(1, 2), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("4"), RangeBoundary.CLOSED, null))))), new Overlap(Arrays.asList(3, 4), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("6"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("7"), 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(2, 1), new MaskedRule(4, 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)));
}
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) 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) 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)

Example 12 with DTAnalysis

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

the class GapsCube3Test method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("GapsCube3.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_4b41743d-ff04-4855-bf0b-993d475a9d62");
    assertThat(analysis.getGaps(), hasSize(4));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(3, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)))), new Hyperrectangle(3, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.OPEN, null), new Bound(new BigDecimal("2"), RangeBoundary.OPEN, null)))), new Hyperrectangle(3, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("1"), RangeBoundary.OPEN, null)))), new Hyperrectangle(3, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("2"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("1"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("3"), RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("1"), RangeBoundary.OPEN, null)))));
    assertThat(gaps, hasSize(4));
    // Assert GAPS
    assertThat(analysis.getGaps(), contains(gaps.toArray()));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 13 with DTAnalysis

use of org.kie.dmn.validation.dtanalysis.model.DTAnalysis 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 14 with DTAnalysis

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

the class MisleadingRulesTest method testMisleadingRules2.

@Test
public void testMisleadingRules2() {
    List<DMNMessage> validate = validator.validate(getReader("MisleadingRules2.dmn"), VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_0cffdf05-071b-423b-94b9-182c2cc2435c");
    assertThat(analysis.getGaps(), hasSize(0));
    // no need for assert overlaps.
    // MisleadingRules count.
    assertThat(analysis.getMisleadingRules(), hasSize(0));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 15 with DTAnalysis

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

the class NotTest method testNOTnumber.

@Test
public void testNOTnumber() {
    List<DMNMessage> validate = validator.validate(getReader("DTusingNOTnumber.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_d0cbacca-55d4-47dd-acc6-131add2a8a53");
    assertThat(analysis.getGaps(), hasSize(1));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Hyperrectangle> gaps = Arrays.asList(new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null), new Bound(new BigDecimal("0"), RangeBoundary.CLOSED, null)))));
    assertThat(gaps, hasSize(1));
    // Assert GAPS
    assertThat(analysis.getGaps(), contains(gaps.toArray()));
    // assert OVERLAPs count.
    assertThat(analysis.getOverlaps(), hasSize(1));
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Overlap> overlaps = Arrays.asList(new Overlap(Arrays.asList(1, 2), new Hyperrectangle(1, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("0"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(1));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) 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) Test(org.junit.Test)

Aggregations

DTAnalysis (org.kie.dmn.validation.dtanalysis.model.DTAnalysis)63 DMNMessage (org.kie.dmn.api.core.DMNMessage)50 Test (org.junit.Test)46 Bound (org.kie.dmn.validation.dtanalysis.model.Bound)32 Hyperrectangle (org.kie.dmn.validation.dtanalysis.model.Hyperrectangle)32 BigDecimal (java.math.BigDecimal)25 List (java.util.List)16 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.hasSize (org.hamcrest.Matchers.hasSize)16 Assert.assertTrue (org.junit.Assert.assertTrue)16 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)16 ANALYZE_DECISION_TABLE (org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE)16 Overlap (org.kie.dmn.validation.dtanalysis.model.Overlap)15 Arrays (java.util.Arrays)11 Matchers.contains (org.hamcrest.Matchers.contains)11 Matchers.is (org.hamcrest.Matchers.is)7 VALIDATE_COMPILATION (org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION)7 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)7 RangeBoundary (org.kie.dmn.feel.runtime.Range.RangeBoundary)6 DecisionTable (org.kie.dmn.model.api.DecisionTable)5