public static FactIdentifier create(String name, String className) { return new FactIdentifier(name, className); }
public Collection<String> getFactNames() { return factMappingValues.stream().map(e -> e.getFactIdentifier().getName()).collect(toSet()); }
/** * Returns <code>true</code> when * <p> * factIdentifier == FactIdentifier.DESCRIPTION * </p><p> * <b>or</b> * <p> * factIdentifier != FactIdentifier.EMPTY * </p><p> * <b>and</b> * </p><p> * factIdentifier != FactIdentifier.INDEX * </p><p> * @param factIdentifier * @return */ protected boolean isInstanceAssigned(FactIdentifier factIdentifier) { if (FactIdentifier.DESCRIPTION.equals(factIdentifier)) { return true; } else { return !(FactIdentifier.EMPTY.equals(factIdentifier) || FactIdentifier.INDEX.equals(factIdentifier)); } }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
@Before public void init() { simulationDescriptor = new SimulationDescriptor(); factIdentifier = FactIdentifier.create("test fact", String.class.getCanonicalName()); expressionIdentifier = ExpressionIdentifier.create("test expression", FactMappingType.EXPECT); }
public FactMapping(String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { this.factAlias = factAlias; this.expressionIdentifier = expressionIdentifier; this.className = factIdentifier.getClassName(); this.factIdentifier = factIdentifier; }
@Before public void init() { simulationDescriptor = new SimulationDescriptor(); factIdentifier = FactIdentifier.create("test fact", String.class.getCanonicalName()); expressionIdentifier = ExpressionIdentifier.create("test expression", FactMappingType.EXPECT); }
public int getIndexByIdentifier(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { return IntStream.range(0, factMappings.size()).filter(index -> { FactMapping factMapping = factMappings.get(index); return factMapping.getExpressionIdentifier().equals(expressionIdentifier) && factMapping.getFactIdentifier().equals(factIdentifier); }).findFirst().orElseThrow(() -> new IllegalArgumentException( new StringBuilder().append("Impossible to find a FactMapping with factIdentifier '").append(factIdentifier.getName()) .append("' and expressionIdentifier '").append(expressionIdentifier.getName()).append("'").toString())); }
public FactMapping(String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { this.factAlias = factAlias; this.expressionIdentifier = expressionIdentifier; this.className = factIdentifier.getClassName(); this.factIdentifier = factIdentifier; }
public Collection<String> getFactNames() { return factMappingValues.stream().map(e -> e.getFactIdentifier().getName()).collect(toSet()); }
@Test public void getIndexByIdentifierTest() { List<FactMapping> originalFactMappings = IntStream.range(0, 2).boxed() .map(i -> simulationDescriptor .addFactMapping(FactIdentifier.create("test " + i, String.class.getCanonicalName()), this.expressionIdentifier) ).collect(Collectors.toList()); int indexToCheck = 0; int indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); indexToCheck = 1; indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); }
public static FactIdentifier create(String name, String className) { return new FactIdentifier(name, className); }
/** * Dynamically evaluated status to know if the values of the given column are editable or not * @return */ public boolean isReadOnly() { if (FactIdentifier.INDEX.equals(factIdentifier) || FactIdentifier.EMPTY.equals(factIdentifier)) { return true; } if (FactIdentifier.DESCRIPTION.equals(factIdentifier)) { return false; } else { return !isPropertyAssigned(); } }
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; }
public FactMappingValue addMappingValue(FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier, Object value) { String factName = factIdentifier.getName(); if (getFactMappingValue(factIdentifier, expressionIdentifier).isPresent()) { throw new IllegalArgumentException( new StringBuilder().append("A fact value for expression '").append(expressionIdentifier.getName()) .append("' and fact '").append(factName).append("' already exist").toString()); } FactMappingValue factMappingValue = new FactMappingValue(factIdentifier, expressionIdentifier, value); factMappingValues.add(factMappingValue); return factMappingValue; }
@Test public void getIndexByIdentifierTest() { List<FactMapping> originalFactMappings = IntStream.range(0, 2).boxed() .map(i -> simulationDescriptor .addFactMapping(FactIdentifier.create("test " + i, String.class.getCanonicalName()), this.expressionIdentifier) ).collect(Collectors.toList()); int indexToCheck = 0; int indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); indexToCheck = 1; indexRetrieved = simulationDescriptor.getIndexByIdentifier(originalFactMappings.get(indexToCheck).getFactIdentifier(), this.expressionIdentifier); assertEquals(indexToCheck, indexRetrieved); }
@Test public void getExpressionElementsWithoutClass() { FactMapping original = new FactMapping("FACT_ALIAS", new FactIdentifier("FI_TEST", "com.test.Foo"), new ExpressionIdentifier("EI_TEST", FactMappingType.GIVEN)); assertThatThrownBy(original::getExpressionElementsWithoutClass) .isInstanceOf(IllegalStateException.class) .hasMessage("ExpressionElements malformed"); assertEquals(0, original.getExpressionElements().size()); original.addExpressionElement("STEP", String.class.getCanonicalName()); assertEquals(0, original.getExpressionElementsWithoutClass().size()); assertEquals(1, original.getExpressionElements().size()); } }
public List<FactMappingValue> getFactMappingValuesByFactIdentifier(FactIdentifier factIdentifier) { return factMappingValues.stream().filter(e -> e.getFactIdentifier().equals(factIdentifier)).collect(toList()); }
public List<ScenarioGiven> extractGivenValues(SimulationDescriptor simulationDescriptor, List<FactMappingValue> factMappingValues, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator) { List<ScenarioGiven> scenarioGiven = new ArrayList<>(); Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.GIVEN); for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) { FactIdentifier factIdentifier = entry.getKey(); // for each fact, create a map of path to fields and values to set Map<List<String>, Object> paramsForBean = getParamsForBean(simulationDescriptor, factIdentifier, entry.getValue(), classLoader, expressionEvaluator); Object bean = getDirectMapping(paramsForBean) .orElseGet(() -> createObject(factIdentifier.getClassName(), paramsForBean, classLoader)); scenarioGiven.add(new ScenarioGiven(factIdentifier, bean)); } return scenarioGiven; }
public FactMapping addFactMapping(int index, String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { if (getFactMapping(factIdentifier, expressionIdentifier).isPresent()) { throw new IllegalArgumentException( new StringBuilder().append("An expression with name '").append(expressionIdentifier.getName()) .append("' already exists for the fact '").append(factIdentifier.getName()).append("'").toString()); } if (index > factMappings.size()) { throw new IllegalArgumentException( new StringBuilder().append("Impossible to add an element at position ").append(index) .append(" because there are only ").append(factMappings.size()).append(" elements").toString()); } FactMapping factMapping = new FactMapping(factAlias, factIdentifier, expressionIdentifier); factMappings.add(index, factMapping); return factMapping; }