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 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; }
protected SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) { SortedMap<String, FactModelTree> toReturn = new TreeMap<>(); // map instance name to base class if (model != null) { final SimulationDescriptor simulationDescriptor = model.getSimulation().getSimulationDescriptor(); simulationDescriptor.getUnmodifiableFactMappings() .stream() .filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())) .forEach(factMapping -> { String dataObjectName = factMapping.getFactIdentifier().getClassName(); if (dataObjectName.contains(".")) { dataObjectName = dataObjectName.substring(dataObjectName.lastIndexOf(".") + 1); } final String instanceName = factMapping.getFactAlias(); if (!instanceName.equals(dataObjectName)) { final FactModelTree factModelTree = sourceMap.get(dataObjectName); if (factModelTree != null) { toReturn.put(instanceName, factModelTree); } } }); } return toReturn; }
@Test public void getScenarioGridColumnLocal() { String columnId = factMappingDescription.getExpressionIdentifier().getName(); String instanceTitle = factMappingDescription.getFactIdentifier().getName(); String propertyTitle = "PROPERTY TITLE"; final FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, type, ScenarioSimulationEditorConstants.INSTANCE.insertValue()); verify(scenarioGrid, times(1)).getScenarioHeaderTextBoxSingletonDOMElementFactory(); verify(scenarioGrid, times(1)).getHeaderBuilderLocal(eq(instanceTitle), eq(propertyTitle), eq(columnId), eq(columnGroup), eq(type), eq(scenarioHeaderTextBoxSingletonDOMElementFactoryMock)); }
@Test public void setHeaderColumn() { String columnId = factMappingDescription.getExpressionIdentifier().getName(); FactMappingType type = factMappingDescription.getExpressionIdentifier().getType(); String columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingDescription, true); reset(scenarioGridModelMock); columnId = factMappingGiven.getExpressionIdentifier().getName(); type = factMappingGiven.getExpressionIdentifier().getType(); columnGroup = type.name(); scenarioGrid.setHeaderColumn(1, factMappingGiven, true);
protected void setHeaderColumn(int columnIndex, FactMapping factMapping, boolean editableHeaders) { final FactIdentifier factIdentifier = factMapping.getFactIdentifier(); String columnId = factMapping.getExpressionIdentifier().getName(); String instanceTitle = factMapping.getFactAlias(); String propertyTitle = factMapping.getExpressionAlias(); String columnGroup = factMapping.getExpressionIdentifier().getType().name(); boolean isInstanceAssigned = isInstanceAssigned(factIdentifier); boolean isPropertyAssigned = isPropertyAssigned(isInstanceAssigned, factMapping); String placeHolder = getPlaceholder(isPropertyAssigned); ScenarioGridColumn scenarioGridColumn = getScenarioGridColumnLocal(instanceTitle, propertyTitle, columnId, columnGroup, factMapping.getExpressionIdentifier().getType(), placeHolder); scenarioGridColumn.setInstanceAssigned(isInstanceAssigned); scenarioGridColumn.setPropertyAssigned(isPropertyAssigned); scenarioGridColumn.setFactIdentifier(factIdentifier); scenarioGridColumn.setEditableHeaders(editableHeaders); // by default ScenarioGridColumnBuilders.ScenarioGridColumnBuilder.build() set ColumnWidthMode.auto to all generated columns if (FactMappingType.OTHER.equals(factMapping.getExpressionIdentifier().getType())) { scenarioGridColumn.setColumnWidthMode(ColumnWidthMode.FIXED); scenarioGridColumn.setMinimumWidth(scenarioGridColumn.getWidth()); } ((ScenarioGridModel) model).insertColumnGridOnly(columnIndex, scenarioGridColumn); }