-/**\r
- * ============LICENSE_START=======================================================\r
- * org.onap.aai\r
- * ================================================================================\r
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * Copyright © 2017 Amdocs\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END=========================================================\r
- *\r
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- */\r
-package org.onap.aai.sa.searchdbabstraction.searchapi;\r
-\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-import org.junit.Assert;\r
-import org.junit.Test;\r
-import org.onap.aai.sa.rest.TestUtils;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.Date;\r
-\r
-public class RangeQueryTest {\r
-\r
- @Test(expected=IllegalArgumentException.class)\r
- public void testSetGt(){\r
-\r
- RangeQuery rq = new RangeQuery();\r
- rq.setLt(new String("2x"));\r
- Assert.assertEquals("2x", rq.getLt());\r
- Assert.assertNotNull(rq.toElasticSearch());\r
- Assert.assertNotNull(rq.toString());\r
- rq.setGt(new Integer(1));\r
- }\r
-\r
- @Test(expected=IllegalArgumentException.class)\r
- public void testSetGte(){\r
-\r
- RangeQuery rq = new RangeQuery();\r
- rq.setGt(new Integer(1));\r
- Assert.assertNotNull(rq.toElasticSearch());\r
- Assert.assertNotNull(rq.toString());\r
- rq.setGte(new Integer(1));\r
- }\r
-\r
- @Test(expected=IllegalArgumentException.class)\r
- public void testSetLt(){\r
-\r
- RangeQuery rq = new RangeQuery();\r
- rq.setLt(new Integer(1));\r
- rq.setFormat("format-1");\r
- Assert.assertEquals(rq.getFormat(), "format-1");\r
- Assert.assertNotNull(rq.toElasticSearch());\r
- Assert.assertNotNull(rq.toString());\r
-\r
- rq.setGt(new Integer(1));\r
- Assert.assertNotNull(rq.toElasticSearch());\r
- Assert.assertNotNull(rq.toString());\r
- rq.setLt(new String("10"));\r
- }\r
-\r
- @Test(expected=IllegalArgumentException.class)\r
- public void testSetLte(){\r
- RangeQuery rq = new RangeQuery();\r
- rq.setGt(new Integer(1));\r
- rq.setTimeZone("CT");\r
- Assert.assertEquals(rq.getTimeZone(), "CT");\r
- Assert.assertNotNull(rq.toElasticSearch());\r
- Assert.assertNotNull(rq.toString());\r
-\r
- rq.setLte(new String("10"));\r
- }\r
-\r
- @Test\r
- public void testSearchStatementAggregations() throws IOException {\r
- File queryWithSubrangeFile = new File("src/test/resources/json/queries/query-with-subrange.json");\r
- String queryWithSubrangeStr = TestUtils.readFileToString(queryWithSubrangeFile);\r
-\r
- ObjectMapper mapper = new ObjectMapper();\r
- SearchStatement ss = mapper.readValue(queryWithSubrangeStr, SearchStatement.class);\r
-\r
- Aggregation a1 = getAggregationObject();\r
- Aggregation a2 = getAggregationObject();\r
- Aggregation[] aggs= new Aggregation[] {a1, a2};\r
- ss.setAggregations(aggs);\r
- Assert.assertNotNull(ss.toString());\r
- }\r
-\r
- private Aggregation getAggregationObject(){\r
- Aggregation a = new Aggregation();\r
-\r
- AggregationStatement as = new AggregationStatement();\r
- DateHistogramAggregation dha = new DateHistogramAggregation();\r
- dha.setField("field-1");\r
- dha.setInterval("interval-1");\r
- Assert.assertEquals(dha.getInterval(), "interval-1");\r
- dha.setTimeZone("CT");\r
- Assert.assertEquals(dha.getTimeZone(), "CT");\r
- dha.setFormat("format-1");\r
- Assert.assertEquals(dha.getFormat(), "format-1");\r
- dha.setSize(10);\r
- dha.setMinThreshold(1);\r
- Assert.assertNotNull(dha.toElasticSearch());\r
- Assert.assertNotNull(dha.toString());\r
- as.setDateHist(dha);\r
- as.toString();\r
-\r
- as.getNestedPath();\r
-\r
- DateRangeAggregation dra = new DateRangeAggregation();\r
- dra.setField("field-1");\r
- dra.setMinThreshold(1);\r
- dra.setFormat("format-1");\r
- Assert.assertEquals(dra.getFormat(), "format-1");\r
- DateRange dr = new DateRange();\r
- dr.setFromDate("01-12-2017");\r
- Assert.assertEquals(dr.getFromDate(), "01-12-2017");\r
- dr.setToDate("21-12-2017");\r
- Assert.assertEquals(dr.getToDate(), "21-12-2017");\r
- DateRange[] drs = {dr};\r
- dra.setDateRanges(drs);\r
- Assert.assertTrue(dra.getDateRanges().length==1);\r
- Assert.assertNotNull(dra.toElasticSearch());\r
- Assert.assertNotNull(dra.toString());\r
- as.setDateRange(dra);\r
- as.toString();\r
-\r
- as.getNestedPath();\r
-\r
- GroupByAggregation gba = new GroupByAggregation();\r
- gba.setField("field-1");\r
- gba.setMinThreshold(1);\r
- Assert.assertNotNull(gba.toElasticSearch());\r
- Assert.assertNotNull(gba.toString());\r
- as.setGroupBy(gba);\r
- Assert.assertNotNull(as.toString());\r
-\r
- a.setStatement(as);\r
- Assert.assertNotNull(a.toString());\r
- return a;\r
- }\r
-}\r
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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.aai.sa.searchdbabstraction.searchapi;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.File;
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.aai.sa.rest.TestUtils;
+
+public class RangeQueryTest {
+
+ static {
+ // Set the location of the payload translation JSON file.
+ System.setProperty("CONFIG_HOME", "src/test/resources/json");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetGt() {
+ RangeQuery rq = new RangeQuery();
+ rq.setLt(new String("2x"));
+ Assert.assertEquals("2x", rq.getLt());
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+ rq.setGt(new Integer(1));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetGte() {
+ RangeQuery rq = new RangeQuery();
+ rq.setGt(new Integer(1));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+ rq.setGte(new Integer(1));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetLt() {
+ RangeQuery rq = new RangeQuery();
+ rq.setLt(new Integer(1));
+ rq.setFormat("format-1");
+ assertThat(rq.getFormat(), is(equalTo("format-1")));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+
+ rq.setGt(new Integer(1));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+ rq.setLt(new String("10"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testSetLte() {
+ RangeQuery rq = new RangeQuery();
+ rq.setGt(new Integer(1));
+ rq.setTimeZone("CT");
+ assertThat(rq.getTimeZone(), is(equalTo("CT")));
+ Assert.assertNotNull(rq.toElasticSearch());
+ Assert.assertNotNull(rq.toString());
+
+ rq.setLte(new String("10"));
+ }
+
+ @Test
+ public void testSearchStatementAggregations() throws IOException {
+ File queryWithSubrangeFile = new File("src/test/resources/json/queries/query-with-subrange.json");
+ String queryWithSubrangeStr = TestUtils.readFileToString(queryWithSubrangeFile);
+
+ ObjectMapper mapper = new ObjectMapper();
+ SearchStatement ss = mapper.readValue(queryWithSubrangeStr, SearchStatement.class);
+
+ Aggregation a1 = getAggregationObject();
+ Aggregation a2 = getAggregationObject();
+ Aggregation[] aggs = new Aggregation[] {a1, a2};
+ ss.setAggregations(aggs);
+ Assert.assertNotNull(ss.toString());
+ }
+
+ private Aggregation getAggregationObject() {
+ Aggregation a = new Aggregation();
+
+ AggregationStatement as = new AggregationStatement();
+ DateHistogramAggregation dha = new DateHistogramAggregation();
+ dha.setField("field-1");
+ dha.setInterval("interval-1");
+ assertThat(dha.getInterval(), is(equalTo("interval-1")));
+ dha.setTimeZone("CT");
+ assertThat(dha.getTimeZone(), is(equalTo("CT")));
+ dha.setFormat("format-1");
+ assertThat(dha.getFormat(), is(equalTo("format-1")));
+ dha.setSize(10);
+ dha.setMinThreshold(1);
+ Assert.assertNotNull(dha.toElasticSearch());
+ Assert.assertNotNull(dha.toString());
+ as.setDateHist(dha);
+ as.toString();
+
+ as.getNestedPath();
+
+ DateRangeAggregation dra = new DateRangeAggregation();
+ dra.setField("field-1");
+ dra.setMinThreshold(1);
+ dra.setFormat("format-1");
+ assertThat(dra.getFormat(), is(equalTo("format-1")));
+ DateRange dr = new DateRange();
+ dr.setFromDate("01-12-2017");
+ assertThat(dr.getFromDate(), is(equalTo("01-12-2017")));
+ dr.setToDate("21-12-2017");
+ assertThat(dr.getToDate(), is(equalTo("21-12-2017")));
+ DateRange[] drs = {dr};
+ dra.setDateRanges(drs);
+ Assert.assertTrue(dra.getDateRanges().length == 1);
+ Assert.assertNotNull(dra.toElasticSearch());
+ Assert.assertNotNull(dra.toString());
+ as.setDateRange(dra);
+ as.toString();
+
+ as.getNestedPath();
+
+ GroupByAggregation gba = new GroupByAggregation();
+ gba.setField("field-1");
+ gba.setMinThreshold(1);
+ Assert.assertNotNull(gba.toElasticSearch());
+ Assert.assertNotNull(gba.toString());
+ as.setGroupBy(gba);
+ Assert.assertNotNull(as.toString());
+
+ a.setStatement(as);
+ Assert.assertNotNull(a.toString());
+ return a;
+ }
+}