2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.sa.searchdbabstraction.searchapi;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import java.io.IOException;
25 import org.junit.Assert;
26 import org.junit.Test;
28 public class TermQueryTest {
31 public void testAllMethods() throws IOException {
32 String field = "searchTags.nested";
33 String stringValue = "theValue.nested";
34 String termQueryWithStringValueJson = "{\"field\": \"" + field + "\", \"value\": \"" + stringValue + "\"}";
36 ObjectMapper mapper = new ObjectMapper();
37 TermQuery stringTermQuery = mapper.readValue(termQueryWithStringValueJson, TermQuery.class);
38 Assert.assertEquals(stringValue, stringTermQuery.getValue());
39 Assert.assertEquals("searchTags.nested", stringTermQuery.getField());
40 stringTermQuery.setOperator("operator-1");
41 Assert.assertEquals("operator-1", stringTermQuery.getOperator());
42 stringTermQuery.setSearchAnalyzer("search-1");
43 Assert.assertEquals("search-1", stringTermQuery.getSearchAnalyzer());
45 String field1 = "searchTags-1 searchTags.second";
46 String stringValue1 = "theValue-1 theValue.second";
47 String multiFieldTermQueryJSon = "{\"field\": \"" + field1 + "\", \"value\": \"" + stringValue1 + "\"}";
48 TermQuery multiFieldTermQuery = mapper.readValue(multiFieldTermQueryJSon, TermQuery.class);
49 multiFieldTermQuery.setOperator("and");
50 multiFieldTermQuery.setSearchAnalyzer("search-1");
51 Assert.assertNotNull(multiFieldTermQuery.toElasticSearch());
52 Assert.assertNotNull(multiFieldTermQuery.pathForNestedField(field1));
54 String field2 = "search11 search2";
55 String stringValue2 = "theValue1 theValue2";
56 String multiFieldTermJSon = "{\"field\": \"" + field2 + "\", \"value\": \"" + stringValue2 + "\"}";
57 TermQuery multiFieldTerm = mapper.readValue(multiFieldTermJSon, TermQuery.class);
58 multiFieldTerm.setOperator("or");
59 multiFieldTerm.setSearchAnalyzer("search-1");
60 Assert.assertNotNull(multiFieldTerm.toElasticSearch());