From 56c9f2b4c2cf204d75b7270bcacc9f9678b7c097 Mon Sep 17 00:00:00 2001 From: Carlos Mendes Date: Sun, 7 Jan 2024 13:52:30 -0300 Subject: [PATCH] fix tests --- .../resources/scenario/ScenarioSpec.java | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/main/java/br/unifor/ppgia/resiliencebench/resources/scenario/ScenarioSpec.java b/src/main/java/br/unifor/ppgia/resiliencebench/resources/scenario/ScenarioSpec.java index 63ab64e..3cda5a1 100644 --- a/src/main/java/br/unifor/ppgia/resiliencebench/resources/scenario/ScenarioSpec.java +++ b/src/main/java/br/unifor/ppgia/resiliencebench/resources/scenario/ScenarioSpec.java @@ -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() { @@ -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 getPatternConfig() { - return toObjectMap(patternConfig.get("patternConfig")); - } - - private static Map toObjectMap(JsonNode jsonNode) { - Map 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 list = new ArrayList<>(); jsonNode.elements().forEachRemaining(element -> list.add(toObject(element))); return list;