summaryrefslogtreecommitdiffstats
path: root/components/datalake-handler/feeder
diff options
context:
space:
mode:
authorGuobiao Mo <guobiaomo@chinamobile.com>2019-06-11 09:59:29 -0700
committerGuobiao Mo <guobiaomo@chinamobile.com>2019-06-11 09:59:29 -0700
commit5df8be3782bfe95e6c7a8ab3847899d9fa2ca20e (patch)
tree86b2cf419aa69c69a84f4472423d8d94e6a86a2e /components/datalake-handler/feeder
parent9beee367caa9591882136498237825488978c5f6 (diff)
Unit test for JsonUtil
Issue-ID: DCAEGEN2-1598 Change-Id: I61ccf5a2859fe80351ea6bf31138b775fe68bead Signed-off-by: Guobiao Mo <guobiaomo@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder')
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/JsonUtilTest.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/JsonUtilTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/JsonUtilTest.java
new file mode 100644
index 00000000..c7dd0617
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/util/JsonUtilTest.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DCAE
+ * ================================================================================
+ * Copyright 2019 China Mobile
+ *=================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.datalake.feeder.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.json.JSONObject;
+import org.junit.Test;
+
+/**
+ * test json utils
+ *
+ * @author Guobiao Mo
+ */
+public class JsonUtilTest {
+
+ @Test
+ public void arrayAggregate() {
+ String text = "{a:{b:[{c:1, d: vvvv},{c:2, d: xxxx, f:6.9}]}}";
+ JSONObject json = new JSONObject(text);
+
+ JsonUtil.arrayAggregate("/a/b", json);
+ String expected = "{\"a\":{\"b\":[{\"c\":1,\"d\":\"vvvv\"},{\"c\":2,\"d\":\"xxxx\",\"f\":6.9}],\"b_count\":2,\"b_min\":{\"f\":6.9,\"c\":1},\"b_max\":{\"f\":6.9,\"c\":2},\"b_sum\":{\"f\":6.9,\"c\":3},\"b_average\":{\"f\":3.45,\"c\":1.5}}}";
+ assertEquals(expected, json.toString());
+
+ JsonUtil.arrayAggregate("/a/bxx", json);
+
+ }
+
+ @Test
+ public void flattenArray() {
+ String text = "{a:{b:[{c:1, d: vvvv},{c:2, d: xxxx, f:6.9}]}}";
+ JSONObject json = new JSONObject(text);
+
+ JsonUtil.flattenArray("/a/b/d", json);
+ System.out.println(json.toString());
+ String expected = "{\"a\":{\"b_d_vvvv\":{\"c\":1,\"d\":\"vvvv\"},\"b\":[{\"c\":1,\"d\":\"vvvv\"},{\"c\":2,\"d\":\"xxxx\",\"f\":6.9}],\"b_d_xxxx\":{\"c\":2,\"d\":\"xxxx\",\"f\":6.9}}}";
+ assertEquals(expected, json.toString());
+
+ JsonUtil.flattenArray("/a/bxx", json);
+
+ }
+
+}