DMNScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected void verifyConditions(ScesimModelDescriptor scesimModelDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, Map<String, Object> requestContext) { DMNResult dmnResult = (DMNResult) requestContext.get(DMNScenarioExecutableBuilder.DMN_RESULT); for (ScenarioExpect output : scenarioRunnerData.getExpects()) { FactIdentifier factIdentifier = output.getFactIdentifier(); String decisionName = factIdentifier.getName(); DMNDecisionResult decisionResult = dmnResult.getDecisionResultByName(decisionName); if (decisionResult == null) { throw new ScenarioException("DMN execution has not generated a decision result with name " + decisionName); } for (FactMappingValue expectedResult : output.getExpectedResult()) { ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier(); FactMapping factMapping = scesimModelDescriptor.getFactMapping(factIdentifier, expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(expectedResult); ScenarioResult scenarioResult = fillResult(expectedResult, () -> getSingleFactValueResult(factMapping, expectedResult, decisionResult, expressionEvaluator), expressionEvaluator); scenarioRunnerData.addResult(scenarioResult); } } }    }
@Test public void verifyConditions() { ScenarioRunnerData scenarioRunnerData1 = new ScenarioRunnerData(); scenarioRunnerData1.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(firstNameExpectedValue))); assertThatThrownBy(() -> runnerHelper.verifyConditions(simulation.getScesimModelDescriptor(), scenarioRunnerData1, expressionEvaluatorFactory, requestContextMock)) .isInstanceOf(ScenarioException.class) .hasMessage("DMN execution has not generated a decision result with name Fact 1"); when(dmnResultMock.getDecisionResultByName(anyString())).thenReturn(dmnDecisionResultMock); when(dmnDecisionResultMock.getEvaluationStatus()).thenReturn(DecisionEvaluationStatus.SUCCEEDED); runnerHelper.verifyConditions(simulation.getScesimModelDescriptor(), scenarioRunnerData1, expressionEvaluatorFactory, requestContextMock); assertEquals(1, scenarioRunnerData1.getResults().size()); assertFalse(scenarioRunnerData1.getResults().get(0).getResult()); when(dmnDecisionResultMock.getResult()).thenReturn(""); assertThatThrownBy(() -> runnerHelper.verifyConditions(simulation.getScesimModelDescriptor(), scenarioRunnerData1, expressionEvaluatorFactory, requestContextMock)) .isInstanceOf(ScenarioException.class) .hasMessage("Wrong resultRaw structure because it is not a complex type as expected"); Map<String, Object> resultMap = new HashMap<>(); resultMap.put("firstName", "WrongValue"); when(dmnDecisionResultMock.getResult()).thenReturn(resultMap); ScenarioRunnerData scenarioRunnerData2 = new ScenarioRunnerData(); scenarioRunnerData2.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(firstNameExpectedValue))); runnerHelper.verifyConditions(simulation.getScesimModelDescriptor(), scenarioRunnerData2, expressionEvaluatorFactory, requestContextMock); assertEquals(1, scenarioRunnerData2.getResults().size()); assertFalse(scenarioRunnerData2.getResults().get(0).getResult()); ScenarioRunnerData scenarioRunnerData3 = new ScenarioRunnerData(); scenarioRunnerData3.addExpect(new ScenarioExpect(personFactIdentifier, singletonList(firstNameExpectedValue))); resultMap.put("firstName", NAME); runnerHelper.verifyConditions(simulation.getScesimModelDescriptor(), scenarioRunnerData3, expressionEvaluatorFactory, requestContextMock); assertEquals(1, scenarioRunnerData3.getResults().size()); assertTrue(scenarioRunnerData3.getResults().get(0).getResult()); ExpressionEvaluatorFactory expressionEvaluatorFactoryMock = mock(ExpressionEvaluatorFactory.class); when(expressionEvaluatorFactoryMock.getOrCreate(any())).thenReturn(mock(ExpressionEvaluator.class)); runnerHelper.verifyConditions(simulation.getScesimModelDescriptor(), scenarioRunnerData3, expressionEvaluatorFactoryMock, requestContextMock); assertEquals(FactMappingValueStatus.FAILED_WITH_ERROR, scenarioRunnerData3.getResults().get(0).getFactMappingValue().getStatus()); }