Search in sources :

Example 36 with DTAnalysis

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

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

the class Check2ndNFViolationTest method testCheck2ndNFViolationWasADash.

@Test
public void testCheck2ndNFViolationWasADash() {
    List<DMNMessage> validate = validator.validate(getReader("DT2ndNFWasADash.dmn"), ANALYZE_DECISION_TABLE);
    DTAnalysis analysis = getAnalysis(validate, "_C40525EF-9735-410B-A070-E0336E108268");
    assertThat(analysis.is2ndNFViolation(), is(true));
    assertThat(analysis.getCellsViolating2ndNF(), hasSize(1));
}
Also used : DMNMessage(org.kie.dmn.api.core.DMNMessage) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) Test(org.junit.Test)

Example 38 with DTAnalysis

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

the class DMNValidatorImpl method analyseDT.

private List<DMNMessage> analyseDT(DMNResource dmnR, Set<Validation> flags) {
    if (dmnR != null) {
        DMNCompilerImpl compiler = new DMNCompilerImpl(dmnCompilerConfig);
        // must use this internal method to ensure the Definitions model is the same (identity wise)
        DMNModel model = compiler.compile(dmnR.getDefinitions(), dmnR.getResAndConfig().getResource(), Collections.emptyList());
        if (model != null) {
            List<DTAnalysis> vs = dmnDTValidator.analyse(model, flags);
            return processDMNDTValidatorMessages(dmnR, vs);
        } else {
            throw new IllegalStateException("Compiled model is null!");
        }
    }
    return Collections.emptyList();
}
Also used : DMNCompilerImpl(org.kie.dmn.core.compiler.DMNCompilerImpl) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 39 with DTAnalysis

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

the class DMNDTAnalyser method analyse.

@Override
public List<DTAnalysis> analyse(DMNModel model, Set<DMNValidator.Validation> flags) {
    if (!flags.contains(Validation.ANALYZE_DECISION_TABLE)) {
        throw new IllegalArgumentException();
    }
    List<DTAnalysis> results = new ArrayList<>();
    List<? extends DecisionTable> decisionTables = model.getDefinitions().findAllChildren(DecisionTable.class);
    for (DecisionTable dt : decisionTables) {
        try {
            DTAnalysis result = dmnDTAnalysis(model, dt, flags);
            results.add(result);
        } catch (Throwable t) {
            LOG.debug("Skipped dmnDTAnalysis for table: {}", dt.getId(), t);
            DTAnalysis result = DTAnalysis.ofError(dt, t);
            results.add(result);
        }
    }
    return results;
}
Also used : DecisionTable(org.kie.dmn.model.api.DecisionTable) ArrayList(java.util.ArrayList) DTAnalysis(org.kie.dmn.validation.dtanalysis.model.DTAnalysis)

Example 40 with DTAnalysis

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

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