6f9fde998bd9f7970a307240c04c2a0ea8f3be93
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / dal / elasticsearch / ElasticSearchConfigTest.java
1 /**\r
2  * ============LICENSE_START===================================================\r
3  * SPARKY (AAI UI service)\r
4  * ============================================================================\r
5  * Copyright © 2017 AT&T Intellectual Property.\r
6  * Copyright © 2017 Amdocs\r
7  * All rights reserved.\r
8  * ============================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  *\r
13  *      http://www.apache.org/licenses/LICENSE-2.0\r
14  *\r
15  * Unless required by applicable law or agreed to in writing, software\r
16  * distributed under the License is distributed on an "AS IS" BASIS,\r
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18  * See the License for the specific language governing permissions and\r
19  * limitations under the License.\r
20  * ============LICENSE_END=====================================================\r
21  *\r
22  * ECOMP and OpenECOMP are trademarks\r
23  * and service marks of AT&T Intellectual Property.\r
24  */\r
25 \r
26 package org.onap.aai.sparky.dal.elasticsearch;\r
27 \r
28 import static org.junit.Assert.assertEquals;\r
29 import static org.junit.Assert.assertNotEquals;\r
30 \r
31 import java.io.File;\r
32 import java.io.IOException;\r
33 \r
34 import javax.servlet.ServletException;\r
35 \r
36 import org.junit.Before;\r
37 import org.junit.Ignore;\r
38 import org.junit.Test;\r
39 import org.mockito.Mockito;\r
40 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;\r
41 import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;\r
42 \r
43 /**\r
44  * The Class ElasticSearchConfigTest.\r
45  */\r
46 public class ElasticSearchConfigTest {\r
47 \r
48   private static final String GOOD_MAPPINGS_FILE =\r
49       "{" + "\"properties\": {" + "\"entityType\": {" + "\"type\": \"string\"" + "},"\r
50           + "\"edgeTagQueryEntityFieldName\": {" + "\"type\": \"string\"," + "\"index\": \"no\""\r
51           + "}," + "\"edgeTagQueryEntityFieldValue\": {" + "\"type\": \"string\","\r
52           + "\"index\": \"no\"" + "}," + "\"searchTagIDs\" : {" + "\"type\" : \"string\"" + "},"\r
53           + "\"searchTags\": {" + "\"type\": \"string\"," + "\"analyzer\": \"nGram_analyzer\","\r
54           + "\"search_analyzer\": \"whitespace_analyzer\"}" + "}" + "}";\r
55 \r
56   private static final String GOOD_SETTINGS_FILE = "{\"analysis\": {" + "\"filter\": {"\r
57       + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50,"\r
58       + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\""\r
59       + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\","\r
60       + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\","\r
61       + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\","\r
62       + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\","\r
63       + "\"asciifolding\"]}}}}";\r
64 \r
65   private static final String BAD_SETTINGS_FILE = "{\"analysis\": {" + "\"filter\": {"\r
66       + "\"nGram_filter\": {" + "\"type\": \"nGram\"," + "\"min_gram\": 1," + "\"max_gram\": 50,"\r
67       + "\"token_chars\": [" + "\"letter\"," + "\"digit\"," + "\"punctuation\"," + "\"symbol\""\r
68       + "]}}," + "\"analyzer\": {" + "\"nGram_analyzer\": {" + "\"type\": \"custom\","\r
69       + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\"," + "\"asciifolding\","\r
70       + "\"nGram_filter\"]}," + "\"whitespace_analyzer\": {" + "\"type\": \"custom\","\r
71       + "\"tokenizer\": \"whitespace\"," + "\"filter\": [" + "\"lowercase\","\r
72       + "\"asciifolding\"]}}";\r
73 \r
74   /**\r
75    * Inits the.\r
76    *\r
77    * @throws Exception the exception\r
78    */\r
79   @Before\r
80   public void init() throws Exception {}\r
81 \r
82   /**\r
83    * Validate accessors.\r
84    *\r
85    * @throws IOException Signals that an I/O exception has occurred.\r
86    * @throws ServletException the servlet exception\r
87    * @throws Exception the exception\r
88    */\r
89   @Test\r
90   public void validateAccessors() throws IOException, ServletException, Exception {\r
91 \r
92     ElasticSearchConfig esConfig = new ElasticSearchConfig();\r
93 \r
94     esConfig.setIpAddress("47.248.10.127");\r
95     esConfig.setHttpPort("8123");\r
96     esConfig.setJavaApiPort("9123");\r
97     esConfig.setIndexName("myIndexName");\r
98     esConfig.setType("myIndexTableType");\r
99     esConfig.setClusterName("ES_AAI_DEV");\r
100     esConfig.setMappingsFileName("d:\\1\\mappings.json");\r
101     esConfig.setSettingsFileName("d:\\1\\settings.json");\r
102 \r
103     ElasticSearchConfig.setConfig(esConfig);\r
104 \r
105     assertEquals(esConfig.getIpAddress(), "47.248.10.127");\r
106     assertEquals(esConfig.getHttpPort(), "8123");\r
107     assertEquals(esConfig.getJavaApiPort(), "9123");\r
108     assertEquals(esConfig.getIndexName(), "myIndexName");\r
109     assertEquals(esConfig.getType(), "myIndexTableType");\r
110     assertEquals(esConfig.getClusterName(), "ES_AAI_DEV");\r
111     assertEquals(esConfig.getMappingsFileName(), "d:\\1\\mappings.json");\r
112     assertEquals(esConfig.getSettingsFileName(), "d:\\1\\settings.json");\r
113 \r
114     String output = esConfig.toString();\r
115 \r
116     assertNotEquals(output, null);\r
117 \r
118   }\r
119 }\r