use of org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult in project drools-wb by kiegroup.
the class ScenarioSimulationEditorBusinessCentralWrapperTest method onRunScenario.
@Test
public void onRunScenario() {
scenarioWithIndexLocal.add(new ScenarioWithIndex(1, new Scenario()));
scenarioWithIndexLocal.add(new ScenarioWithIndex(2, new Scenario()));
scenarioWithIndexLocal.add(new ScenarioWithIndex(3, new Scenario()));
RemoteCallback<SimulationRunResult> remoteCallback = mock(RemoteCallback.class);
ScenarioSimulationHasBusyIndicatorDefaultErrorCallback errorCallback = mock(ScenarioSimulationHasBusyIndicatorDefaultErrorCallback.class);
scenarioSimulationEditorBusinessClientWrapper.onRunScenario(remoteCallback, errorCallback, simulationDescriptorMock, settingsLocal, scenarioWithIndexLocal, backgroundLocal);
verify(scenarioSimulationEditorBusinessClientWrapper, times(1)).unpublishTestResultsAlerts();
verify(scenarioSimulationCaller, times(1)).call(eq(remoteCallback), eq(errorCallback));
verify(scenarioSimulationServiceMock, times(1)).runScenario(eq(observablePathMock), eq(simulationDescriptorMock), eq(scenarioWithIndexLocal), eq(settingsLocal), eq(backgroundLocal));
}
use of org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult 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.workbench.screens.scenariosimulation.model.SimulationRunResult in project drools-wb by kiegroup.
the class ScenarioRunnerServiceImplTest method runTest.
@Test
public void runTest() {
SimulationRunResult test = scenarioRunnerService.runTest("test", mock(Path.class), simulationLocal.getScesimModelDescriptor(), simulationLocal.getScenarioWithIndex(), settingsLocal, backgroundLocal);
assertNotNull(test.getTestResultMessage());
assertNotNull(test.getScenarioWithIndex());
assertNotNull(test.getSimulationRunMetadata());
when(runnerMock.getLastRunResultMetadata()).thenReturn(Optional.empty());
scenarioRunnerService.setRunnerSupplier((kieContainer, scenarioRunnerDTO) -> runnerMock);
assertThatThrownBy(() -> scenarioRunnerService.runTest("test", mock(Path.class), simulationLocal.getScesimModelDescriptor(), simulationLocal.getScenarioWithIndex(), settingsLocal, backgroundLocal)).isInstanceOf(IllegalStateException.class).hasMessage("SimulationRunMetadata should be available after a run");
}
use of org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult 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.workbench.screens.scenariosimulation.model.SimulationRunResult in project drools-wb by kiegroup.
the class ScenarioRunnerServiceImpl method runTest.
@Override
public SimulationRunResult runTest(final String identifier, final Path path, final ScesimModelDescriptor simulationDescriptor, final List<ScenarioWithIndex> scenarios, final Settings settings, final Background background) {
final KieContainer kieContainer = getKieContainer(path);
final ScenarioRunnerDTO scenarioRunnerDTO = new ScenarioRunnerDTO(simulationDescriptor, scenarios, null, settings, background);
final AbstractScenarioRunner scenarioRunner = getOrCreateRunnerSupplier(settings.getType()).create(kieContainer, scenarioRunnerDTO);
final List<Failure> failures = new ArrayList<>();
final List<Failure> failureDetails = new ArrayList<>();
final Result result = runWithJunit(path, scenarioRunner, failures, failureDetails);
return new SimulationRunResult(scenarios, background.getBackgroundDataWithIndex(), scenarioRunner.getLastRunResultMetadata().orElseThrow(() -> new IllegalStateException("SimulationRunMetadata should be available after a run")), new TestResultMessage(identifier, result.getRunCount(), result.getRunTime(), failures));
}
Aggregations