Search in sources :

Example 6 with ANALYZE_DECISION_TABLE

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

the class FailingOutputConstraintsTest method testFailingOutputConstraintsWhenOutputIsSymbol.

@Test
public void testFailingOutputConstraintsWhenOutputIsSymbol() {
    List<DMNMessage> validate = validator.validate(getReader("FailingOutputConstraints2.dmn"), ANALYZE_DECISION_TABLE);
    debugValidatorMsg(validate);
    assertTrue("It should NOT contain DMNMessage for output outside of LoV (using a symbol in output)", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_ANALYSIS_ERROR)));
    DTAnalysis analysis = getAnalysis(validate, "_E72BD036-C550-4992-AA6D-A8AD4666C63A");
    assertThat(analysis.isError(), is(false));
    assertThat(analysis.getGaps(), hasSize(1));
    assertThat(analysis.getOverlaps(), hasSize(0));
}
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) Matchers.is(org.hamcrest.Matchers.is) 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 7 with ANALYZE_DECISION_TABLE

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

the class FailingOutputConstraintsTest method testFailingOutputConstraints.

@Test
public void testFailingOutputConstraints() {
    List<DMNMessage> validate = validator.validate(getReader("FailingOutputConstraints.dmn"), ANALYZE_DECISION_TABLE);
    assertTrue("It should contain DMNMessage for output outside of LoV", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_ANALYSIS_ERROR)));
    debugValidatorMsg(validate);
    DTAnalysis analysis = getAnalysis(validate, "_E72BD036-C550-4992-AA6D-A8AD4666C63A");
    assertThat(analysis.isError(), is(false));
    assertThat(analysis.getGaps(), hasSize(1));
    assertThat(analysis.getOverlaps(), hasSize(0));
}
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) Matchers.is(org.hamcrest.Matchers.is) 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 8 with ANALYZE_DECISION_TABLE

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

the class Check2ndNFViolationTest method testCheck2ndNFViolation.

@Test
public void testCheck2ndNFViolation() {
    List<DMNMessage> validate = validator.validate(getReader("DT2ndNFViolation.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_4e358bae-7012-42dd-acea-e88b3aa3c8b2");
    assertThat(analysis.is2ndNFViolation(), is(true));
    assertThat(analysis.getContractionsViolating2ndNF(), hasSize(1));
    Contraction c2NFViolation = analysis.getContractionsViolating2ndNF().iterator().next();
    assertThat(c2NFViolation.rule, is(1));
    assertThat(c2NFViolation.pairedRules, contains(2));
    assertThat(c2NFViolation.adjacentDimension, is(3));
    assertTrue("It should contain at DMNMessage for the 2nd NF Violation", validate.stream().anyMatch(p -> p.getSourceId().equals("_4e358bae-7012-42dd-acea-e88b3aa3c8b2") && p.getMessageType().equals(DMNMessageType.DECISION_TABLE_2NDNFVIOLATION)));
}
Also used : List(java.util.List) DMNMessage(org.kie.dmn.api.core.DMNMessage) Matchers.contains(org.hamcrest.Matchers.contains) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) Contraction(org.kie.dmn.validation.dtanalysis.model.Contraction) 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) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Contraction(org.kie.dmn.validation.dtanalysis.model.Contraction) Test(org.junit.Test)

Example 9 with ANALYZE_DECISION_TABLE

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

Example 10 with ANALYZE_DECISION_TABLE

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

the class Check1stNFViolationTest method testCheck1stNFViolationB.

@Test
public void testCheck1stNFViolationB() {
    List<DMNMessage> validate = validator.validate(getReader("DT1stNFViolationB.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysisDuplicate = getAnalysis(validate, "_053034d5-0e1f-4c4a-8513-ab3c6ba538db");
    assertThat(analysisDuplicate.is1stNFViolation(), is(true));
    assertThat(analysisDuplicate.getDuplicateRulesTuples(), hasSize(1));
    assertThat(analysisDuplicate.getDuplicateRulesTuples(), contains(Collections.singletonList(Arrays.asList(1, 2)).toArray()));
    assertTrue("It should contain at DMNMessage for the 1st NF Violation", validate.stream().anyMatch(p -> p.getSourceId().equals("_053034d5-0e1f-4c4a-8513-ab3c6ba538db") && p.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION)));
}
Also used : Arrays(java.util.Arrays) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) List(java.util.List) Level(org.kie.api.builder.Message.Level) Matchers.contains(org.hamcrest.Matchers.contains) 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) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Collections(java.util.Collections) DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) 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