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