Search in sources :

Example 1 with RuleScenarioRunner

use of org.drools.scenariosimulation.backend.runner.RuleScenarioRunner 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)

Aggregations

Background (org.drools.scenariosimulation.api.model.Background)1 Scenario (org.drools.scenariosimulation.api.model.Scenario)1 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)1 Settings (org.drools.scenariosimulation.api.model.Settings)1 RuleScenarioRunner (org.drools.scenariosimulation.backend.runner.RuleScenarioRunner)1 ScenarioException (org.drools.scenariosimulation.backend.runner.ScenarioException)1 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)1 SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)1 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)1 Test (org.junit.Test)1 Path (org.uberfire.backend.vfs.Path)1