Search in sources :

Example 1 with SimulationRunResult

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));
}
Also used : SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test) AbstractScenarioSimulationEditorTest(org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)

Example 2 with SimulationRunResult

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());
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Path(org.uberfire.backend.vfs.Path) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) ArrayList(java.util.ArrayList) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Test(org.junit.Test)

Example 3 with SimulationRunResult

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");
}
Also used : Path(org.uberfire.backend.vfs.Path) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) Test(org.junit.Test)

Example 4 with SimulationRunResult

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));
}
Also used : Path(org.uberfire.backend.vfs.Path) Background(org.drools.scenariosimulation.api.model.Background) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) RuleScenarioRunner(org.drools.scenariosimulation.backend.runner.RuleScenarioRunner) Scenario(org.drools.scenariosimulation.api.model.Scenario) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioException(org.drools.scenariosimulation.backend.runner.ScenarioException) Test(org.junit.Test)

Example 5 with SimulationRunResult

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));
}
Also used : ScenarioRunnerDTO(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) ArrayList(java.util.ArrayList) AbstractScenarioRunner(org.drools.scenariosimulation.backend.runner.AbstractScenarioRunner) Failure(org.guvnor.common.services.shared.test.Failure) KieContainer(org.kie.api.runtime.KieContainer) Result(org.junit.runner.Result) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)

Aggregations

SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)7 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)5 Test (org.junit.Test)5 Path (org.uberfire.backend.vfs.Path)4 ArrayList (java.util.ArrayList)3 Scenario (org.drools.scenariosimulation.api.model.Scenario)3 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)3 Background (org.drools.scenariosimulation.api.model.Background)2 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)2 BackgroundDataWithIndex (org.drools.scenariosimulation.api.model.BackgroundDataWithIndex)2 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)2 ScenarioSimulationHasBusyIndicatorDefaultErrorCallback (org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback)2 GWT (com.google.gwt.core.client.GWT)1 EventBus (com.google.gwt.event.shared.EventBus)1 DomGlobal (elemental2.dom.DomGlobal)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1