2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.sa.searchdbabstraction.elasticsearch.dao;
25 import com.fasterxml.jackson.annotation.JsonInclude.Include;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.json.simple.JSONObject;
28 import org.json.simple.parser.JSONParser;
29 import org.junit.Test;
30 import org.onap.aai.sa.searchdbabstraction.entity.AggregationResult;
31 import org.onap.aai.sa.searchdbabstraction.entity.AggregationResults;
32 import org.onap.aai.sa.searchdbabstraction.util.AggregationParsingUtil;
34 public class AggregationResponseParsingTest {
37 public void testParseAggregationResponse() {
38 JSONParser parser = new JSONParser();
42 "{\r\n \"aggregations\": {\r\n \"violations\": {\r\n \"doc_count\": 2,\r\n \"by_Timestamp\": {\r\n \"doc_count_error_upper_bound\": 0,\r\n \"sum_other_doc_count\": 0,\r\n \"buckets\": [\r\n {\r\n \"key\": 7199992,\r\n \"key_as_string\": \"Jan 1 1970 01:59:59\",\r\n \"doc_count\": 2\r\n }\r\n ]\r\n }\r\n }\r\n }\r\n}";
45 root = (JSONObject) parser.parse(input);
46 JSONObject aggregations = (JSONObject) root.get("aggregations");
47 AggregationResult[] results = AggregationParsingUtil.parseAggregationResults(aggregations);
48 AggregationResults aggs = new AggregationResults();
49 ObjectMapper mapper = new ObjectMapper();
50 aggs.setAggregations(results);
51 System.out.println(mapper.setSerializationInclusion(Include.NON_NULL)
52 .writerWithDefaultPrettyPrinter().writeValueAsString(aggs));
53 } catch (Exception e) {
59 public void testParseAggregationResponse2() {
60 JSONParser parser = new JSONParser();
64 "{\r\n \"aggregations\": {\r\n \"entityType\": {\r\n \"doc_count_error_upper_bound\": 0,\r\n \"sum_other_doc_count\": 0,\r\n \"buckets\": [\r\n {\r\n \"key\": \"entity1\",\r\n \"doc_count\": 5,\r\n \"byVersion\": {\r\n \"doc_count_error_upper_bound\": 0,\r\n \"sum_other_doc_count\": 0,\r\n \"buckets\": [\r\n {\r\n \"key\": \"0\",\r\n \"doc_count\": 5\r\n }\r\n ]\r\n }\r\n }\r\n ]\r\n }\r\n }\r\n}";
67 root = (JSONObject) parser.parse(input);
68 JSONObject aggregations = (JSONObject) root.get("aggregations");
69 AggregationResult[] results = AggregationParsingUtil.parseAggregationResults(aggregations);
70 AggregationResults aggs = new AggregationResults();
71 ObjectMapper mapper = new ObjectMapper();
72 aggs.setAggregations(results);
73 System.out.println(mapper.setSerializationInclusion(Include.NON_NULL)
74 .writerWithDefaultPrettyPrinter().writeValueAsString(aggs));
75 } catch (Exception e) {
81 public void testParseAggregationResponse3() {
82 JSONParser parser = new JSONParser();
86 "{\r\n \"aggregations\": {\r\n \"validateTimes\": {\r\n \"buckets\": [\r\n {\r\n \"key\": \"Jan 10 2017 21:6:6-Jan 24 2017 13:43:5\",\r\n \"from\": 1484082366000,\r\n \"from_as_string\": \"Jan 10 2017 21:6:6\",\r\n \"to\": 1485265385000,\r\n \"to_as_string\": \"Jan 24 2017 13:43:5\",\r\n \"doc_count\": 95\r\n },\r\n {\r\n \"key\": \"Feb 3 2017 18:27:39-*\",\r\n \"from\": 1486146459000,\r\n \"from_as_string\": \"Feb 3 2017 18:27:39\",\r\n \"doc_count\": 2\r\n }\r\n ]\r\n }\r\n }\r\n}";
89 root = (JSONObject) parser.parse(input);
90 JSONObject aggregations = (JSONObject) root.get("aggregations");
91 AggregationResult[] results = AggregationParsingUtil.parseAggregationResults(aggregations);
92 AggregationResults aggs = new AggregationResults();
93 ObjectMapper mapper = new ObjectMapper();
94 aggs.setAggregations(results);
95 System.out.println(mapper.setSerializationInclusion(Include.NON_NULL)
96 .writerWithDefaultPrettyPrinter().writeValueAsString(aggs));
97 } catch (Exception e) {