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)));
}
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));
}
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();
}
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;
}
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)));
}
Aggregations