5a159133a37d506dd7e737d12546e37f968cdbb4
[aai/search-data-service.git] / src / test / java / org / onap / aai / sa / searchdbabstraction / searchapi / TermQueryTest.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\r
4  * ================================================================================\r
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017-2018 Amdocs\r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *       http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  */\r
21 package org.onap.aai.sa.searchdbabstraction.searchapi;\r
22 \r
23 import com.fasterxml.jackson.databind.ObjectMapper;\r
24 import java.io.IOException;\r
25 import org.junit.Assert;\r
26 import org.junit.Test;\r
27 \r
28 public class TermQueryTest {\r
29 \r
30     @Test\r
31     public void testAllMethods() throws IOException {\r
32         String field = "searchTags.nested";\r
33         String stringValue = "theValue.nested";\r
34         String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}";\r
35 \r
36         ObjectMapper mapper = new ObjectMapper();\r
37         TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class);\r
38         Assert.assertEquals(stringValue, stringTermQuery.getValue());\r
39         Assert.assertEquals("searchTags.nested", stringTermQuery.getField());\r
40         stringTermQuery.setOperator("operator-1");\r
41         Assert.assertEquals("operator-1", stringTermQuery.getOperator());\r
42         stringTermQuery.setSearchAnalyzer("search-1");\r
43         Assert.assertEquals("search-1", stringTermQuery.getSearchAnalyzer());\r
44 \r
45         String field1 = "searchTags-1 searchTags.second";\r
46         String stringValue1 = "theValue-1 theValue.second";\r
47         String multiFieldTermQueryJSon = "{\"field\": \"" + field1 + "\", \"value\": \"" + stringValue1 + "\"}";\r
48         TermQuery multiFieldTermQuery = mapper.readValue(multiFieldTermQueryJSon, TermQuery.class);\r
49         multiFieldTermQuery.setOperator("and");\r
50         multiFieldTermQuery.setSearchAnalyzer("search-1");\r
51         Assert.assertNotNull(multiFieldTermQuery.toElasticSearch());\r
52         Assert.assertNotNull(multiFieldTermQuery.pathForNestedField(field1));\r
53 \r
54         String field2 = "search11 search2";\r
55         String stringValue2 = "theValue1 theValue2";\r
56         String multiFieldTermJSon = "{\"field\": \"" + field2 + "\", \"value\": \"" + stringValue2 + "\"}";\r
57         TermQuery multiFieldTerm = mapper.readValue(multiFieldTermJSon, TermQuery.class);\r
58         multiFieldTerm.setOperator("or");\r
59         multiFieldTerm.setSearchAnalyzer("search-1");\r
60         Assert.assertNotNull(multiFieldTerm.toElasticSearch());\r
61     }\r
62 \r
63 }\r