@Test public void executeScenario() { ArgumentCaptor<Object> insertCaptor = 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(); String ruleFlowGroup = "ruleFlowGroup"; settings.setRuleFlowGroup(ruleFlowGroup); runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings); verify(ruleScenarioExecutableBuilderMock, times(1)).setActiveRuleFlowGroup(eq(ruleFlowGroup)); verify(ruleScenarioExecutableBuilderMock, times(inputObjects)).insert(insertCaptor.capture()); for (Object value : insertCaptor.getAllValues()) { assertTrue(value instanceof Person || value instanceof Dispute); } verify(ruleScenarioExecutableBuilderMock, times(1)).addInternalCondition(eq(Person.class), any(), any()); verify(ruleScenarioExecutableBuilderMock, times(1)).run(); assertEquals(1, scenarioRunnerData.getResults().size()); settings.setType(ScenarioSimulationModel.Type.DMN); assertThatThrownBy(() -> runnerHelper.executeScenario(kieContainerMock, scenarioRunnerData, expressionEvaluatorFactory, simulation.getScesimModelDescriptor(), settings)) .isInstanceOf(ScenarioException.class) .hasMessageStartingWith("Impossible to run"); }
@Override protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) { if (!Type.RULE.equals(settings.getType())) { throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner"); } RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings); if (settings.getRuleFlowGroup() != null) { ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup()); } loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder); loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder); scenarioRunnerData.getExpects().stream() .filter(ScenarioExpect::isNewFact) .flatMap(output -> output.getExpectedResult().stream() .map(ScenarioResult::new)) .forEach(scenarioResult -> { Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader()); ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue()); scenarioRunnerData.addResult(scenarioResult); ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult); }); return ruleScenarioExecutableBuilder.run(); }
RuleScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) { if (!Type.RULE.equals(settings.getType())) { throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner"); } RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings); if (settings.getRuleFlowGroup() != null) { ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup()); } loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder); loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder); scenarioRunnerData.getExpects().stream() .filter(ScenarioExpect::isNewFact) .flatMap(output -> output.getExpectedResult().stream() .map(ScenarioResult::new)) .forEach(scenarioResult -> { Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader()); ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue()); scenarioRunnerData.addResult(scenarioResult); ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult); }); return ruleScenarioExecutableBuilder.run(); } }
RuleScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) { if (!Type.RULE.equals(settings.getType())) { throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner"); } RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings); if (settings.getRuleFlowGroup() != null) { ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup()); } loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder); loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder); scenarioRunnerData.getExpects().stream() .filter(ScenarioExpect::isNewFact) .flatMap(output -> output.getExpectedResult().stream() .map(ScenarioResult::new)) .forEach(scenarioResult -> { Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader()); ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue()); scenarioRunnerData.addResult(scenarioResult); ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult); }); return ruleScenarioExecutableBuilder.run(); }  }
RuleScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) { if (!Type.RULE.equals(settings.getType())) { throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner"); } RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings); if (settings.getRuleFlowGroup() != null) { ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup()); } loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder); loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder); scenarioRunnerData.getExpects().stream() .filter(ScenarioExpect::isNewFact) .flatMap(output -> output.getExpectedResult().stream() .map(ScenarioResult::new)) .forEach(scenarioResult -> { Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader()); ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue()); scenarioRunnerData.addResult(scenarioResult); ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult); }); return ruleScenarioExecutableBuilder.run(); }   }
RuleScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) { if (!Type.RULE.equals(settings.getType())) { throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner"); } RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings); if (settings.getRuleFlowGroup() != null) { ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup()); } loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder); loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder); scenarioRunnerData.getExpects().stream() .filter(ScenarioExpect::isNewFact) .flatMap(output -> output.getExpectedResult().stream() .map(ScenarioResult::new)) .forEach(scenarioResult -> { Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader()); ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue()); scenarioRunnerData.addResult(scenarioResult); ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult); }); return ruleScenarioExecutableBuilder.run(); }    }