Search in sources :

Example 11 with Background

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

the class ScenarioSimulationEditorPresenterTest method getImportCallback.

@Test
public void getImportCallback() {
    List<AbstractScesimModel> toTest = Arrays.asList(new Simulation(), new Background());
    for (AbstractScesimModel abstractScesimModel : toTest) {
        FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().addFactMapping(FactIdentifier.EMPTY, ExpressionIdentifier.create("empty", FactMappingType.GIVEN));
        FactMappingValue toBeRemoved = abstractScesimModel.addData().addOrUpdateMappingValue(factMapping.getFactIdentifier(), factMapping.getExpressionIdentifier(), "toBeRemoved");
        presenterSpy.getImportCallBack().callback(abstractScesimModel);
        verify(presenterSpy, times(1)).cleanReadOnlyColumn(eq(abstractScesimModel));
        assertNull(toBeRemoved.getRawValue());
        reset(presenterSpy);
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) Test(org.junit.Test)

Example 12 with Background

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

the class RuleScenarioRunnerHelperTest method extractBackgroundValues.

@Test
public void extractBackgroundValues() {
    // TEST 0 - empty background
    Background emptyBackground = new Background();
    List<InstanceGiven> emptyBackgroundGivens = runnerHelper.extractBackgroundValues(emptyBackground, classLoader, expressionEvaluatorFactory);
    assertEquals(0, emptyBackgroundGivens.size());
    emptyBackground.addData();
    emptyBackgroundGivens = runnerHelper.extractBackgroundValues(emptyBackground, classLoader, expressionEvaluatorFactory);
    assertEquals(0, emptyBackgroundGivens.size());
    // TEST 1 - background correct
    List<InstanceGiven> backgroundGivens = runnerHelper.extractBackgroundValues(this.background, classLoader, expressionEvaluatorFactory);
    assertEquals(3, backgroundGivens.size());
    for (InstanceGiven backgroundGiven : backgroundGivens) {
        if (backgroundGiven.getFactIdentifier().equals(personFactIdentifier)) {
            assertEquals(personFactIdentifier, backgroundGiven.getFactIdentifier());
            Person person = (Person) backgroundGiven.getValue();
            assertEquals(NAME, person.getFirstName());
        } else if (backgroundGiven.getFactIdentifier().equals(disputeFactIdentifier)) {
            assertEquals(disputeFactIdentifier, backgroundGiven.getFactIdentifier());
            Dispute dispute = (Dispute) backgroundGiven.getValue();
            double parsedAmount = Double.parseDouble(AMOUNT);
            assertEquals(parsedAmount, dispute.getAmount(), 0.1);
        } else {
            fail();
        }
    }
    // TEST 2 - broken background
    String notValid = "notValid";
    FactMappingValue notValid1 = backgroundData1.addOrUpdateMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, notValid);
    FactMappingValue notValid2 = backgroundData2.addOrUpdateMappingValue(disputeFactIdentifier, amountGivenExpressionIdentifier, notValid);
    assertThatThrownBy(() -> runnerHelper.extractBackgroundValues(this.background, classLoader, expressionEvaluatorFactory)).isInstanceOf(ScenarioException.class).hasMessage("Error in BACKGROUND data");
    assertEquals(FactMappingValueStatus.FAILED_WITH_EXCEPTION, notValid1.getStatus());
    assertTrue(notValid1.getExceptionMessage().startsWith("Impossible to parse"));
    assertEquals(FactMappingValueStatus.FAILED_WITH_EXCEPTION, notValid2.getStatus());
    assertTrue(notValid2.getExceptionMessage().startsWith("Impossible to parse"));
}
Also used : Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) Dispute(org.drools.scenariosimulation.backend.model.Dispute) Person(org.drools.scenariosimulation.backend.model.Person) AbstractRuleCoverageTest(org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest) Test(org.junit.Test)

Example 13 with Background

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

the class ScenarioRunnerServiceImplTest method makeScenarioSimulationModel.

private ScenarioSimulationModel makeScenarioSimulationModel(boolean toSkip) {
    Simulation simulation = new Simulation();
    Settings settings = new Settings();
    settings.setType(Type.RULE);
    settings.setSkipFromBuild(toSkip);
    ScenarioSimulationModel scenarioSimulationModel = new ScenarioSimulationModel();
    scenarioSimulationModel.setSimulation(simulation);
    scenarioSimulationModel.setSettings(settings);
    scenarioSimulationModel.setBackground(new Background());
    return scenarioSimulationModel;
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 14 with Background

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

the class ScenarioSimulationServiceImplTest method runScenario.

@Test
public void runScenario() throws Exception {
    doReturn("test userMock").when(userMock).getIdentifier();
    final Path path = mock(Path.class);
    Simulation simulation = new Simulation();
    Settings settings = new Settings();
    Background background = new Background();
    service.runScenario(path, simulation.getScesimModelDescriptor(), simulation.getScenarioWithIndex(), settings, background);
    verify(scenarioRunnerServiceMock).runTest("test userMock", path, simulation.getScesimModelDescriptor(), simulation.getScenarioWithIndex(), settings, background);
}
Also used : Path(org.uberfire.backend.vfs.Path) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) Settings(org.drools.scenariosimulation.api.model.Settings) Test(org.junit.Test)

Example 15 with Background

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

the class AbstractScenarioGridCommand method setCurrentContext.

@Override
protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) {
    try {
        final Simulation simulationToRestore = restorableStatus.getSimulation();
        final Background backgroundToRestore = restorableStatus.getBackground();
        if (simulationToRestore == null) {
            throw new IllegalStateException("Simulation is null in restorable status");
        }
        if (backgroundToRestore == null) {
            throw new IllegalStateException("Background is null in restorable status");
        }
        final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus();
        ScenarioSimulationModel.Type type = context.getScenarioSimulationModel().getSettings().getType();
        context.getSimulationGrid().getModel().clearSelections();
        context.getBackgroundGrid().getModel().clearSelections();
        context.getSimulationGrid().setContent(simulationToRestore, type);
        context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore);
        context.getBackgroundGrid().setContent(backgroundToRestore, type);
        context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore);
        context.getScenarioSimulationEditorPresenter().reloadTestTools(true);
        context.setStatus(restorableStatus);
        restorableStatus = originalStatus;
        return commonExecution(context);
    } catch (Exception e) {
        return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage())));
    }
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) ScenarioSimulationViolation(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

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