Search in sources :

Example 6 with AuditLogLine

use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools by kiegroup.

the class SimulationRunMetadataBuilderTest method build.

@Test
public void build() {
    ScenarioWithIndex scenarioWithIndex1 = new ScenarioWithIndex(1, new Scenario());
    ScenarioResultMetadata result1 = new ScenarioResultMetadata(scenarioWithIndex1);
    result1.addExecuted("d1");
    result1.addExecuted("d2");
    result1.addAvailable("d1");
    result1.addAvailable("d2");
    result1.addAvailable("d3");
    List<DMNMessage> messagesResult1decision1 = getRandomlyGeneratedDMNMessageList();
    List<DMNMessage> messagesResult1decision2 = getRandomlyGeneratedDMNMessageList();
    Map<Integer, List<String>> expectedResult1Decision1 = fillAuditMessagesForDecision(result1, messagesResult1decision1, "d1");
    Map<Integer, List<String>> expectedResult1Decision2 = fillAuditMessagesForDecision(result1, messagesResult1decision2, "d2");
    ScenarioResultMetadata result2 = new ScenarioResultMetadata(new ScenarioWithIndex(2, new Scenario()));
    List<String> expectedDecisionsResult2 = Arrays.asList("d1", "d3");
    result2.addExecuted(expectedDecisionsResult2.get(0));
    result2.addExecuted(expectedDecisionsResult2.get(1));
    result2.addAvailable("d1");
    result2.addAvailable("d2");
    result2.addAvailable("d3");
    List<DMNMessage> messagesResult2decision1 = getRandomlyGeneratedDMNMessageList();
    List<DMNMessage> messagesResult2decision3 = getRandomlyGeneratedDMNMessageList();
    Map<Integer, List<String>> expectedResult2Decision1 = fillAuditMessagesForDecision(result1, messagesResult2decision1, "d1");
    Map<Integer, List<String>> expectedResult2Decision3 = fillAuditMessagesForDecision(result1, messagesResult2decision3, "d3");
    SimulationRunMetadataBuilder builder = SimulationRunMetadataBuilder.create();
    builder.addScenarioResultMetadata(result1);
    builder.addScenarioResultMetadata(result2);
    SimulationRunMetadata build = builder.build();
    assertEquals(3, build.getAvailable());
    assertEquals(3, build.getExecuted());
    assertEquals(100, build.getCoveragePercentage(), 0.1);
    assertEquals(2, build.getOutputCounter().get("d1"), 0.1);
    assertEquals(1, build.getOutputCounter().get("d2"), 0.1);
    assertEquals(2, build.getScenarioCounter().get(scenarioWithIndex1).size(), 0.1);
    AuditLog retrieved = build.getAuditLog();
    assertNotNull(retrieved);
    final List<AuditLogLine> auditLogLines = retrieved.getAuditLogLines();
    assertNotNull(auditLogLines);
    assertEquals(auditLogLines.size(), messagesResult1decision1.size() + messagesResult1decision2.size() + messagesResult2decision1.size() + messagesResult2decision3.size());
    checkAuditLogLine(auditLogLines, expectedResult1Decision1, expectedResult1Decision2, expectedResult2Decision1, expectedResult2Decision3);
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) TestUtils.commonCheckAuditLogLine(org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine) AuditLog(org.drools.scenariosimulation.api.model.AuditLog) Scenario(org.drools.scenariosimulation.api.model.Scenario) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DMNMessage(org.kie.dmn.api.core.DMNMessage) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) TestUtils.getRandomlyGeneratedDMNMessageList(org.drools.scenariosimulation.backend.TestUtils.getRandomlyGeneratedDMNMessageList) ArrayList(java.util.ArrayList) List(java.util.List) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Test(org.junit.Test)

Example 7 with AuditLogLine

use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools-wb by kiegroup.

the class ScenarioCsvDownloadReportTest 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 8 with AuditLogLine

use of org.drools.scenariosimulation.api.model.AuditLogLine in project drools-wb by kiegroup.

the class ScenarioCsvDownloadReportTest method commonGetReport.

private void commonGetReport(ScenarioSimulationModel.Type type, String[] overallStats, String[] counterHeader, String[] auditHeader) {
    AuditLog auditLog = new AuditLog();
    IntStream.range(0, 6).forEach(index -> auditLog.addAuditLogLine(getAuditLogLine()));
    SimulationRunMetadata simulationRunMetadata = getSimulationRunMetadata(auditLog);
    String retrieved = scenarioCsvDownloadReport.getReport(simulationRunMetadata, type);
    assertNotNull(retrieved);
    String[] retrievedLines = retrieved.split("\r\n");
    commonCheckHeader(overallStats, retrievedLines[0]);
    List<String> overallStatsData = Arrays.asList(String.valueOf(simulationRunMetadata.getAvailable()), String.valueOf(simulationRunMetadata.getExecuted()), String.valueOf(simulationRunMetadata.getCoveragePercentage()));
    commonCheckRetrievedString(retrievedLines[1], overallStatsData);
    assertTrue(retrievedLines[2].isEmpty());
    commonCheckHeader(counterHeader, retrievedLines[3]);
    Map.Entry<String, Integer> entry = simulationRunMetadata.getOutputCounter().entrySet().iterator().next();
    List<String> rulesCounterData = Arrays.asList("\"" + entry.getKey() + "\"", String.valueOf(entry.getValue()));
    commonCheckRetrievedString(retrievedLines[4], rulesCounterData);
    assertTrue(retrievedLines[5].isEmpty());
    commonCheckHeader(auditHeader, retrievedLines[6]);
    for (int i = 7; i < retrievedLines.length; i++) {
        AuditLogLine auditLogLine = auditLog.getAuditLogLines().get(i - 7);
        List<String> auditData = Arrays.asList(String.valueOf(auditLogLine.getScenarioIndex()), "\"" + auditLogLine.getScenario() + "\"", String.valueOf(auditLogLine.getExecutionIndex()), "\"" + auditLogLine.getDecisionOrRuleName() + "\"", auditLogLine.getResult(), auditLogLine.getMessage().orElse(""));
        commonCheckRetrievedString(retrievedLines[i], auditData);
    }
}
Also used : AuditLogLine(org.drools.scenariosimulation.api.model.AuditLogLine) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) HashMap(java.util.HashMap) Map(java.util.Map) AuditLog(org.drools.scenariosimulation.api.model.AuditLog)

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