Search in sources :

Example 1 with SimulationRunMetadata

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

the class ScenarioSimulationEditorBusinessCentralWrapper method setCoverageReport.

protected void setCoverageReport(CoverageReportView.Presenter presenter) {
    ScenarioSimulationModel.Type modelType = scenarioSimulationEditorPresenter.getDataManagementStrategy() instanceof AbstractDMODataManagementStrategy ? ScenarioSimulationModel.Type.RULE : ScenarioSimulationModel.Type.DMN;
    SimulationRunMetadata simulationRunMetadata = lastRunResult != null ? lastRunResult.getSimulationRunMetadata() : null;
    presenter.populateCoverageReport(modelType, simulationRunMetadata);
    if (simulationRunMetadata != null && simulationRunMetadata.getAuditLog() != null) {
        presenter.setDownloadReportCommand(() -> onDownloadReportToCsv(scenarioSimulationEditorPresenter.getExportCallBack(), new ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(scenarioSimulationEditorPresenter.getView()), simulationRunMetadata, modelType));
    }
}
Also used : SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback) AbstractDMODataManagementStrategy(org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMODataManagementStrategy) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 2 with SimulationRunMetadata

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

the class CoverageReportPresenterTest method setup.

@Before
public void setup() {
    presenterSpy = spy(presenter);
    presenterSpy.downloadReportCommand = downloadReportCommandMock;
    when(coverageReportViewMock.getDonutChart()).thenReturn(donutChartMock);
    when(coverageReportViewMock.getList()).thenReturn(list);
    when(coverageReportViewMock.getScenarioList()).thenReturn(scenarioList);
    when(coverageReportViewMock.getDownloadReportButton()).thenReturn(downloadReportButtonMock);
    availableLocal = 10;
    executedLocal = 6;
    coverageLocal = (double) executedLocal / availableLocal * 100;
    outputCounterLocal = new HashMap<>();
    outputCounterLocal.put("d1", 1);
    outputCounterLocal.put("d2", 2);
    scenarioCounterLocal = new HashMap<>();
    Map<String, Integer> scenario1Data = new HashMap<>();
    scenario1Data.put("d1", 1);
    scenario1Data.put("d2", 1);
    Map<String, Integer> scenario2Data = new HashMap<>();
    scenario2Data.put("d2", 1);
    scenarioCounterLocal.put(new ScenarioWithIndex(1, new Scenario()), scenario1Data);
    scenarioCounterLocal.put(new ScenarioWithIndex(2, new Scenario()), scenario2Data);
    simulationRunMetadataLocal = new SimulationRunMetadata(availableLocal, executedLocal, outputCounterLocal, scenarioCounterLocal, auditLog);
}
Also used : HashMap(java.util.HashMap) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) Matchers.anyString(org.mockito.Matchers.anyString) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario) Before(org.junit.Before)

Example 3 with SimulationRunMetadata

use of org.drools.scenariosimulation.api.model.SimulationRunMetadata 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 4 with SimulationRunMetadata

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

the class ScenarioCsvDownloadReportTest method getSimulationRunMetadata.

private SimulationRunMetadata getSimulationRunMetadata(AuditLog auditLog) {
    Random random = new Random();
    Map<String, Integer> rules = new HashMap<>();
    rules.put("Rule,1", random.nextInt(7));
    return new SimulationRunMetadata(random.nextInt(10), random.nextInt(5), rules, Collections.emptyMap(), auditLog);
}
Also used : Random(java.util.Random) HashMap(java.util.HashMap) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata)

Example 5 with SimulationRunMetadata

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

the class ScenarioSimulationEditorPresenterTest method refreshModelContent.

@Test
public void refreshModelContent() {
    when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock);
    List<ScenarioWithIndex> scenarioWithIndex = new ArrayList<>();
    int scenarioNumber = 1;
    int scenarioIndex = scenarioNumber - 1;
    Scenario scenario = mock(Scenario.class);
    scenarioWithIndex.add(new ScenarioWithIndex(scenarioNumber, scenario));
    List<BackgroundDataWithIndex> backgroundDataWithIndex = new ArrayList<>();
    BackgroundData backgroundData = mock(BackgroundData.class);
    backgroundDataWithIndex.add(new BackgroundDataWithIndex(scenarioNumber, backgroundData));
    TestResultMessage testResultMessage = mock(TestResultMessage.class);
    SimulationRunResult testRunResult = new SimulationRunResult(scenarioWithIndex, backgroundDataWithIndex, new SimulationRunMetadata(), testResultMessage);
    presenterSpy.refreshModelContent(testRunResult);
    verify(scenarioSimulationViewMock, times(1)).hideBusyIndicator();
    verify(simulationMock, times(1)).replaceData(eq(scenarioIndex), eq(scenario));
    assertEquals(scenarioSimulationModelMock, presenterSpy.getModel());
    verify(scenarioGridWidgetSpy, times(1)).refreshContent(eq(simulationMock));
    assertEquals(scenarioSimulationContextLocal.getStatus().getSimulation(), simulationMock);
    verify(backgroundMock, times(1)).replaceData(eq(scenarioIndex), eq(backgroundData));
    verify(backgroundGridWidgetSpy, times(1)).refreshContent(eq(backgroundMock));
    assertEquals(scenarioSimulationContextLocal.getStatus().getBackground(), backgroundMock);
    assertEquals(scenarioSimulationModelMock, presenterSpy.getModel());
    verify(abstractScenarioSimulationDocksHandlerMock, times(1)).expandTestResultsDock();
    verify(dataManagementStrategyMock, times(1)).setModel(eq(scenarioSimulationModelMock));
    verify(scenarioSimulationEditorWrapperMock, times(1)).onRefreshedModelContent(eq(testRunResult));
}
Also used : SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) ArrayList(java.util.ArrayList) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Aggregations

SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)12 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 AuditLog (org.drools.scenariosimulation.api.model.AuditLog)5 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Scenario (org.drools.scenariosimulation.api.model.Scenario)3 List (java.util.List)2 Random (java.util.Random)2 CSVPrinter (org.apache.commons.csv.CSVPrinter)2 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)2 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)1 BackgroundDataWithIndex (org.drools.scenariosimulation.api.model.BackgroundDataWithIndex)1 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)1 TestUtils.commonCheckAuditLogLine (org.drools.scenariosimulation.backend.TestUtils.commonCheckAuditLogLine)1 TestUtils.getRandomlyGeneratedDMNMessageList (org.drools.scenariosimulation.backend.TestUtils.getRandomlyGeneratedDMNMessageList)1 AbstractDMODataManagementStrategy (org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMODataManagementStrategy)1