Initial search service commit
[aai/search-data-service.git] / src / test / java / org / openecomp / sa / searchdbabstraction / searchapi / DateHistogramAggregationTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * Search Data Service
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License ati
12  *
13  *    http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.openecomp.sa.searchdbabstraction.searchapi;
26
27 import com.fasterxml.jackson.databind.ObjectMapper;
28 import org.junit.Test;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.fail;
32
33 public class DateHistogramAggregationTest {
34   ObjectMapper mapper = new ObjectMapper();
35
36   @Test
37   public void testFullSet() {
38     String input =
39         "{\r\n  \"field\": \"mydate\",\r\n  \"interval\": \"day\",\r\n  \"time-zone\": \"-01:00\"\r\n}";
40
41     String expected =
42         "\"date_histogram\": {\"field\": \"mydate\", \"interval\": \"day\", \"time_zone\": \"-01:00\"}";
43
44     DateHistogramAggregation actual;
45     try {
46       actual = mapper.readValue(input, DateHistogramAggregation.class);
47       assertEquals(expected, actual.toElasticSearch());
48     } catch (Exception e) {
49       fail("Exception occurred: " + e.getMessage());
50     }
51   }
52
53   @Test
54   public void test2() {
55     String input =
56         "{\r\n  \"field\": \"mydate\",\r\n  \"interval\": \"day\"\r\n}";
57
58     String expected =
59         "\"date_histogram\": {\"field\": \"mydate\", \"interval\": \"day\"}";
60
61     DateHistogramAggregation actual;
62     try {
63       actual = mapper.readValue(input, DateHistogramAggregation.class);
64       assertEquals(expected, actual.toElasticSearch());
65     } catch (Exception e) {
66       fail("Exception occurred: " + e.getMessage());
67     }
68   }
69
70   @Test
71   public void test3() {
72     String input =
73         "{\r\n  \"field\": \"mydate\"\r\n}";
74
75     String expected =
76         "\"date_histogram\": {\"field\": \"mydate\"}";
77
78     DateHistogramAggregation actual;
79     try {
80       actual = mapper.readValue(input, DateHistogramAggregation.class);
81       assertEquals(expected, actual.toElasticSearch());
82     } catch (Exception e) {
83       fail("Exception occurred: " + e.getMessage());
84     }
85   }
86
87 }