Search in sources :

Example 6 with ScenarioWithIndex

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

the class RULESimulationSettingsCreationStrategy method createSimulation.

@Override
public Simulation createSimulation(Path context, String value) {
    Simulation toReturn = new Simulation();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
    // Add GIVEN Fact
    createEmptyColumn(simulationDescriptor, scenarioWithIndex, 1, GIVEN, simulationDescriptor.getFactMappings().size());
    // Add EXPECT Fact
    createEmptyColumn(simulationDescriptor, scenarioWithIndex, 2, EXPECT, simulationDescriptor.getFactMappings().size());
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Simulation(org.drools.scenariosimulation.api.model.Simulation) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

Example 7 with ScenarioWithIndex

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

the class SimulationSettingsCreationStrategyTest method createEmptyColumn.

@Test
public void createEmptyColumn() {
    ArgumentCaptor<ExpressionIdentifier> expressionIdentifierCaptor1 = ArgumentCaptor.forClass(ExpressionIdentifier.class);
    ArgumentCaptor<ExpressionIdentifier> expressionIdentifierCaptor2 = ArgumentCaptor.forClass(ExpressionIdentifier.class);
    int placeholderId = 1;
    int columnIndex = 0;
    SimulationSettingsCreationStrategy simulationSettingsCreationStrategy = new SimulationSettingsCreationStrategy() {

        @Override
        public Simulation createSimulation(Path context, String value) {
            return null;
        }

        @Override
        public Background createBackground(Path context, String dmnFilePath) {
            return null;
        }

        @Override
        public Settings createSettings(Path context, String value) {
            return null;
        }
    };
    ScesimModelDescriptor simulationDescriptorSpy = spy(new ScesimModelDescriptor());
    Scenario scenarioSpy = spy(new Scenario());
    ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, scenarioSpy);
    simulationSettingsCreationStrategy.createEmptyColumn(simulationDescriptorSpy, scenarioWithIndex, placeholderId, GIVEN, columnIndex);
    verify(simulationDescriptorSpy, times(1)).addFactMapping(eq(columnIndex), eq(FactMapping.getInstancePlaceHolder(placeholderId)), eq(FactIdentifier.EMPTY), expressionIdentifierCaptor1.capture());
    assertEquals(GIVEN, expressionIdentifierCaptor1.getValue().getType());
    verify(scenarioSpy, times(1)).addMappingValue(eq(FactIdentifier.EMPTY), expressionIdentifierCaptor2.capture(), isNull());
    assertEquals(GIVEN, expressionIdentifierCaptor2.getValue().getType());
}
Also used : Path(org.uberfire.backend.vfs.Path) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Example 8 with ScenarioWithIndex

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

the class ScenarioRunnerServiceImplTest method runTestWithScenarios.

@Test
public void runTestWithScenarios() {
    when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock);
    when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock);
    ScesimModelDescriptor simulationDescriptor = new ScesimModelDescriptor();
    List<ScenarioWithIndex> scenarios = new ArrayList<>();
    SimulationRunResult test = scenarioRunnerService.runTest("test", mock(Path.class), simulationDescriptor, scenarios, settingsLocal, backgroundLocal);
    assertNotNull(test.getTestResultMessage());
    assertNotNull(test.getScenarioWithIndex());
    assertNotNull(test.getSimulationRunMetadata());
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Path(org.uberfire.backend.vfs.Path) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) ArrayList(java.util.ArrayList) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Test(org.junit.Test)

Example 9 with ScenarioWithIndex

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

the class ScenarioRunnerServiceImplTest method runFailed.

@Test
public void runFailed() {
    when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock);
    when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock);
    simulationLocal.addData();
    Scenario scenario = simulationLocal.getDataByIndex(0);
    scenario.setDescription("Test Scenario");
    String errorMessage = "Test Error";
    scenarioRunnerService.setRunnerSupplier((kieContainer, scenarioRunnerDTO) -> new RuleScenarioRunner(kieContainer, scenarioRunnerDTO) {

        @Override
        protected void internalRunScenario(ScenarioWithIndex scenarioWithIndex, ScenarioRunnerData scenarioRunnerData, Settings settings, Background background) {
            throw new ScenarioException(errorMessage);
        }
    });
    SimulationRunResult test = scenarioRunnerService.runTest("test", mock(Path.class), simulationLocal.getScesimModelDescriptor(), simulationLocal.getScenarioWithIndex(), settingsLocal, backgroundLocal);
    TestResultMessage value = test.getTestResultMessage();
    List<org.guvnor.common.services.shared.test.Failure> failures = value.getFailures();
    assertEquals(1, failures.size());
    String testDescription = String.format("#%d: %s", 1, scenario.getDescription());
    String errorMessageFormatted = String.format("#%d %s: %s", 1, scenario.getDescription(), errorMessage);
    org.guvnor.common.services.shared.test.Failure failure = failures.get(0);
    assertEquals(errorMessageFormatted, failure.getMessage());
    assertEquals(1, value.getRunCount());
    assertTrue(failure.getDisplayName().startsWith(testDescription));
}
Also used : Path(org.uberfire.backend.vfs.Path) Background(org.drools.scenariosimulation.api.model.Background) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) RuleScenarioRunner(org.drools.scenariosimulation.backend.runner.RuleScenarioRunner) Scenario(org.drools.scenariosimulation.api.model.Scenario) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioException(org.drools.scenariosimulation.backend.runner.ScenarioException) Test(org.junit.Test)

Example 10 with ScenarioWithIndex

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

the class ScenarioSimulationEditorPresenter method onRunScenario.

public void onRunScenario(List<Integer> indexOfScenarioToRun) {
    scenarioMainGridWidget.resetErrors();
    scenarioBackgroundGridWidget.resetErrors();
    model.setSimulation(scenarioMainGridWidget.getScenarioSimulationContext().getStatus().getSimulation());
    model.setBackground(scenarioMainGridWidget.getScenarioSimulationContext().getStatus().getBackground());
    Simulation simulation = model.getSimulation();
    List<ScenarioWithIndex> toRun = simulation.getScenarioWithIndex().stream().filter(elem -> indexOfScenarioToRun.contains(elem.getIndex() - 1)).collect(Collectors.toList());
    view.showBusyIndicator(ScenarioSimulationEditorConstants.INSTANCE.running());
    scenarioSimulationEditorWrapper.onRunScenario(getRefreshModelCallback(), new ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(view), simulation.getScesimModelDescriptor(), model.getSettings(), toRun, model.getBackground());
}
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) ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

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