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);
}
}
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"));
}
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;
}
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);
}
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())));
}
}
Aggregations