0a458d80515516cf13bc945a8c167c0aa2392356
[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.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.nio.charset.StandardCharsets;
30
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.config.AaiConfig;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.config.DcaeConfig;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.config.PmConfig;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.conf.ToggleAlarmConfig;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 import com.google.common.io.Files;
44
45 public class TestDevMgrPropertiesFile {
46
47     private static final Logger LOG = LoggerFactory.getLogger(ArchiveCleanService.class);
48
49     private static final File FILENAME = new File("testdevmgrpropertiesfile.properties");
50     private static final File AAIPROP_FILE=new File("testdevmgrpropertiesfileaaiclient.properties");
51     private int hasChanged;
52
53     @Before
54     public void init() {
55         delete(FILENAME);
56         delete(AAIPROP_FILE);
57     }
58     @After
59     public void deinit() {
60         this.init();
61     }
62
63     @Test
64     public void testBasicConfiguration() {
65
66         writeFile(FILENAME, this.getContent1());
67         writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
68
69         LOG.info("Read and verify");
70         ConfigurationFileRepresentation cfg2 = new ConfigurationFileRepresentation(FILENAME.getPath());
71
72         AaiConfig aaiConfig = new AaiConfig(cfg2);
73         assertNotNull(aaiConfig);
74         DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
75         assertNotNull(dcaeConfig);
76         PmConfig pmConfig = new PmConfig(cfg2);
77         assertNotNull(pmConfig);
78         ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
79         assertNotNull(toggleAlarmConfig);
80
81         LOG.info("Verify {} ", aaiConfig);
82     }
83
84     //-- Observer not working with all testcases, because config does not support different file types.
85     @Test
86     public void testChangeConfiguration() {
87
88         LOG.info("Read and verify");
89
90         writeFile(FILENAME, this.getContent1());
91         writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
92
93         ConfigurationFileRepresentation cfg2 = new ConfigurationFileRepresentation(FILENAME.getPath());
94         hasChanged = 0;
95         cfg2.registerConfigChangedListener(() -> {
96             hasChanged++;
97             LOG.info("file changed listener triggered: {}",hasChanged);
98         });
99
100         AaiConfig aaiConfig = new AaiConfig(cfg2);
101         assertNotNull(aaiConfig);
102         DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
103         assertNotNull(dcaeConfig);
104         PmConfig pmConfig = new PmConfig(cfg2);
105         assertNotNull(pmConfig);
106         ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
107         assertNotNull(toggleAlarmConfig);
108
109         LOG.info("Write new content. Changes {}",hasChanged);
110         writeFile(FILENAME, this.getContent2());
111
112         int i=10;
113         while(hasChanged == 0 && i-- > 0) {
114             LOG.info("Wait for Change indication.");
115             sleep(1000);
116         }
117         LOG.info("Changes {}",hasChanged);
118
119         assertTrue("fileChanged counter "+hasChanged, hasChanged > 0);
120         LOG.info("Test done");
121
122     }
123
124
125     private static void sleep(int milliseconds) {
126         try {
127             Thread.sleep(milliseconds);
128         } catch (InterruptedException e) {
129         }
130     }
131
132     public static void writeFile(File f, String content) {
133          try {
134             Files.asCharSink(f, StandardCharsets.UTF_8).write(content);
135         } catch (IOException e) {
136             fail(e.getMessage());
137         };
138         sleep(500);
139     }
140
141     private void delete(File f) {
142         if(f.exists()) {
143             f.delete();
144         }
145     }
146
147
148     private String getContent2() {
149         return "[dcae]\n" +
150                 "dcaeUserCredentials=admin:admin\n" +
151                 "dcaeUrl=http://localhost:45451/abc\n" +
152                 "dcaeHeartbeatPeriodSeconds=120\n" +
153                 "dcaeTestCollector=no\n" +
154                 "\n" +
155                 "[aots]\n" +
156                 "userPassword=passwd\n" +
157                 "soapurladd=off\n" +
158                 "soapaddtimeout=10\n" +
159                 "soapinqtimeout=20\n" +
160                 "userName=user\n" +
161                 "inqtemplate=inqreq.tmpl.xml\n" +
162                 "assignedto=userid\n" +
163                 "addtemplate=addreq.tmpl.xml\n" +
164                 "severitypassthrough=critical,major,minor,warning\n" +
165                 "systemuser=user\n" +
166                 "prt-offset=1200\n" +
167                 "soapurlinq=off\n" +
168                 "#smtpHost=\n" +
169                 "#smtpPort=\n" +
170                 "#smtpUsername=\n" +
171                 "#smtpPassword=\n" +
172                 "#smtpSender=\n" +
173                 "#smtpReceivers=\n" +
174                 "\n" +
175                 "[es]\n" +
176                 "esCluster=sendateodl5\n" +
177                 "\n" +
178                 "[aai]\n" +
179                 "#keep comment\n" +
180                 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
181                 "aaiUrl=off\n" +
182                 "aaiUserCredentials=AAI:AAI\n" +
183                 "aaiDeleteOnMountpointRemove=true\n" +
184                 "aaiTrustAllCerts=false\n" +
185                 "aaiApiVersion=aai/v13\n" +
186                 "aaiPropertiesFile=aaiclient.properties\n" +
187                 "aaiApplicationId=SDNR\n" +
188                 "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n" +
189                 "aaiPcks12ClientCertPassphrase=adminadmin\n" +
190                 "aaiClientConnectionTimeout=30000\n" +
191                 "\n" +
192                 "[pm]\n" +
193                 "pmCluster=sendateodl5\n" +
194                 "pmEnabled=true\n" +
195                 "[toggleAlarmFilter]\n" +
196                 "taEnabled=true\n" +
197                 "taDelay=5555\n" +
198                 "";
199     }
200
201     private String getContent1() {
202         return "[dcae]\n" +
203                 "dcaeUserCredentials=admin:admin\n" +
204                 "dcaeUrl=http://localhost:45/abc\n" +
205                 "dcaeHeartbeatPeriodSeconds=120\n" +
206                 "dcaeTestCollector=no\n" +
207                 "\n" +
208                 "[aots]\n" +
209                 "userPassword=passwd\n" +
210                 "soapurladd=off\n" +
211                 "soapaddtimeout=10\n" +
212                 "soapinqtimeout=20\n" +
213                 "userName=user\n" +
214                 "inqtemplate=inqreq.tmpl.xml\n" +
215                 "assignedto=userid\n" +
216                 "addtemplate=addreq.tmpl.xml\n" +
217                 "severitypassthrough=critical,major,minor,warning\n" +
218                 "systemuser=user\n" +
219                 "prt-offset=1200\n" +
220                 "soapurlinq=off\n" +
221                 "#smtpHost=\n" +
222                 "#smtpPort=\n" +
223                 "#smtpUsername=\n" +
224                 "#smtpPassword=\n" +
225                 "#smtpSender=\n" +
226                 "#smtpReceivers=\n" +
227                 "\n" +
228                 "[es]\n" +
229                 "esCluster=sendateodl5\n" +
230                 "\n" +
231                 "[aai]\n" +
232                 "#keep comment\n" +
233                 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
234                 "aaiUrl=off\n" +
235                 "aaiUserCredentials=AAI:AAI\n" +
236                 "aaiDeleteOnMountpointRemove=true\n" +
237                 "aaiTrustAllCerts=false\n" +
238                 "aaiApiVersion=aai/v13\n" +
239                 "aaiPropertiesFile=aaiclient.properties\n" +
240                 "\n" +
241                 "[pm]\n" +
242                 "pmCluster=sendateodl5\n" +
243                 "pmEnabled=true\n" +
244                 "[toggleAlarmFilter]\n" +
245                 "taEnabled=false\n" +
246                 "taDelay=5555\n" +
247                 "";
248     }
249     private String getAaiPropertiesConfig() {
250         return "org.onap.ccsdk.sli.adaptors.aai.ssl.key=keykey\"\"\n" +
251                 "org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd=psswdpsswd\"\"\n" +
252                 "org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=\"false\"\n" +
253                 "org.onap.ccsdk.sli.adaptors.aai.application=appxyz\"\"\n" +
254                 "org.onap.ccsdk.sli.adaptors.aai.uri=uriu\"\"\n" +
255                 "connection.timeout=60000\n" +
256                 "read.timeout=60000";
257     }
258
259 }