summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-10-19 12:03:35 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-10-19 12:08:01 +0100
commit56858b0b356c62bd6fdea3486343d331bbc9567d (patch)
tree99a4c7e9a1f9cfc9d6b26f9735d3f5200f6e9ff4 /services
parentd4e7632aa00b42c544406fe9d83621c50831fe8e (diff)
Fix bug to allow JSON arrays of events
Apex should allow JSON arrays of events to be processed, processing the array of events as they come in. This review changes the Apex JSON array handling to allow arrays of JSON events to be processed. Arrays of events are required to perform Apex pewrformance tests. Change-Id: I08ddc9659414bd076fbaa250182335d6f38473e6 Issue-ID: POLICY-812 Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'services')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java3
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java5
2 files changed, 5 insertions, 3 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java
index 78b96ed2c..549947e9b 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java
@@ -24,6 +24,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.internal.LinkedTreeMap;
import java.util.ArrayList;
import java.util.Collection;
@@ -150,6 +151,8 @@ public class Apex2JsonEventConverter implements ApexEventProtocolConverter {
eventList.add(jsonStringApexEvent(eventName, (String) jsonListObject));
} else if (jsonListObject instanceof JsonObject) {
eventList.add(jsonObject2ApexEvent(eventName, (JsonObject) jsonListObject));
+ } else if (jsonListObject instanceof LinkedTreeMap) {
+ eventList.add(jsonObject2ApexEvent(eventName, new Gson().toJsonTree(jsonListObject).getAsJsonObject()));
} else {
throw new ApexEventException("incoming event (" + jsonEventString
+ ") is a JSON object array containing an invalid object " + jsonListObject);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java
index 4dbdc8cce..3ccdd5926 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java
@@ -75,9 +75,8 @@ public class TestJsonEventConverter {
converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]");
fail("test should throw an exception");
} catch (Exception tae) {
- assertEquals("Failed to unmarshal JSON event: incoming event ([{\"aKey\": 1},{\"aKey\": 2}]) "
- + "is a JSON object array containing an invalid object "
- + "{aKey=1.0}, event=[{\"aKey\": 1},{\"aKey\": 2}]", tae.getMessage());
+ assertEquals("Failed to unmarshal JSON event: event received without mandatory parameter \"name\" "
+ + "on configuration or on event, event=[{\"aKey\": 1},{\"aKey\": 2}]", tae.getMessage());
}
try {