Search in sources :

Example 11 with ScenarioWithIndex

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

the class ScenarioSimulationEditorPresenter method refreshModelContent.

protected void refreshModelContent(SimulationRunResult newData) {
    view.hideBusyIndicator();
    if (this.model == null) {
        return;
    }
    // refresh simulation data
    Simulation simulation = this.model.getSimulation();
    for (ScenarioWithIndex scenarioWithIndex : newData.getScenarioWithIndex()) {
        int index = scenarioWithIndex.getIndex() - 1;
        simulation.replaceData(index, scenarioWithIndex.getScesimData());
    }
    scenarioMainGridWidget.refreshContent(simulation);
    context.getStatus().setSimulation(simulation);
    // refresh background data
    boolean hasBackgroundError = false;
    Background background = this.model.getBackground();
    for (BackgroundDataWithIndex backgroundDataWithIndex : newData.getBackgroundDataWithIndex()) {
        int index = backgroundDataWithIndex.getIndex() - 1;
        BackgroundData scesimData = backgroundDataWithIndex.getScesimData();
        background.replaceData(index, scesimData);
        hasBackgroundError |= scesimData.getUnmodifiableFactMappingValues().stream().anyMatch(elem -> !FactMappingValueStatus.SUCCESS.equals(elem.getStatus()));
    }
    scenarioBackgroundGridWidget.refreshContent(background);
    context.getStatus().setBackground(background);
    if (hasBackgroundError) {
        sendNotification(ScenarioSimulationEditorConstants.INSTANCE.backgroundErrorNotification(), NotificationEvent.NotificationType.ERROR);
        selectBackgroundTab();
    }
    dataManagementStrategy.setModel(model);
    abstractScenarioSimulationDocksHandler.expandTestResultsDock();
    scenarioSimulationEditorWrapper.onRefreshedModelContent(newData);
}
Also used : AbstractScenarioSimulationDocksHandler(org.drools.workbench.screens.scenariosimulation.client.handlers.AbstractScenarioSimulationDocksHandler) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) TestToolsPresenter(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenter) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) AbstractDMODataManagementStrategy(org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMODataManagementStrategy) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) CustomBusyPopup(org.drools.workbench.screens.scenariosimulation.client.popup.CustomBusyPopup) FactMappingValidationError(org.drools.workbench.screens.scenariosimulation.model.FactMappingValidationError) Observes(javax.enterprise.event.Observes) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) SettingsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.SettingsView) AbstractScenarioSimulationProducer(org.drools.workbench.screens.scenariosimulation.client.producers.AbstractScenarioSimulationProducer) EventBus(com.google.gwt.event.shared.EventBus) TextFileExport(org.uberfire.ext.editor.commons.client.file.exports.TextFileExport) SettingsPresenter(org.drools.workbench.screens.scenariosimulation.client.rightpanel.SettingsPresenter) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) UberfireDocksInteractionEvent(org.uberfire.client.workbench.docks.UberfireDocksInteractionEvent) Collectors(java.util.stream.Collectors) CheatSheetView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.CheatSheetView) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ObservablePath(org.uberfire.backend.vfs.ObservablePath) ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback) Simulation(org.drools.scenariosimulation.api.model.Simulation) ScenarioMenuItemFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioMenuItemFactory) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) IntStream(java.util.stream.IntStream) RedoEvent(org.drools.workbench.screens.scenariosimulation.client.events.RedoEvent) PlaceStatus(org.uberfire.client.mvp.PlaceStatus) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) PlaceManager(org.uberfire.client.mvp.PlaceManager) GWT(com.google.gwt.core.client.GWT) Supplier(java.util.function.Supplier) ScenarioSimulationEditorI18nServerManager(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorI18nServerManager) ImportEvent(org.drools.workbench.screens.scenariosimulation.client.events.ImportEvent) Inject(javax.inject.Inject) CSV(org.drools.workbench.screens.scenariosimulation.service.ImportExportType.CSV) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) ConfirmPopupPresenter(org.drools.workbench.screens.scenariosimulation.client.popup.ConfirmPopupPresenter) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) MenuItem(org.uberfire.workbench.model.menu.MenuItem) CommonConstants(org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants) SCESIMEDITOR_ID(org.drools.workbench.screens.scenariosimulation.client.handlers.AbstractScenarioSimulationDocksHandler.SCESIMEDITOR_ID) ScenarioSimulationResourceType(org.drools.workbench.screens.scenariosimulation.client.type.ScenarioSimulationResourceType) DataManagementStrategy(org.drools.workbench.screens.scenariosimulation.client.editor.strategies.DataManagementStrategy) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) TextContent(org.uberfire.ext.editor.commons.client.file.exports.TextContent) UndoEvent(org.drools.workbench.screens.scenariosimulation.client.events.UndoEvent) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Background(org.drools.scenariosimulation.api.model.Background) DomGlobal(elemental2.dom.DomGlobal) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Type(org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type) AtomicLong(java.util.concurrent.atomic.AtomicLong) MarshallingWrapper(org.jboss.errai.enterprise.client.jaxrs.MarshallingWrapper) Dependent(javax.enterprise.context.Dependent) FileMenuBuilder(org.kie.workbench.common.widgets.client.menu.FileMenuBuilder) ScenarioGridWidget(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridWidget) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) BusyPopup(org.uberfire.ext.widgets.common.client.common.BusyPopup) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData)

Example 12 with ScenarioWithIndex

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

the class ScenarioSimulationEditorPresenterTest method onRunScenario.

@Test
public void onRunScenario() {
    scenarioWithIndexLocal.add(new ScenarioWithIndex(1, new Scenario()));
    scenarioWithIndexLocal.add(new ScenarioWithIndex(2, new Scenario()));
    scenarioWithIndexLocal.add(new ScenarioWithIndex(3, new Scenario()));
    when(simulationMock.getDataByIndex(anyInt())).thenReturn(mock(Scenario.class));
    List<Integer> indexList = Arrays.asList(0, 2);
    presenterSpy.onRunScenario(indexList);
    verify(scenarioGridWidgetSpy, times(1)).resetErrors();
    verify(backgroundGridWidgetSpy, times(1)).resetErrors();
    verify(scenarioSimulationModelMock, times(1)).setSimulation(simulationMock);
    verify(scenarioSimulationModelMock, times(1)).setBackground(backgroundMock);
    verify(scenarioSimulationViewMock, times(1)).showBusyIndicator(anyString());
    verify(scenarioSimulationEditorWrapperMock, times(1)).onRunScenario(any(), any(), any(), eq(settingsLocal), scenarioWithIndexCaptor.capture(), any());
    List<ScenarioWithIndex> capturedValue = scenarioWithIndexCaptor.getValue();
    assertEquals(2, capturedValue.size());
    for (Integer requestedIndex : indexList) {
        assertEquals(1, capturedValue.stream().filter(elem -> elem.getIndex() == (requestedIndex + 1)).count());
    }
}
Also used : ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Example 13 with ScenarioWithIndex

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

Example 14 with ScenarioWithIndex

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

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

Aggregations

ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)20 Scenario (org.drools.scenariosimulation.api.model.Scenario)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)7 Path (org.uberfire.backend.vfs.Path)7 List (java.util.List)6 SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)6 Simulation (org.drools.scenariosimulation.api.model.Simulation)5 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 SimulationRunMetadata (org.drools.scenariosimulation.api.model.SimulationRunMetadata)4 ScenarioResultMetadata (org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Inject (javax.inject.Inject)3 AuditLogLine (org.drools.scenariosimulation.api.model.AuditLogLine)3 Background (org.drools.scenariosimulation.api.model.Background)3 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)3 BackgroundDataWithIndex (org.drools.scenariosimulation.api.model.BackgroundDataWithIndex)3