use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReport method getReport.
/**
* @param simulationRunMetadata the <code>SimulationRunMetadata</code> to print out
* @param modelType
* @return
* @throws IOException
*/
public String getReport(SimulationRunMetadata simulationRunMetadata, ScenarioSimulationModel.Type modelType) {
StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter printer = new CSVPrinter(stringBuilder, CSVFormat.DEFAULT.withNullString(""))) {
generateOverallStatsHeader(printer, modelType);
printOverallStatsLine(printer, simulationRunMetadata.getAvailable(), simulationRunMetadata.getExecuted(), simulationRunMetadata.getCoveragePercentage());
Map<String, Integer> outputCounter = simulationRunMetadata.getOutputCounter();
if (outputCounter != null && !outputCounter.isEmpty()) {
printer.println();
generateRulesCounterHeader(printer, modelType);
for (Map.Entry<String, Integer> entry : outputCounter.entrySet()) {
printRulesCounterLine(printer, entry.getKey(), entry.getValue());
}
}
List<AuditLogLine> auditLogLines = simulationRunMetadata.getAuditLog().getAuditLogLines();
if (auditLogLines != null && !auditLogLines.isEmpty()) {
printer.println();
generateAuditLogHeader(printer, modelType);
for (AuditLogLine auditLogLine : auditLogLines) {
printAuditLogLine(auditLogLine, printer);
}
}
} catch (IOException e) {
throw ExceptionUtilities.handleException(e);
}
return stringBuilder.toString();
}
use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools-wb by kiegroup.
the class RunnerReportServiceImplTest method getAuditLogLine.
private AuditLogLine getAuditLogLine() {
Random random = new Random();
String message = random.nextBoolean() ? "WARN: Error during evaluation" : null;
return new AuditLogLine(random.nextInt(3), "sce,nario-" + random.nextInt(5), random.nextInt(6), "Ru,le-" + random.nextInt(), "INFO", message);
}
use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools-wb by kiegroup.
the class ScenarioCsvDownloadReportTest method printAuditLogLine.
@Test
public void printAuditLogLine() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
CSVPrinter printer = getCSVPrinter(stringBuilder);
AuditLogLine auditLogLine = getAuditLogLine();
scenarioCsvDownloadReport.printAuditLogLine(auditLogLine, printer);
String retrieved = stringBuilder.toString();
List<String> data = Arrays.asList(String.valueOf(auditLogLine.getScenarioIndex()), "\"" + auditLogLine.getScenario() + "\"", String.valueOf(auditLogLine.getExecutionIndex()), "\"" + auditLogLine.getDecisionOrRuleName() + "\"", auditLogLine.getResult(), auditLogLine.getMessage().orElse(""));
commonCheckRetrievedString(retrieved, data);
}
use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools by kiegroup.
the class DMNScenarioRunnerHelperTest method commonExtractResultMetadata.
public void commonExtractResultMetadata(List<DMNMessage> messages) {
Set<DecisionNode> decisions = new HashSet<>();
IntStream.range(0, 5).forEach(index -> decisions.add(createDecisionMock("decision" + index)));
when(dmnModelMock.getDecisions()).thenReturn(decisions);
List<DMNDecisionResult> decisionResults = new ArrayList<>();
decisionResults.add(createDecisionResultMock("decision2", true, messages));
decisionResults.add(createDecisionResultMock("decision3", false, messages));
when(dmnResultMock.getDecisionResults()).thenReturn(decisionResults);
ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, scenario1);
ScenarioResultMetadata scenarioResultMetadata = runnerHelper.extractResultMetadata(requestContextMock, scenarioWithIndex);
assertEquals(scenarioWithIndex, scenarioResultMetadata.getScenarioWithIndex());
assertEquals(5, scenarioResultMetadata.getAvailable().size());
assertTrue(scenarioResultMetadata.getAvailable().contains("decision1"));
assertEquals(1, scenarioResultMetadata.getExecuted().size());
assertTrue(scenarioResultMetadata.getExecuted().contains("decision2"));
assertFalse(scenarioResultMetadata.getExecuted().contains("decision3"));
final List<AuditLogLine> auditLogLines = scenarioResultMetadata.getAuditLogLines();
assertNotNull(auditLogLines);
if (messages == null) {
assertEquals(decisionResults.size(), auditLogLines.size());
for (int i = 0; i < decisionResults.size(); i++) {
commonCheckAuditLogLine(auditLogLines.get(i), decisionResults.get(i).getDecisionName(), decisionResults.get(i).getEvaluationStatus().name(), null);
}
} else {
List<String> expectedDecisions = Arrays.asList("decision2", "decision3");
List<String> expectedResults = Arrays.asList(DecisionEvaluationStatus.SUCCEEDED.toString(), DecisionEvaluationStatus.FAILED.toString());
int expectedLines = messages.size() * expectedDecisions.size();
assertEquals(expectedLines, auditLogLines.size());
for (int i = 0; i < auditLogLines.size(); i++) {
int messagesIndex = i < messages.size() ? i : i - messages.size();
String decisionName = i < messages.size() ? expectedDecisions.get(0) : expectedDecisions.get(1);
String expectedResultName = i < messages.size() ? expectedResults.get(0) : expectedResults.get(1);
commonCheckAuditLogLine(auditLogLines.get(i), decisionName, expectedResultName, messages.get(messagesIndex).getLevel().name() + ": " + messages.get(messagesIndex).getText());
}
}
}
use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools by kiegroup.
the class RuleScenarioRunnerHelperTest method extractResultMetadata.
@Test
public void extractResultMetadata() {
Map<String, Integer> coverageData = new LinkedHashMap<>();
coverageData.put("rule1", 2);
coverageData.put("rule2", 2);
CoverageAgendaListener coverageAgendaListenerMock = createCoverageAgendaListenerWithData(coverageData);
ScenarioWithIndex scenarioWithIndexMock = mock(ScenarioWithIndex.class);
Scenario scenarioMock = mock(Scenario.class);
when(scenarioMock.getDescription()).thenReturn("DESCRIPTION");
when(scenarioWithIndexMock.getScesimData()).thenReturn(scenarioMock);
Map<String, Object> requestContext = new LinkedHashMap<>();
requestContext.put(COVERAGE_LISTENER, coverageAgendaListenerMock);
requestContext.put(RULES_AVAILABLE, coverageData.keySet());
ScenarioResultMetadata scenarioResultMetadata = runnerHelper.extractResultMetadata(requestContext, scenarioWithIndexMock);
assertEquals(scenarioWithIndexMock, scenarioResultMetadata.getScenarioWithIndex());
assertEquals(2, scenarioResultMetadata.getAvailable().size());
assertEquals(2, scenarioResultMetadata.getExecuted().size());
assertEquals((Integer) 2, scenarioResultMetadata.getExecutedWithCounter().get("rule1"));
assertEquals((Integer) 2, scenarioResultMetadata.getExecutedWithCounter().get("rule2"));
List<String> expectedMessages = new ArrayList<>();
commonAddMessageString(Arrays.asList("rule1", "rule2"), expectedMessages);
final List<AuditLogLine> auditLogLines = scenarioResultMetadata.getAuditLogLines();
assertEquals(expectedMessages.size(), auditLogLines.size());
for (int i = 0; i < expectedMessages.size(); i++) {
commonCheckAuditLogLine(auditLogLines.get(i), expectedMessages.get(i), ConstantsHolder.EXECUTED, null);
}
}
Aggregations