2 * ============LICENSE_START=======================================================
\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
12 * http://www.apache.org/licenses/LICENSE-2.0
\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
21 package org.onap.aai.sa.searchdbabstraction.searchapi;
\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
28 public class TermQueryTest {
\r
31 public void testAllMethods() throws IOException {
\r
33 String field = "searchTags.nested";
\r
34 String stringValue = "theValue.nested";
\r
35 String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}";
\r
36 String termQueryWithStringValueExpectedES = "{\"term\": {\"" + field + "\" : \"" + stringValue + "\"}}";
\r
38 ObjectMapper mapper = new ObjectMapper();
\r
39 TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class);
\r
40 Assert.assertEquals(stringValue, stringTermQuery.getValue());
\r
41 Assert.assertEquals("searchTags.nested", stringTermQuery.getField());
\r
42 stringTermQuery.setOperator("operator-1");
\r
43 Assert.assertEquals("operator-1", stringTermQuery.getOperator());
\r
44 stringTermQuery.setSearchAnalyzer("search-1");
\r
45 Assert.assertEquals("search-1", stringTermQuery.getSearchAnalyzer());
\r
47 String field1 = "searchTags-1 searchTags.second";
\r
48 String stringValue1 = "theValue-1 theValue.second";
\r
49 String multiFieldTermQueryJSon = "{\"field\": \"" + field1 + "\", \"value\": \"" + stringValue1 + "\"}";
\r
50 TermQuery multiFieldTermQuery = mapper.readValue(multiFieldTermQueryJSon, TermQuery.class);
\r
51 multiFieldTermQuery.setOperator("and");
\r
52 multiFieldTermQuery.setSearchAnalyzer("search-1");
\r
53 Assert.assertNotNull(multiFieldTermQuery.toElasticSearch());
\r
54 Assert.assertNotNull(multiFieldTermQuery.pathForNestedField(field1));
\r
56 String field2 = "search11 search2";
\r
57 String stringValue2 = "theValue1 theValue2";
\r
58 String multiFieldTermJSon = "{\"field\": \"" + field2 + "\", \"value\": \"" + stringValue2 + "\"}";
\r
59 TermQuery multiFieldTerm = mapper.readValue(multiFieldTermJSon, TermQuery.class);
\r
60 multiFieldTerm.setOperator("or");
\r
61 multiFieldTerm.setSearchAnalyzer("search-1");
\r
62 Assert.assertNotNull(multiFieldTerm.toElasticSearch());
\r