DMNScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) { if (!ScenarioSimulationModel.Type.DMN.equals(settings.getType())) { throw new ScenarioException("Impossible to run a not-DMN simulation with DMN runner"); } DMNScenarioExecutableBuilder executableBuilder = createBuilderWrapper(kieContainer); executableBuilder.setActiveModel(settings.getDmnFilePath()); loadInputData(scenarioRunnerData.getBackgrounds(), executableBuilder); loadInputData(scenarioRunnerData.getGivens(), executableBuilder); return executableBuilder.run().getOutputs(); }    }
@Test public void executeScenario() { ArgumentCaptor<Object> setValueCaptor = ArgumentCaptor.forClass(Object.class); ScenarioRunnerData scenarioRunnerData = new ScenarioRunnerData(); scenarioRunnerData.addBackground(new InstanceGiven(personFactIdentifier, new Person())); scenarioRunnerData.addBackground(new InstanceGiven(disputeFactIdentifier, new Dispute())); scenarioRunnerData.addGiven(new InstanceGiven(personFactIdentifier, new Person())); FactMappingValue factMappingValue = new FactMappingValue(personFactIdentifier, firstNameExpectedExpressionIdentifier, NAME); scenarioRunnerData.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(factMappingValue), false)); scenarioRunnerData.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(factMappingValue), true)); int inputObjects = scenarioRunnerData.getBackgrounds().size() + scenarioRunnerData.getGivens().size(); runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings); verify(dmnScenarioExecutableBuilderMock, times(1)).setActiveModel(eq(DMN_FILE_PATH)); verify(dmnScenarioExecutableBuilderMock, times(inputObjects)).setValue(anyString(), setValueCaptor.capture()); for (Object value : setValueCaptor.getAllValues()) { assertTrue(value instanceof Person || value instanceof Dispute); } verify(dmnScenarioExecutableBuilderMock, times(1)).run(); settings.setType(ScenarioSimulationModel.Type.RULE); assertThatThrownBy(() -> runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings)) .isInstanceOf(ScenarioException.class) .hasMessageStartingWith("Impossible to run"); }