RuleScenarioRunnerHelper extends AbstractRunnerHelper { protected List<ScenarioResult> getScenarioResultsFromGivenFacts(ScesimModelDescriptor scesimModelDescriptor, List<ScenarioExpect> scenarioOutputsPerFact, InstanceGiven input, ExpressionEvaluatorFactory expressionEvaluatorFactory) { Object factInstance = input.getValue(); List<ScenarioResult> scenarioResults = new ArrayList<>(); for (ScenarioExpect scenarioExpect : scenarioOutputsPerFact) { if (scenarioExpect.isNewFact()) { continue; } for (FactMappingValue expectedResult : scenarioExpect.getExpectedResult()) { ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(expectedResult); ScenarioResult scenarioResult = fillResult(expectedResult, () -> createExtractorFunction(expressionEvaluator, expectedResult, scesimModelDescriptor) .apply(factInstance), expressionEvaluator); scenarioResults.add(scenarioResult); } } return scenarioResults; }    }
@Test public void getScenarioResultsTest() { List<InstanceGiven> scenario1Inputs = runnerHelper.extractGivenValues(simulation.getScesimModelDescriptor(), scenario1.getUnmodifiableFactMappingValues(), classLoader, expressionEvaluatorFactory); List<ScenarioExpect> scenario1Outputs = runnerHelper.extractExpectedValues(scenario1.getUnmodifiableFactMappingValues()); assertTrue(scenario1Inputs.size() > 0); InstanceGiven input1 = scenario1Inputs.get(0); scenario1Outputs = scenario1Outputs.stream().filter(elem -> elem.getFactIdentifier().equals(input1.getFactIdentifier())).collect(toList()); List<ScenarioResult> scenario1Results = runnerHelper.getScenarioResultsFromGivenFacts(simulation.getScesimModelDescriptor(), scenario1Outputs, input1, expressionEvaluatorFactory); assertEquals(1, scenario1Results.size()); assertEquals(FactMappingValueStatus.SUCCESS, scenario1Outputs.get(0).getExpectedResult().get(0).getStatus()); List<InstanceGiven> scenario2Inputs = runnerHelper.extractGivenValues(simulation.getScesimModelDescriptor(), scenario2.getUnmodifiableFactMappingValues(), classLoader, expressionEvaluatorFactory); List<ScenarioExpect> scenario2Outputs = runnerHelper.extractExpectedValues(scenario2.getUnmodifiableFactMappingValues()); assertTrue(scenario2Inputs.size() > 0); InstanceGiven input2 = scenario2Inputs.get(0); scenario2Outputs = scenario2Outputs.stream().filter(elem -> elem.getFactIdentifier().equals(input2.getFactIdentifier())).collect(toList()); List<ScenarioResult> scenario2Results = runnerHelper.getScenarioResultsFromGivenFacts(simulation.getScesimModelDescriptor(), scenario2Outputs, input2, expressionEvaluatorFactory); assertEquals(1, scenario2Results.size()); assertEquals(FactMappingValueStatus.SUCCESS, scenario1Outputs.get(0).getExpectedResult().get(0).getStatus()); List<ScenarioExpect> newFact = singletonList(new ScenarioExpect(personFactIdentifier, emptyList(), true)); List<ScenarioResult> scenario2NoResults = runnerHelper.getScenarioResultsFromGivenFacts(simulation.getScesimModelDescriptor(), newFact, input2, expressionEvaluatorFactory); assertEquals(0, scenario2NoResults.size()); Person person = new Person(); person.setFirstName("ANOTHER STRING"); InstanceGiven newInput = new InstanceGiven(personFactIdentifier, person); List<ScenarioResult> scenario3Results = runnerHelper.getScenarioResultsFromGivenFacts(simulation.getScesimModelDescriptor(), scenario1Outputs, newInput, expressionEvaluatorFactory); assertEquals(FactMappingValueStatus.FAILED_WITH_ERROR, scenario1Outputs.get(0).getExpectedResult().get(0).getStatus()); assertEquals(1, scenario3Results.size()); assertEquals(person.getFirstName(), scenario3Results.get(0).getResultValue().get()); assertEquals("NAME", scenario3Results.get(0).getFactMappingValue().getRawValue()); }