Search in sources :

Example 11 with ANALYZE_DECISION_TABLE

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

the class Check1stNFViolationTest method testCheck1stNFViolationCollect.

@Test
public void testCheck1stNFViolationCollect() {
    List<DMNMessage> 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));
}
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)

Example 12 with ANALYZE_DECISION_TABLE

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

the class Check1stNFViolationTest method testCheck1stNFViolation.

@Test
public void testCheck1stNFViolation() {
    List<DMNMessage> validate = validator.validate(getReader("DT1stNFViolation.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)));
    DTAnalysis analysisFIRST = getAnalysis(validate, "_1ca6acde-c1d4-4c50-8e21-f3b11e106f3d");
    assertThat(analysisFIRST.is1stNFViolation(), is(true));
    assertTrue("It should contain at DMNMessage for the 1st NF Violation", validate.stream().anyMatch(p -> p.getSourceId().equals("_1ca6acde-c1d4-4c50-8e21-f3b11e106f3d") && p.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION)));
    DTAnalysis analysisRULE_ORDER = getAnalysis(validate, "_03522945-b520-4b45-ac5e-ef3cbd7f1eaf");
    assertThat(analysisRULE_ORDER.is1stNFViolation(), is(true));
    assertTrue("It should contain at DMNMessage for the 1st NF Violation", validate.stream().anyMatch(p -> p.getSourceId().equals("_03522945-b520-4b45-ac5e-ef3cbd7f1eaf") && 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)

Example 13 with ANALYZE_DECISION_TABLE

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

the class Check1stNFViolationTest method testCheck1stNFViolationDuplicateNoSubsumption.

@Test
public void testCheck1stNFViolationDuplicateNoSubsumption() {
    List<DMNMessage> validate = validator.validate(getReader("DT1stNFViolationDuplicateNoSubsumption.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_221BF4A4-F8D4-466C-96E4-311FE3C9867B");
    assertThat(analysis.is1stNFViolation(), is(true));
    assertThat(analysis.getDuplicateRulesTuples(), hasSize(1));
    assertThat(analysis.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.getMessageType().equals(DMNMessageType.DECISION_TABLE_1STNFVIOLATION)));
    assertThat(analysis.getSubsumptions().isEmpty(), is(false));
    assertTrue("No message about subsumption", validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_SUBSUMPTION_RULE)));
}
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)

Example 14 with ANALYZE_DECISION_TABLE

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

the class OverlapHitPolicyTest method testOverlapHitPolicy.

@Test
public void testOverlapHitPolicy() {
    Definitions definitions = getDefinitions("OverlapHitPolicy.dmn", "https://github.com/kiegroup/drools/kie-dmn/_3010653A-DD3F-4C88-89DA-3FDD845F6604", "OverlapHitPolicy");
    // mutates XML file in the Hit Policy, accordingly to this test parameter.
    ((DecisionTable) ((Decision) definitions.getDrgElement().get(0)).getExpression()).setHitPolicy(hp);
    List<DMNMessage> validate = validator.validate(definitions, VALIDATE_COMPILATION, ANALYZE_DECISION_TABLE);
    checkAnalysis(validate);
    if (hp == HitPolicy.UNIQUE) {
        assertTrue("It should contain at least 1 DMNMessage for the type", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_UNIQUE)));
    } else if (hp == HitPolicy.ANY) {
        assertTrue("It should contain at least 1 DMNMessage for the type", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_ANY)));
    } else {
        LOG.debug("Testing for {} I am expecting there is NOT DMNMessage pertaining to Overlaps", hp);
        assertTrue(validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_UNIQUE)) && validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP_HITPOLICY_ANY)) && validate.stream().noneMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_OVERLAP)));
    }
}
Also used : Arrays(java.util.Arrays) RangeBoundary(org.kie.dmn.feel.runtime.Range.RangeBoundary) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Bound(org.kie.dmn.validation.dtanalysis.model.Bound) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) RunWith(org.junit.runner.RunWith) Definitions(org.kie.dmn.model.api.Definitions) BigDecimal(java.math.BigDecimal) Hyperrectangle(org.kie.dmn.validation.dtanalysis.model.Hyperrectangle) Decision(org.kie.dmn.model.api.Decision) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Parameterized(org.junit.runners.Parameterized) Interval(org.kie.dmn.validation.dtanalysis.model.Interval) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) HitPolicy(org.kie.dmn.model.api.HitPolicy) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Overlap(org.kie.dmn.validation.dtanalysis.model.Overlap) ANALYZE_DECISION_TABLE(org.kie.dmn.validation.DMNValidator.Validation.ANALYZE_DECISION_TABLE) DecisionTable(org.kie.dmn.model.api.DecisionTable) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.api.Definitions) Test(org.junit.Test)

Example 15 with ANALYZE_DECISION_TABLE

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

the class SimpleStringNoGapTest method test.

@Test
public void test() {
    List<DMNMessage> validate = validator.validate(getReader("simpleStringNoGap.dmn"), VALIDATE_COMPILATION, VALIDATE_MODEL, ANALYZE_DECISION_TABLE);
    // Gap Analysis skipped because of free string.
    assertThat(validate, hasSize(1));
    assertTrue("It should contain DMNMessage for the skipped gap analysis", validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_GAP)));
    debugValidatorMsg(validate);
    DTAnalysis analysis = getAnalysis(validate, "_3D5BDDEF-8B71-4797-8662-5026A9C2A112");
    assertThat(analysis.getGaps(), hasSize(0));
    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) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) 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) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) 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