Search in sources :

Example 1 with AuditLogLine

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();
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) IOException(java.io.IOException) Map(java.util.Map)

Example 2 with AuditLogLine

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);
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) Random(java.util.Random)

Example 3 with AuditLogLine

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);
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) Test(org.junit.Test)

Example 4 with AuditLogLine

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());
        }
    }
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) TestUtils.commonCheckAuditLogLine(org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine) ArrayList(java.util.ArrayList) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Mockito.anyString(org.mockito.Mockito.anyString) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) HashSet(java.util.HashSet)

Example 5 with AuditLogLine

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);
    }
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) TestUtils.commonCheckAuditLogLine(org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Scenario(org.drools.scenariosimulation.api.model.Scenario) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) CoverageAgendaListener(org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Aggregations

AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)8 ArrayList (java.util.ArrayList)3 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)3 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)3 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)3 Test (org.junit.Test)3 Map (java.util.Map)2 Random (java.util.Random)2 CSVPrinter (org.apache.commons.csv.CSVPrinter)2 AuditLog (org.drools.scenariosimulation.api.model.AuditLog)2 Scenario (org.drools.scenariosimulation.api.model.Scenario)2 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 TestUtils.getRandomlyGeneratedDMNMessageList (org.drools.scenariosimulation.backend.TestUtils.getRandomlyGeneratedDMNMessageList)1 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)1