Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmendesce committed Jan 7, 2024
1 parent b5ed030 commit 56c9f2b
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public ScenarioSpec(
this.sourceServiceName = sourceServiceName;
this.workload = workload;
this.fault = fault;
patternConfig.forEach(this::addToPatternConfig);
this.patternConfig = patternConfig.entrySet().stream()
.collect(LinkedHashMap::new,
(map, entry) -> map.put(entry.getKey(), mapper.valueToTree(entry.getValue())),
LinkedHashMap::putAll);
}

public ScenarioSpec() {
Expand All @@ -58,30 +61,18 @@ public ScenarioFaultTemplate getFault() {
return fault;
}

public void addToPatternConfig(String name, Object value) {
internalPatternConfig.put(name, mapper.valueToTree(value));
patternConfig.put("patternConfig", mapper.valueToTree(internalPatternConfig));
}

/**
* Returns a copy of the given expanded patternConfig
*/
public Map<String, Object> getPatternConfig() {
return toObjectMap(patternConfig.get("patternConfig"));
}

private static Map<String, Object> toObjectMap(JsonNode jsonNode) {
Map<String, Object> resultMap = new LinkedHashMap<>();
if (jsonNode != null && jsonNode.isObject()) {
jsonNode.fields().forEachRemaining(entry -> resultMap.put(entry.getKey(), toObject(entry.getValue())));
}
return resultMap;
return patternConfig.entrySet().stream()
.collect(LinkedHashMap::new,
(map, entry) -> map.put(entry.getKey(), toObject(entry.getValue())),
LinkedHashMap::putAll);
}

private static Object toObject(JsonNode jsonNode) {
if (jsonNode.isObject()) {
return toObjectMap(jsonNode);
} else if (jsonNode.isArray()) {
if (jsonNode.isArray()) {
List<Object> list = new ArrayList<>();
jsonNode.elements().forEachRemaining(element -> list.add(toObject(element)));
return list;
Expand Down

0 comments on commit 56c9f2b

Please sign in to comment.