Search in sources :

Example 1 with ScenarioRunnerDTO

use of org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO in project drools by kiegroup.

the class ScenarioJunitActivator method parseFile.

protected ScenarioRunnerDTO parseFile(String path) {
    try (final Scanner scanner = new Scanner(new File(path))) {
        String rawFile = scanner.useDelimiter("\\Z").next();
        ScenarioSimulationModel scenarioSimulationModel = getXmlReader().unmarshal(rawFile);
        return new ScenarioRunnerDTO(scenarioSimulationModel, path);
    } catch (FileNotFoundException e) {
        throw new ScenarioException("File not found, this should not happen: " + path, e);
    } catch (Exception e) {
        throw new ScenarioException("Issue on parsing file: " + path, e);
    }
}
Also used : Scanner(java.util.Scanner) ScenarioRunnerDTO(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ScenarioRunnerDTO

use of org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO in project drools by kiegroup.

the class AbstractScenarioRunnerTest method getScenarioRunnerDTO.

private ScenarioRunnerDTO getScenarioRunnerDTO() {
    Simulation simulation = new Simulation();
    IntStream.range(0, SCENARIO_DATA).forEach(index -> {
        Scenario scenario = simulation.addData();
        scenario.setDescription("INDEX-" + index);
    });
    ScenarioSimulationModel model = new ScenarioSimulationModel();
    model.setSimulation(simulation);
    return new ScenarioRunnerDTO(model, "test.scesim");
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) ScenarioRunnerDTO(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 3 with ScenarioRunnerDTO

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

ScenarioRunnerDTO (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerDTO)3 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 Scenario (org.drools.scenariosimulation.api.model.Scenario)1 Simulation (org.drools.scenariosimulation.api.model.Simulation)1 AbstractScenarioRunner (org.drools.scenariosimulation.backend.runner.AbstractScenarioRunner)1 SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)1 Failure (org.guvnor.common.services.shared.test.Failure)1 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)1 Result (org.junit.runner.Result)1 KieContainer (org.kie.api.runtime.KieContainer)1