Search in sources :

Example 1 with ANALYZE_DECISION_TABLE

use of org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE in project drools by kiegroup.

the class HitPolicyFirstTest method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("DTAnalysisFirst.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_38EB6C20-6DF4-4EA0-A421-206B9F31AF22");
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(0));
    assertTrue("It should contain at least 1 DMNMessage for the type " + DMNMessageType.DECISION_TABLE_1STNFVIOLATION, validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION)));
}
Also used : List(java.util.List) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assert.assertTrue(org.junit.Assert.assertTrue) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) Test(org.junit.Test) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 2 with ANALYZE_DECISION_TABLE

use of org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE in project drools by kiegroup.

the class MaskTest method test_MaskTest.

@Test
public void test_MaskTest() {
    List<DMNMessage> validate = validator.validate(getReader("MaskTest.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(2, 1), new Hyperrectangle(3, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("18"), RangeBoundary.CLOSED, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound("L", RangeBoundary.CLOSED, null), new Bound("M", RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(1));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
    // MaskedRules count.
    assertThat(analysis.getMaskedRules(), hasSize(1));
    List<MaskedRule> maskedRules = Arrays.asList(new MaskedRule(1, 2));
    assertThat(maskedRules, hasSize(1));
    assertThat(analysis.getMaskedRules(), contains(maskedRules.toArray()));
    assertTrue("It should contain at least 1 DMNMessage for the MaskedRule", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_MASKED_RULE)));
    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) 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) 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) MaskedRule(org.kie.dmn.validation.dtanalysis.model.MaskedRule) Test(org.junit.Test)

Example 3 with ANALYZE_DECISION_TABLE

use of org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE 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 4 with ANALYZE_DECISION_TABLE

use of org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE in project drools by kiegroup.

the class RecommenderHitPolicyTest method testGaps.

@Test
public void testGaps() {
    Definitions definitions = getDefinitions("RecommenderHitPolicy1.dmn", "http://www.trisotech.com/definitions/_50aea0bb-4482-48f6-acfe-4abc1a1bd0d6", "Drawing 1");
    List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_3aa68aee-6314-482f-a0be-84c2411d65d7");
    debugValidatorMsg(validate);
    assertThat(analysis.getGaps(), hasSize(1));
    assertTrue(validate.stream().noneMatch(m -> m.getMessageType() == DMNMessageType.DECISION_TABLE_HITPOLICY_RECOMMENDER));
}
Also used : Arrays(java.util.Arrays) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) 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) Definitions(org.kie.dmn.model.api.Definitions) HitPolicy(org.kie.dmn.model.api.HitPolicy) List(java.util.List) Decision(org.kie.dmn.model.api.Decision) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) 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) Definitions(org.kie.dmn.model.api.Definitions) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 5 with ANALYZE_DECISION_TABLE

use of org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE in project drools by kiegroup.

the class SubsumptionRulesTest method testSubsumptionRules.

@Test
public void testSubsumptionRules() {
    List<DMNMessage> validate = validator.validate(getReader("Subsumption.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_82100fc5-8799-4ee2-981f-215ded39e68a");
    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(2, 3), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("21"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(false, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.OPEN, null))))), new Overlap(Arrays.asList(2, 4), new Hyperrectangle(2, Arrays.asList(Interval.newFromBounds(new Bound(new BigDecimal("21"), RangeBoundary.OPEN, null), new Bound(Interval.POS_INF, RangeBoundary.CLOSED, null)), Interval.newFromBounds(new Bound(true, RangeBoundary.CLOSED, null), new Bound(true, RangeBoundary.CLOSED, null))))));
    assertThat(overlaps, hasSize(2));
    // Assert OVERLAPs same values
    assertThat(analysis.getOverlaps(), contains(overlaps.toArray()));
    // Subsumption count.
    assertThat(analysis.getSubsumptions(), hasSize(1));
    List<Subsumption> results = Arrays.asList(new Subsumption(2, 4));
    assertThat(results, hasSize(1));
    assertThat(analysis.getSubsumptions(), contains(results.toArray()));
    assertTrue("It should contain at least 1 DMNMessage for the Subsumtption", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_SUBSUMPTION_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) Subsumption(org.kie.dmn.validation.dtanalysis.model.Subsumption) 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) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Subsumption(org.kie.dmn.validation.dtanalysis.model.Subsumption) 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

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 Test (org.junit.Test)16 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)16 ANALYZE_DECISION_TABLE (org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE)16 DTAnalysis (org.kie.dmn.validation.dtanalysis.model.DTAnalysis)16 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 RangeBoundary (org.kie.dmn.feel.runtime.Range.RangeBoundary)6 Bound (org.kie.dmn.validation.dtanalysis.model.Bound)6 Hyperrectangle (org.kie.dmn.validation.dtanalysis.model.Hyperrectangle)6 Interval (org.kie.dmn.validation.dtanalysis.model.Interval)6 Overlap (org.kie.dmn.validation.dtanalysis.model.Overlap)6 BigDecimal (java.math.BigDecimal)5 Collections (java.util.Collections)4