3a6655d601f9bb392614b29ac9387a35f2d94a5b
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk feature sdnr wt
4  *  ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  ******************************************************************************/
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
22
23 import static org.junit.Assert.*;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28
29 import org.junit.After;
30 import org.junit.Before;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.HtDevicemanagerConfiguration;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.AaiConfig;
33 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.DcaeConfig;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.EsConfig;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.PmConfig;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.ToggleAlarmConfig;
37
38 import com.google.common.io.Files;
39
40 public class TestDevMgrPropertiesFile {
41
42     private static final String FILENAME = "test.properties";
43     private static final String AAIPROP_FILE="aaiclient.properties";
44     protected boolean hasChanged;
45
46     @Before
47     public void init() {
48         File f=new File(FILENAME);
49         if(f.exists()) {
50             f.delete();
51         }
52         f=new File(AAIPROP_FILE);
53         if(f.exists()) {
54             f.delete();
55         }
56     }
57     @After
58     public void deinit() {
59         this.init();
60     }
61
62     //@Test
63     public void test() {
64         File f=new File(FILENAME);
65         hasChanged=false;
66         try {
67             Files.asCharSink(f, StandardCharsets.UTF_8).write(this.getContent1());
68         } catch (IOException e) {
69             fail(e.getMessage());
70         };
71         f=new File(AAIPROP_FILE);
72         try {
73             Files.asCharSink(f, StandardCharsets.UTF_8).write(this.getAaiPropertiesConfig());
74         } catch (IOException e) {
75             fail(e.getMessage());
76         };
77         HtDevicemanagerConfiguration cfg=HtDevicemanagerConfiguration.getTestConfiguration(FILENAME);
78         assertNotNull(cfg.getAai());
79         assertNotNull(cfg.getDcae());
80         assertNotNull(cfg.getPm());
81         assertNotNull(cfg.getEs());
82         assertNotNull(cfg.getToggleAlarm());
83         assertTrue(AaiConfig.isInstantiated());
84         assertTrue(DcaeConfig.isInstantiated());
85         assertTrue(PmConfig.isInstantiated());
86         assertTrue(EsConfig.isInstantiated());
87         assertTrue(ToggleAlarmConfig.isInstantiated());
88
89
90         assertFalse(cfg.getAai().equals(AaiConfig.getDefaultConfiguration()));
91         assertFalse(cfg.getDcae().equals(DcaeConfig.getDefaultConfiguration()));
92         assertFalse(cfg.getPm().equals(PmConfig.getDefaultConfiguration()));
93         assertFalse(cfg.getEs().equals(EsConfig.getDefaultConfiguration()));
94         assertFalse(cfg.getToggleAlarm().equals(ToggleAlarmConfig.getDefaultConfiguration()));
95         System.out.println(cfg.getAai().toString());
96         System.out.println(cfg.getDcae().toString());
97         System.out.println(cfg.getPm().toString());
98         System.out.println(cfg.getEs().toString());
99         System.out.println(cfg.getToggleAlarm().toString());
100         cfg.registerConfigChangedListener(() -> {
101             hasChanged=true;
102             System.out.println("file changed listener triggered");
103             AaiConfig.reload();
104             DcaeConfig.reload();
105             PmConfig.reload();
106             EsConfig.reload();
107             ToggleAlarmConfig.reload();
108
109         });
110         try {
111             Files.asCharSink(f, StandardCharsets.UTF_8).write(this.getContent2());
112         } catch (IOException e) {
113             fail(e.getMessage());
114         };
115         int i=0;
116         while(!hasChanged && i++<10) {
117             try {
118                 Thread.sleep(2000);
119             } catch (InterruptedException e) {
120             }
121
122         }
123         assertTrue("fileChanged not covered",hasChanged);
124         assertFalse(cfg.getAai().hashCode()==AaiConfig.getDefaultConfiguration().hashCode());
125         assertFalse(cfg.getDcae().hashCode()==DcaeConfig.getDefaultConfiguration().hashCode());
126         assertFalse(cfg.getPm().hashCode()==PmConfig.getDefaultConfiguration().hashCode());
127         assertFalse(cfg.getEs().hashCode()==EsConfig.getDefaultConfiguration().hashCode());
128         assertFalse(cfg.getToggleAlarm().hashCode()==ToggleAlarmConfig.getDefaultConfiguration().hashCode());
129
130         HtDevicemanagerConfiguration.clear();
131
132
133     }
134     private CharSequence getContent2() {
135         return "[dcae]\n" +
136                 "dcaeUserCredentials=admin:admin\n" +
137                 "dcaeUrl=http://localhost:45451/abc\n" +
138                 "dcaeHeartbeatPeriodSeconds=120\n" +
139                 "dcaeTestCollector=no\n" +
140                 "\n" +
141                 "[aots]\n" +
142                 "userPassword=passwd\n" +
143                 "soapurladd=off\n" +
144                 "soapaddtimeout=10\n" +
145                 "soapinqtimeout=20\n" +
146                 "userName=user\n" +
147                 "inqtemplate=inqreq.tmpl.xml\n" +
148                 "assignedto=userid\n" +
149                 "addtemplate=addreq.tmpl.xml\n" +
150                 "severitypassthrough=critical,major,minor,warning\n" +
151                 "systemuser=user\n" +
152                 "prt-offset=1200\n" +
153                 "soapurlinq=off\n" +
154                 "#smtpHost=\n" +
155                 "#smtpPort=\n" +
156                 "#smtpUsername=\n" +
157                 "#smtpPassword=\n" +
158                 "#smtpSender=\n" +
159                 "#smtpReceivers=\n" +
160                 "\n" +
161                 "[es]\n" +
162                 "esCluster=sendateodl5\n" +
163                 "\n" +
164                 "[aai]\n" +
165                 "#keep comment\n" +
166                 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
167                 "aaiUrl=off\n" +
168                 "aaiUserCredentials=AAI:AAI\n" +
169                 "aaiDeleteOnMountpointRemove=true\n" +
170                 "aaiTrustAllCerts=false\n" +
171                 "aaiApiVersion=aai/v13\n" +
172                 "aaiPropertiesFile=aaiclient.properties\n" +
173                 "aaiApplicationId=SDNR\n" +
174                 "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n" +
175                 "aaiPcks12ClientCertPassphrase=adminadmin\n" +
176                 "aaiClientConnectionTimeout=30000\n" +
177                 "\n" +
178                 "[pm]\n" +
179                 "pmCluster=sendateodl5\n" +
180                 "pmEnabled=true\n" +
181                 "[toggleAlarmFilter]\n" +
182                 "taEnabled=true\n" +
183                 "taDelay=5555\n" +
184                 "";
185     }
186
187     private String getContent1() {
188         return "[dcae]\n" +
189                 "dcaeUserCredentials=admin:admin\n" +
190                 "dcaeUrl=http://localhost:45/abc\n" +
191                 "dcaeHeartbeatPeriodSeconds=120\n" +
192                 "dcaeTestCollector=no\n" +
193                 "\n" +
194                 "[aots]\n" +
195                 "userPassword=passwd\n" +
196                 "soapurladd=off\n" +
197                 "soapaddtimeout=10\n" +
198                 "soapinqtimeout=20\n" +
199                 "userName=user\n" +
200                 "inqtemplate=inqreq.tmpl.xml\n" +
201                 "assignedto=userid\n" +
202                 "addtemplate=addreq.tmpl.xml\n" +
203                 "severitypassthrough=critical,major,minor,warning\n" +
204                 "systemuser=user\n" +
205                 "prt-offset=1200\n" +
206                 "soapurlinq=off\n" +
207                 "#smtpHost=\n" +
208                 "#smtpPort=\n" +
209                 "#smtpUsername=\n" +
210                 "#smtpPassword=\n" +
211                 "#smtpSender=\n" +
212                 "#smtpReceivers=\n" +
213                 "\n" +
214                 "[es]\n" +
215                 "esCluster=sendateodl5\n" +
216                 "\n" +
217                 "[aai]\n" +
218                 "#keep comment\n" +
219                 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
220                 "aaiUrl=off\n" +
221                 "aaiUserCredentials=AAI:AAI\n" +
222                 "aaiDeleteOnMountpointRemove=true\n" +
223                 "aaiTrustAllCerts=false\n" +
224                 "aaiApiVersion=aai/v13\n" +
225                 "aaiPropertiesFile=aaiclient.properties\n" +
226                 "\n" +
227                 "[pm]\n" +
228                 "pmCluster=sendateodl5\n" +
229                 "pmEnabled=true\n" +
230                 "[toggleAlarmFilter]\n" +
231                 "taEnabled=false\n" +
232                 "taDelay=5555\n" +
233                 "";
234     }
235     private String getAaiPropertiesConfig() {
236         return "org.onap.ccsdk.sli.adaptors.aai.ssl.key=\"\"\n" +
237                 "org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd=\"\"\n" +
238                 "org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=\"false\"\n" +
239                 "org.onap.ccsdk.sli.adaptors.aai.application=\"\"\n" +
240                 "org.onap.ccsdk.sli.adaptors.aai.uri=\"\"\n" +
241                 "connection.timeout=60000\n" +
242                 "read.timeout=60000";
243     }
244
245 }