Update the dependencies to use project version
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / synchronizer / AggregationSuggestionSynchronizerTest.java
1 /**\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\r
4  * ================================================================================\r
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  */\r
23 package org.onap.aai.sparky.synchronizer;\r
24 \r
25 import java.io.File;\r
26 import java.io.IOException;\r
27 import java.lang.reflect.Field;\r
28 import java.lang.reflect.Modifier;\r
29 \r
30 import org.junit.Assert;\r
31 import org.junit.Before;\r
32 import org.junit.Test;\r
33 import org.onap.aai.sparky.dal.NetworkTransaction;\r
34 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;\r
35 import org.onap.aai.sparky.dal.rest.HttpMethod;\r
36 import org.onap.aai.sparky.dal.rest.OperationResult;\r
37 import org.onap.aai.sparky.synchronizer.enumeration.OperationState;\r
38 import org.onap.aai.sparky.synchronizer.enumeration.SynchronizerState;\r
39 import org.onap.aai.sparky.viewandinspect.config.TierSupportUiConstants;\r
40 \r
41 public class AggregationSuggestionSynchronizerTest {\r
42 \r
43   @Before\r
44   public void init() throws IOException {\r
45     System.setProperty("AJSC_HOME", new File(".").getCanonicalPath().replace('\\', '/'));\r
46     TierSupportUiConstants.DYNAMIC_CONFIG_APP_LOCATION =\r
47         System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/";\r
48     // TierSupportUiConstants.CONFIG_OXM_LOCATION =\r
49     // System.getProperty("AJSC_HOME")+"/bundleconfig-local/oxm/";\r
50   }\r
51 \r
52   @Test\r
53   public void testDoSync() throws Exception {\r
54     ElasticSearchConfig.setConfig(null);\r
55     setFinalStatic();\r
56     AggregationSuggestionSynchronizer ass =\r
57         new AggregationSuggestionSynchronizer("entity-search-index");\r
58     Assert.assertNotNull(ass);\r
59     OperationState state = ass.doSync();\r
60     Assert.assertEquals(OperationState.OK, state);\r
61 \r
62     OperationResult result = new OperationResult();\r
63     result.setResultCode(200);\r
64     result.setResult("result-1");\r
65     result.setNumRequestRetries(1);\r
66     NetworkTransaction ntwTxn = new NetworkTransaction(HttpMethod.GET, "entity-1", result);\r
67     ass.updateElasticSearchCounters(ntwTxn);\r
68 \r
69     SynchronizerState syncState = ass.getState();\r
70     Assert.assertEquals(SynchronizerState.IDLE, syncState);\r
71 \r
72     String statReport = ass.getStatReport(true);\r
73     Assert.assertNotNull(statReport);\r
74     Assert.assertTrue(statReport.contains("Aggregation Suggestion Synchronizer"));\r
75 \r
76     ass.shutdown();\r
77   }\r
78 \r
79   static void setFinalStatic() throws NoSuchFieldException, SecurityException,\r
80       IllegalArgumentException, IllegalAccessException {\r
81     Field configField = ElasticSearchConfig.class.getDeclaredField("CONFIG_FILE");\r
82     configField.setAccessible(true);\r
83 \r
84     Field modifiersField = Field.class.getDeclaredField("modifiers");\r
85     modifiersField.setAccessible(true);\r
86     modifiersField.setInt(configField, configField.getModifiers() & ~Modifier.FINAL);\r
87 \r
88     configField.set(null,\r
89         System.getProperty("AJSC_HOME") + "/src/test/resources/appconfig/elasticsearch.properties");\r
90   }\r
91 }\r