Skip to content

Commit

Permalink
VAL-406 Added the passed Drools assertions to RVF report
Browse files Browse the repository at this point in the history
  • Loading branch information
QuyenLy87 committed Sep 3, 2024
1 parent 5f3474a commit 30b834e
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ private void convertDroolsRuleToAssertion(File droolsRulesSubfile) throws IOExce
// check for severity
severityWarning = severityWarning || detectSeverity(line, "Severity.WARNING");
severityError = severityError || detectSeverity(line, "Severity.ERROR");
if (assertion != null && "end".equals(line.trim())) {
assertion.setSeverity(buildSeverity(severityWarning, severityError));
}
setSeverityIfNeeded(assertion, line, severityWarning, severityError);
}
}
}
Expand All @@ -147,6 +145,12 @@ private static UUID extractUuid(String line) {
return null;
}

private void setSeverityIfNeeded(Assertion assertion, String line, boolean severityWarning, boolean severityError) {
if (assertion != null && "end".equals(line.trim()) && (severityWarning || severityError)) {
assertion.setSeverity(buildSeverity(severityWarning, severityError));
}
}

private static boolean detectSeverity(String line, String type) {
return line.contains(type);
}
Expand Down Expand Up @@ -217,6 +221,7 @@ private ValidationReport constructValidationReport(ValidationRunConfig validatio
List<TestRunItem> warningAssertions = new ArrayList<>();
int failureExportMax = validationConfig.getFailureExportMax() != null ? validationConfig.getFailureExportMax() : 10;
Map<UUID, Assertion> uuidToAssertionMap = assertions.stream().collect(Collectors.toMap(Assertion::getUuid, Function.identity()));
Set<UUID> failedAssertionUUIDs = new HashSet<>();

// Convert the Drools validation report into RVF report format
invalidContentMap.keySet().forEach(ruleId -> {
Expand Down Expand Up @@ -247,10 +252,24 @@ private ValidationReport constructValidationReport(ValidationRunConfig validatio
} else {
failedAssertions.add(validationRule);
}
failedAssertionUUIDs.add(validationRule.getAssertionUuid());
});
ValidationReport validationReport = new ValidationReport();
validationReport.addFailedAssertions(failedAssertions);
validationReport.addWarningAssertions(warningAssertions);

Set<Assertion> passedAssertions = assertions.stream().filter(item -> validationConfig.getDroolsRulesGroupList().stream().anyMatch(item.getGroups()::contains) && !failedAssertionUUIDs.contains(item.getUuid())).collect(Collectors.toSet());
validationReport.addPassedAssertions(passedAssertions.stream().map(item -> {
TestRunItem testRunItem = new TestRunItem();
testRunItem.setFailureCount(0L);
testRunItem.setTestCategory("");
testRunItem.setTestType(TestType.DROOL_RULES);
testRunItem.setSeverity(item.getSeverity());
testRunItem.setAssertionUuid(item.getUuid());
testRunItem.setAssertionText(item.getAssertionText());
return testRunItem;
}).toList());

return validationReport;
}

Expand Down

0 comments on commit 30b834e

Please sign in to comment.