Search in sources :

Example 46 with DTAnalysis

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

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

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

the class ContractionRulesTest method testContractionRules.

@Test
public void testContractionRules() {
    List<DMNMessage> validate = validator.validate(getReader("Contraction.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_01d9abb9-b968-49c0-b6ab-909f3e03d8d3");
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(0));
    // Contraction count.
    assertThat(analysis.getContractions(), hasSize(2));
    List<Contraction> results = Arrays.asList(new Contraction(4, Arrays.asList(5), 2, Arrays.asList(new Interval(RangeBoundary.CLOSED, new BigDecimal("0.35"), Interval.POS_INF, RangeBoundary.CLOSED, 0, 0))), new Contraction(3, Arrays.asList(6), 1, Arrays.asList(new Interval(RangeBoundary.CLOSED, new BigDecimal("600"), Interval.POS_INF, RangeBoundary.CLOSED, 0, 0))));
    assertThat(results, hasSize(2));
    assertThat(analysis.getContractions(), contains(results.toArray()));
    assertThat("It should contain 2 DMNMessage for the Contraction", validate.stream().filter(p -> p.getMessageType().equals(DMNMessageType.DECISION_TABLE_CONTRACTION_RULE)).collect(Collectors.toList()), hasSize(2));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Contraction(org.kie.dmn.validation.dtanalysis.model.Contraction) BigDecimal(java.math.BigDecimal) Interval(org.kie.dmn.validation.dtanalysis.model.Interval) Test(org.junit.Test)

Example 49 with DTAnalysis

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

the class DTinBKMTest method testDTnestedEverywhere.

@Test
public void testDTnestedEverywhere() {
    List<DMNMessage> validate = validator.validate(getReader("dtInBKM.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_860A5A56-0C43-4B42-B1DB-7415984E5624");
    assertThat(analysis.getGaps(), hasSize(0));
    assertThat(analysis.getOverlaps(), hasSize(0));
    assertThat(validate, hasSize(1));
    assertThat(validate.get(0).getMessageType(), is(DMNMessageType.DECISION_TABLE_ANALYSIS_EMPTY));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 50 with DTAnalysis

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

the class BuiltinAndOtherValuesTest method testWeirdPosNeg.

@Test
public void testWeirdPosNeg() {
    List<DMNMessage> validate = validator.validate(getReader("weirdPosNeg.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_54ae95be-6866-4dc1-8c10-1c5a4dd15c93");
    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 same values
    assertThat(analysis.getGaps(), contains(gaps.toArray()));
    // assert OVERLAPs count.
    assertThat(analysis.getOverlaps(), hasSize(0));
}
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)

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