summaryrefslogtreecommitdiffstats
path: root/dcae-analytics-common/src
diff options
context:
space:
mode:
authorSingla, Rajiv (rs153v) <rs153v@att.com>2017-10-12 11:15:16 -0400
committerSingla, Rajiv (rs153v) <rs153v@att.com>2017-10-12 11:16:21 -0400
commit619add75ea412de8ef331d9ae898412818b203c6 (patch)
tree53c44fb41760e2ad4fa5ffc439e9fdd3360ce0ef /dcae-analytics-common/src
parent6b9782f9b6a4d062c9bc0dc387cad4bf3011e411 (diff)
TCA:Bug fix for JsonPath with non array values
Change-Id: I98bd9b78a5c7017ca98a0ce85f2ea30a2cb682df Signed-off-by: Singla, Rajiv (rs153v) <rs153v@att.com> Issue-Id: DCAEGEN2-153
Diffstat (limited to 'dcae-analytics-common/src')
-rw-r--r--dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilter.java5
-rw-r--r--dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java16
2 files changed, 20 insertions, 1 deletions
diff --git a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilter.java b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilter.java
index 54de5cc..38e8d28 100644
--- a/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilter.java
+++ b/dcae-analytics-common/src/main/java/org/openecomp/dcae/apod/analytics/common/service/filter/GenericJsonMessageFilter.java
@@ -29,6 +29,7 @@ import org.openecomp.dcae.apod.analytics.common.service.processor.AbstractMessag
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.List;
import java.util.Set;
/**
@@ -77,7 +78,9 @@ public class GenericJsonMessageFilter extends AbstractMessageProcessor<JsonMessa
final DocumentContext documentContext = JsonPath.parse(jsonMessage);
String jsonPathValue = null;
try {
- jsonPathValue = documentContext.read(jsonPath, String.class);
+ final List jsonPathValues = documentContext.read(jsonPath);
+ final Object pathValue = jsonPathValues.isEmpty() ? null : jsonPathValues.get(0);
+ jsonPathValue = pathValue instanceof Number ? pathValue.toString() : (String) pathValue;
} catch (PathNotFoundException ex) {
LOG.info("Unable to find json Path: {}. Exception: {}, Json Message: {}", jsonPath, ex, jsonMessage);
}
diff --git a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java
index 1cd59e8..fd28624 100644
--- a/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java
+++ b/dcae-analytics-common/src/test/java/org/openecomp/dcae/apod/analytics/common/BaseAnalyticsCommonUnitTest.java
@@ -20,9 +20,13 @@
package org.openecomp.dcae.apod.analytics.common;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Suppliers;
+import org.junit.BeforeClass;
import org.openecomp.dcae.apod.analytics.common.service.processor.TestEarlyTerminatingProcessor;
import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor1;
import org.openecomp.dcae.apod.analytics.common.service.processor.TestMessageProcessor2;
+import org.openecomp.dcae.apod.analytics.model.util.json.AnalyticsModelObjectMapperSupplier;
import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;
/**
@@ -37,6 +41,18 @@ public abstract class BaseAnalyticsCommonUnitTest extends BaseDCAEAnalyticsUnitT
protected static final String CEF_MESSAGE_FILE_PATH = "data/json/cef/cef_message.json";
+ protected static ObjectMapper objectMapper;
+
+ /**
+ * Before running test cases need to assign object mapper.
+ */
+ @BeforeClass
+ public static void beforeClass() {
+ final AnalyticsModelObjectMapperSupplier analyticsModelObjectMapperSupplier =
+ new AnalyticsModelObjectMapperSupplier();
+ objectMapper = Suppliers.memoize(analyticsModelObjectMapperSupplier).get();
+ }
+
/*
* Test implementation for {@link CDAPAppSettings}
*/