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