Search in sources :

Example 1 with AuditLog

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

the class ScenarioSimulationEditorBusinessCentralWrapperTest method setCoverageReport.

@Test
public void setCoverageReport() {
    AuditLog auditLogMock = mock(AuditLog.class);
    CoverageReportView.Presenter presenterSpy = spy(CoverageReportView.Presenter.class);
    scenarioSimulationEditorBusinessClientWrapper.setCoverageReport(presenterSpy);
    verify(presenterSpy, times(1)).populateCoverageReport(eq(DMN), eq(null));
    // 
    reset(presenterSpy, simulationRunMetadataMock, scenarioSimulationEditorBusinessClientWrapper);
    scenarioSimulationEditorBusinessClientWrapper.lastRunResult = simulationRunResultMock;
    scenarioSimulationEditorBusinessClientWrapper.setCoverageReport(presenterSpy);
    verify(presenterSpy, times(1)).populateCoverageReport(eq(DMN), eq(simulationRunMetadataMock));
    verify(presenterSpy, never()).setDownloadReportCommand(any());
    // 
    reset(presenterSpy, simulationRunMetadataMock, scenarioSimulationEditorBusinessClientWrapper);
    when(simulationRunMetadataMock.getAuditLog()).thenReturn(auditLogMock);
    scenarioSimulationEditorBusinessClientWrapper.lastRunResult = simulationRunResultMock;
    scenarioSimulationEditorBusinessClientWrapper.setCoverageReport(presenterSpy);
    verify(presenterSpy, times(1)).populateCoverageReport(eq(DMN), eq(simulationRunMetadataMock));
    verify(presenterSpy, times(1)).setDownloadReportCommand(commandArgumentCaptor.capture());
    commandArgumentCaptor.getValue().execute();
    verify(scenarioSimulationEditorBusinessClientWrapper, times(1)).onDownloadReportToCsv(eq(exportCallBackMock), isA(ScenarioSimulationHasBusyIndicatorDefaultErrorCallback.class), eq(simulationRunMetadataMock), eq(DMN));
    // 
    reset(presenterSpy, simulationRunMetadataMock, scenarioSimulationEditorBusinessClientWrapper);
    scenarioSimulationEditorBusinessClientWrapper.lastRunResult = null;
    when(scenarioSimulationEditorPresenterMock.getDataManagementStrategy()).thenReturn(mock(AbstractDMODataManagementStrategy.class));
    scenarioSimulationEditorBusinessClientWrapper.setCoverageReport(presenterSpy);
    verify(presenterSpy, times(1)).populateCoverageReport(eq(RULE), eq(null));
    // 
    reset(presenterSpy, simulationRunMetadataMock, scenarioSimulationEditorBusinessClientWrapper);
    scenarioSimulationEditorBusinessClientWrapper.lastRunResult = simulationRunResultMock;
    scenarioSimulationEditorBusinessClientWrapper.setCoverageReport(presenterSpy);
    verify(presenterSpy, times(1)).populateCoverageReport(eq(RULE), eq(simulationRunMetadataMock));
    verify(presenterSpy, never()).setDownloadReportCommand(any());
    // 
    reset(presenterSpy, simulationRunMetadataMock, scenarioSimulationEditorBusinessClientWrapper);
    when(simulationRunMetadataMock.getAuditLog()).thenReturn(auditLogMock);
    scenarioSimulationEditorBusinessClientWrapper.lastRunResult = simulationRunResultMock;
    scenarioSimulationEditorBusinessClientWrapper.setCoverageReport(presenterSpy);
    verify(presenterSpy, times(1)).populateCoverageReport(eq(RULE), eq(simulationRunMetadataMock));
    verify(presenterSpy, times(1)).setDownloadReportCommand(commandArgumentCaptor.capture());
    commandArgumentCaptor.getValue().execute();
    verify(scenarioSimulationEditorBusinessClientWrapper, times(1)).onDownloadReportToCsv(eq(exportCallBackMock), isA(ScenarioSimulationHasBusyIndicatorDefaultErrorCallback.class), eq(simulationRunMetadataMock), eq(RULE));
}
Also used : CoverageReportView(org.drools.workbench.screens.scenariosimulation.businesscentral.client.rightpanel.coverage.CoverageReportView) ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback) AbstractDMODataManagementStrategy(org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMODataManagementStrategy) AuditLog(org.drools.scenariosimulation.api.model.AuditLog) Test(org.junit.Test) AbstractScenarioSimulationEditorTest(org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)

Example 2 with AuditLog

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

the class ScenarioCsvDownloadReportTest method printOverallStatsLine.

@Test
public void printOverallStatsLine() throws IOException {
    StringBuilder stringBuilder = new StringBuilder();
    CSVPrinter printer = getCSVPrinter(stringBuilder);
    AuditLog auditLog = new AuditLog();
    auditLog.addAuditLogLine(getAuditLogLine());
    SimulationRunMetadata simulationRunMetadata = getSimulationRunMetadata(auditLog);
    scenarioCsvDownloadReport.printOverallStatsLine(printer, simulationRunMetadata.getAvailable(), simulationRunMetadata.getExecuted(), simulationRunMetadata.getCoveragePercentage());
    String retrieved = stringBuilder.toString();
    List<String> data = Arrays.asList(String.valueOf(simulationRunMetadata.getAvailable()), String.valueOf(simulationRunMetadata.getExecuted()), String.valueOf(simulationRunMetadata.getCoveragePercentage()));
    commonCheckRetrievedString(retrieved, data);
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) AuditLog(org.drools.scenariosimulation.api.model.AuditLog) Test(org.junit.Test)

Example 3 with AuditLog

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

the class RunnerReportServiceImplTest method getReportRULE.

@Test
public void getReportRULE() {
    AuditLog auditLog = new AuditLog();
    IntStream.range(0, 6).forEach(index -> auditLog.addAuditLogLine(getAuditLogLine()));
    String report = runnerReportServiceImpl.getReport(getSimulationRunMetadata(auditLog), ScenarioSimulationModel.Type.RULE);
    assertNotNull(report);
    assertFalse(report.isEmpty());
    String[] reportLine = report.split("\\r\\n");
    assertTrue(report.contains("RULE"));
    assertFalse(report.contains("DECISION"));
    assertEquals(7 + auditLog.getAuditLogLines().size(), reportLine.length);
    for (int i = 0; i < reportLine.length; i++) {
        assertNotNull(reportLine[i]);
    }
}
Also used : AuditLog(org.drools.scenariosimulation.api.model.AuditLog) Test(org.junit.Test)

Example 4 with AuditLog

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

the class SimulationRunMetadataBuilder method build.

public SimulationRunMetadata build() {
    int available = 0;
    Map<String, Integer> outputCounter = new HashMap<>();
    Map<ScenarioWithIndex, Map<String, Integer>> scenarioCounter = new HashMap<>();
    AuditLog auditLog = new AuditLog();
    for (ScenarioResultMetadata scenarioResultMetadatum : scenarioResultMetadata) {
        // this value is the same for all the scenarios
        available = scenarioResultMetadatum.getAvailable().size();
        scenarioResultMetadatum.getExecutedWithCounter().forEach((name, counter) -> outputCounter.compute(name, (key, number) -> number == null ? counter : number + counter));
    }
    for (ScenarioResultMetadata scenarioResultMetadatum : scenarioResultMetadata) {
        scenarioCounter.put(scenarioResultMetadatum.getScenarioWithIndex(), scenarioResultMetadatum.getExecutedWithCounter());
        auditLog.addAuditLogLines(scenarioResultMetadatum.getAuditLogLines());
    }
    return new SimulationRunMetadata(available, outputCounter.keySet().size(), outputCounter, scenarioCounter, auditLog);
}
Also used : List(java.util.List) Map(java.util.Map) AuditLog(org.drools.scenariosimulation.api.model.AuditLog) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) HashMap(java.util.HashMap) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Map(java.util.Map) HashMap(java.util.HashMap) AuditLog(org.drools.scenariosimulation.api.model.AuditLog)

Example 5 with AuditLog

use of org.drools.scenariosimulation.api.model.AuditLog 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)

Aggregations

AuditLog (org.drools.scenariosimulation.api.model.AuditLog)8 Test (org.junit.Test)6 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CSVPrinter (org.apache.commons.csv.CSVPrinter)2 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)2 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)2 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Scenario (org.drools.scenariosimulation.api.model.Scenario)1 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)1 TestUtils.getRandomlyGeneratedDMNMessageList (org.drools.scenariosimulation.backend.TestUtils.getRandomlyGeneratedDMNMessageList)1 CoverageReportView (org.drools.workbench.screens.scenariosimulation.businesscentral.client.rightpanel.coverage.CoverageReportView)1 AbstractScenarioSimulationEditorTest (org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)1 AbstractDMODataManagementStrategy (org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMODataManagementStrategy)1 ScenarioSimulationHasBusyIndicatorDefaultErrorCallback (org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1