Search in sources :

Example 6 with Background

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

the class SimulationSettingsCreationStrategy method createBackground.

default Background createBackground(Path context, String dmnFilePath) {
    Background toReturn = new Background();
    ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
    int index = toReturn.getUnmodifiableData().size() + 1;
    BackgroundData backgroundData = toReturn.addData();
    BackgroundDataWithIndex backgroundDataWithIndex = new BackgroundDataWithIndex(index, backgroundData);
    // Add GIVEN Fact
    createEmptyColumn(simulationDescriptor, backgroundDataWithIndex, 1, GIVEN, simulationDescriptor.getFactMappings().size());
    return toReturn;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Background(org.drools.scenariosimulation.api.model.Background) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData)

Example 7 with Background

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

the class ScenarioRunnerServiceImplTest method setup.

@Before
public void setup() {
    simulationLocal = new Simulation();
    backgroundLocal = new Background();
    settingsLocal = new Settings();
    settingsLocal.setType(Type.RULE);
    when(buildInfoServiceMock.getBuildInfo(any())).thenReturn(buildInfoMock);
    when(buildInfoMock.getKieContainer()).thenReturn(kieContainerMock);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Settings(org.drools.scenariosimulation.api.model.Settings) Before(org.junit.Before)

Example 8 with Background

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

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

the class ScenarioSimulationServiceImplTest method setup.

@Before
public void setup() {
    Set<Package> testPackages = new HashSet<>();
    Package testPackage = new Package(path, path, path, path, path, "Test", "", "");
    testPackages.add(testPackage);
    when(kieModuleServiceMock.resolveModule(any())).thenReturn(kieModuleMock);
    when(kieModuleServiceMock.resolvePackages(Mockito.<KieModule>any())).thenReturn(testPackages);
    when(kieModuleServiceMock.newPackage(any(), any())).thenReturn(testPackage);
    when(kieModuleServiceMock.resolveDefaultPackage(any())).thenReturn(testPackage);
    when(kieModuleServiceMock.resolveModule(any())).thenReturn(kieModuleMock);
    when(kieModuleMock.getPom()).thenReturn(projectPomMock);
    when(projectPomMock.getGav()).thenReturn(gavMock);
    when(gavMock.getGroupId()).thenReturn("Test");
    when(projectPomMock.getDependencies()).thenReturn(dependenciesMock);
    when(dependenciesMock.iterator()).thenReturn(new Dependencies().iterator());
    when(ioServiceMock.exists(any())).thenReturn(false);
    when(packageMock.getPackageTestSrcPath()).thenReturn(path);
    when(scenarioSimulationBuilderMock.createSimulation(any(), any(), any())).thenReturn(new Simulation());
    when(scenarioSimulationBuilderMock.createBackground(any(), any(), any())).thenReturn(new Background());
    when(scenarioSimulationBuilderMock.createSettings(any(), any(), any())).thenReturn(new Settings());
    service.scenarioSimulationBuilder = scenarioSimulationBuilderMock;
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Package(org.guvnor.common.services.project.model.Package) Dependencies(org.guvnor.common.services.project.model.Dependencies) Settings(org.drools.scenariosimulation.api.model.Settings) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 10 with Background

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

Aggregations

Background (org.drools.scenariosimulation.api.model.Background)16 Simulation (org.drools.scenariosimulation.api.model.Simulation)10 Settings (org.drools.scenariosimulation.api.model.Settings)9 Test (org.junit.Test)8 Before (org.junit.Before)5 Path (org.uberfire.backend.vfs.Path)5 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)4 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)3 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)3 ScenarioSimulationContext (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext)3 List (java.util.List)2 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)2 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)2 BackgroundDataWithIndex (org.drools.scenariosimulation.api.model.BackgroundDataWithIndex)2 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)2 GIVEN (org.drools.scenariosimulation.api.model.FactMappingType.GIVEN)2 OTHER (org.drools.scenariosimulation.api.model.FactMappingType.OTHER)2 Scenario (org.drools.scenariosimulation.api.model.Scenario)2 ScenarioGridWidget (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridWidget)2