public void sort() { factMappingValues.sort((a, b) -> { Integer aIndex = simulationDescriptor.getIndexByIdentifier(a.getFactIdentifier(), a.getExpressionIdentifier()); Integer bIndex = simulationDescriptor.getIndexByIdentifier(b.getFactIdentifier(), b.getExpressionIdentifier()); return aIndex.compareTo(bIndex); }); }
public List<ScenarioExpect> extractExpectedValues(List<FactMappingValue> factMappingValues) { List<ScenarioExpect> scenarioExpect = new ArrayList<>(); Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.EXPECT); Set<FactIdentifier> inputFacts = factMappingValues.stream() .filter(elem -> FactMappingType.GIVEN.equals(elem.getExpressionIdentifier().getType())) .map(FactMappingValue::getFactIdentifier) .collect(Collectors.toSet()); for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) { FactIdentifier factIdentifier = entry.getKey(); scenarioExpect.add(new ScenarioExpect(factIdentifier, entry.getValue(), !inputFacts.contains(factIdentifier))); } return scenarioExpect; }
public void sort() { factMappingValues.sort((a, b) -> { Integer aIndex = simulationDescriptor.getIndexByIdentifier(a.getFactIdentifier(), a.getExpressionIdentifier()); Integer bIndex = simulationDescriptor.getIndexByIdentifier(b.getFactIdentifier(), b.getExpressionIdentifier()); return aIndex.compareTo(bIndex); }); }
public Optional<FactMappingValue> getFactMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier) && e.getExpressionIdentifier().equals(expressionIdentifier)).findFirst(); }
public Optional<FactMappingValue> getFactMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier) && e.getExpressionIdentifier().equals(expressionIdentifier)).findFirst(); }
public String getDescription() { return factMappingValues.stream() .filter(e -> e.getExpressionIdentifier().equals(ExpressionIdentifier.DESCRIPTION) && e.getFactIdentifier().equals(FactIdentifier.DESCRIPTION) && e.getRawValue() != null) .map(e -> (String) e.getRawValue()) .findFirst().orElse(""); }
public String getDescription() { return factMappingValues.stream() .filter(e -> e.getExpressionIdentifier().equals(ExpressionIdentifier.DESCRIPTION) && e.getFactIdentifier().equals(FactIdentifier.DESCRIPTION) && e.getRawValue() != null) .map(e -> (String) e.getRawValue()) .findFirst().orElse(""); }
public Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifierAndFilter(List<FactMappingValue> factMappingValues, FactMappingType type) { Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = new HashMap<>(); for (FactMappingValue factMappingValue : factMappingValues) { FactIdentifier factIdentifier = factMappingValue.getFactIdentifier(); // null means skip if (factMappingValue.getRawValue() == null) { continue; } ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier(); if (expressionIdentifier == null) { throw new IllegalArgumentException("ExpressionIdentifier malformed"); } if (!Objects.equals(expressionIdentifier.getType(), type)) { continue; } groupByFactIdentifier.computeIfAbsent(factIdentifier, key -> new ArrayList<>()) .add(factMappingValue); } return groupByFactIdentifier; }
public Map<List<String>, Object> getParamsForBean(SimulationDescriptor simulationDescriptor, FactIdentifier factIdentifier, List<FactMappingValue> factMappingValues, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator) { Map<List<String>, Object> paramsForBean = new HashMap<>(); for (FactMappingValue factMappingValue : factMappingValues) { ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier(); FactMapping factMapping = simulationDescriptor.getFactMapping(factIdentifier, expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); List<String> pathToField = factMapping.getExpressionElementsWithoutClass().stream() .map(ExpressionElement::getStep).collect(toList()); try { Object value = expressionEvaluator.getValueForGiven(factMapping.getClassName(), factMappingValue.getRawValue()); paramsForBean.put(pathToField, value); } catch (IllegalArgumentException e) { factMappingValue.setError(true); throw new ScenarioException(e.getMessage(), e); } } return paramsForBean; }
protected Function<Object, ResultWrapper> createExtractorFunction(ExpressionEvaluator expressionEvaluator, FactMappingValue expectedResult, SimulationDescriptor simulationDescriptor) { return objectToCheck -> { ExpressionIdentifier expressionIdentifier = expectedResult.getExpressionIdentifier(); FactMapping factMapping = simulationDescriptor.getFactMapping(expectedResult.getFactIdentifier(), expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); List<String> pathToValue = factMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(toList()); ScenarioBeanWrapper<?> scenarioBeanWrapper = ScenarioBeanUtil.navigateToObject(objectToCheck, pathToValue, false); Object resultValue = scenarioBeanWrapper.getBean(); try { return expressionEvaluator.evaluate(expectedResult.getRawValue(), resultValue, scenarioBeanWrapper.getBeanClass()) ? createResult(resultValue) : createErrorResult(); } catch (Exception e) { expectedResult.setError(true); throw new ScenarioException(e.getMessage(), e); } }; }
@Override public void verifyConditions(SimulationDescriptor simulationDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluator expressionEvaluator, RequestContext requestContext) { DMNResult dmnResult = requestContext.getOutput(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 = simulationDescriptor.getFactMapping(factIdentifier, expressionIdentifier) .orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen")); ScenarioResult scenarioResult = fillResult(expectedResult, factIdentifier, () -> getSingleFactValueResult(factMapping, expectedResult, decisionResult, expressionEvaluator)); scenarioRunnerData.addResult(scenarioResult); } } }
/** * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code> * @param row */ public void insertRowGridOnly(final int rowIndex, final GridRow row, final Scenario scenario) { checkSimulation(); super.insertRow(rowIndex, row); scenario.getUnmodifiableFactMappingValues().forEach(value -> { FactIdentifier factIdentifier = value.getFactIdentifier(); ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier(); if (value.getRawValue() == null || value.getRawValue() instanceof String) { // Let' put a placeholder String stringValue = (String) value.getRawValue(); int columnIndex = simulation.getSimulationDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier); String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder(); setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder))); } else { throw new UnsupportedOperationException("Only string is supported at the moment"); } }); updateIndexColumn(); }