use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.
the class ScenarioRunnerServiceImpl method runAllTests.
@Override
public List<TestResultMessage> runAllTests(final String identifier, final Path path) {
final List<TestResultMessage> testResultMessages = new ArrayList<>();
for (Map.Entry<Path, ScenarioSimulationModel> entry : scenarioLoader.loadScenarios(path).entrySet()) {
final Simulation simulation = entry.getValue().getSimulation();
final Settings settings = entry.getValue().getSettings();
if (!settings.isSkipFromBuild()) {
testResultMessages.add(runTest(identifier, entry.getKey(), simulation.getScesimModelDescriptor(), simulation.getScenarioWithIndex(), settings, entry.getValue().getBackground()).getTestResultMessage());
}
}
return testResultMessages;
}
use of org.drools.scenariosimulation.api.model.Simulation 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());
}
use of org.drools.scenariosimulation.api.model.Simulation 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);
}
use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.
the class AbstractScenarioSimulationEditorTest method getSimulation.
protected Simulation getSimulation() {
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);
Scenario scenario = toReturn.addData();
int row = toReturn.getUnmodifiableData().indexOf(scenario);
scenario.setDescription(null);
// Add GIVEN Fact
int id = 1;
ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN);
final FactMapping givenFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression);
givenFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id));
scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null);
// Add EXPECT Fact
id = 2;
ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT);
final FactMapping expectedFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression);
expectedFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id));
scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null);
return toReturn;
}
use of org.drools.scenariosimulation.api.model.Simulation 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);
}
}
Aggregations