1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk feature sdnr wt
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
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=========================================================
20 ******************************************************************************/
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
28 import java.io.IOException;
29 import java.nio.charset.StandardCharsets;
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.database.config.EsConfig;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.config.AaiConfig;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.config.DcaeConfig;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.config.PmConfig;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.conf.ToggleAlarmConfig;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 import com.google.common.io.Files;
46 public class TestDevMgrPropertiesFile {
48 private static final Logger LOG = LoggerFactory.getLogger(ArchiveCleanService.class);
50 private static final File FILENAME = new File("test.properties");
51 private static final File AAIPROP_FILE=new File("aaiclient.properties");
52 private int hasChanged;
56 //if (! LOG.isDebugEnabled()) {
62 public void deinit() {
69 writeFile(FILENAME, this.getContent1());
70 writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
72 System.out.println("Read and verify");
73 ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(FILENAME.getPath());
74 ConfigurationFileRepresentation cfg2 = cfg;
76 AaiConfig aaiConfig = new AaiConfig(cfg2);
77 assertNotNull(aaiConfig);
78 DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
79 assertNotNull(dcaeConfig);
80 PmConfig pmConfig = new PmConfig(cfg2);
81 assertNotNull(pmConfig);
82 EsConfig esConfig = new EsConfig(cfg2);
83 assertNotNull(esConfig);
84 ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
85 assertNotNull(toggleAlarmConfig);
87 System.out.println("Verify\n"+aaiConfig+"\n");
88 @SuppressWarnings("unused")
91 res = cfg.getAai().equals(AaiConfig.getDefaultConfiguration());
92 res = cfg.getDcae().equals(DcaeConfig.getDefaultConfiguration());
93 res = cfg.getPm().equals(PmConfig.getDefaultConfiguration());
94 res = cfg.getEs().equals(EsConfig.getDefaultConfiguration());
95 res = cfg.getToggleAlarm().equals(ToggleAlarmConfig.getDefaultConfiguration());
97 res = cfg.getAai().hashCode() == AaiConfig.getDefaultConfiguration().hashCode();
98 res = cfg.getDcae().hashCode() == DcaeConfig.getDefaultConfiguration().hashCode();
99 res = cfg.getPm().hashCode() == PmConfig.getDefaultConfiguration().hashCode();
100 res = cfg.getEs().hashCode() == EsConfig.getDefaultConfiguration().hashCode();
101 res = cfg.getToggleAlarm().hashCode() == ToggleAlarmConfig.getDefaultConfiguration().hashCode();
105 //-- Observer not working with all testcases, because config does not support different file types.
107 public void test2() {
110 writeFile(FILENAME, this.getContent1());
111 writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
113 System.out.println("Read and verify");
114 ConfigurationFileRepresentation cfg2 = new ConfigurationFileRepresentation(FILENAME.getPath());
116 AaiConfig aaiConfig = new AaiConfig(cfg2);
117 assertNotNull(aaiConfig);
118 DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
119 assertNotNull(dcaeConfig);
120 PmConfig pmConfig = new PmConfig(cfg2);
121 assertNotNull(pmConfig);
122 EsConfig esConfig = new EsConfig(cfg2);
123 assertNotNull(esConfig);
124 ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
125 assertNotNull(toggleAlarmConfig);
127 cfg2.registerConfigChangedListener(() -> {
129 System.out.println("file changed listener triggered: "+hasChanged);
133 System.out.println("Write new content. Changes "+hasChanged);
134 writeFile(FILENAME, this.getContent2());
138 while(hasChanged == 0 && i-- > 0) {
139 System.out.println("Wait for Change indication.");
142 System.out.println("Changes "+hasChanged);
144 assertTrue("fileChanged counter"+hasChanged, hasChanged > 0);
145 System.out.println("Test done");
150 private static void sleep(int milliseconds) {
152 Thread.sleep(milliseconds);
153 } catch (InterruptedException e) {
157 public static void writeFile(File f, String content) {
159 Files.asCharSink(f, StandardCharsets.UTF_8).write(content);
160 } catch (IOException e) {
161 fail(e.getMessage());
166 private void delete(File f) {
173 private String getContent2() {
175 "dcaeUserCredentials=admin:admin\n" +
176 "dcaeUrl=http://localhost:45451/abc\n" +
177 "dcaeHeartbeatPeriodSeconds=120\n" +
178 "dcaeTestCollector=no\n" +
181 "userPassword=passwd\n" +
183 "soapaddtimeout=10\n" +
184 "soapinqtimeout=20\n" +
186 "inqtemplate=inqreq.tmpl.xml\n" +
187 "assignedto=userid\n" +
188 "addtemplate=addreq.tmpl.xml\n" +
189 "severitypassthrough=critical,major,minor,warning\n" +
190 "systemuser=user\n" +
191 "prt-offset=1200\n" +
198 "#smtpReceivers=\n" +
201 "esCluster=sendateodl5\n" +
205 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
207 "aaiUserCredentials=AAI:AAI\n" +
208 "aaiDeleteOnMountpointRemove=true\n" +
209 "aaiTrustAllCerts=false\n" +
210 "aaiApiVersion=aai/v13\n" +
211 "aaiPropertiesFile=aaiclient.properties\n" +
212 "aaiApplicationId=SDNR\n" +
213 "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n" +
214 "aaiPcks12ClientCertPassphrase=adminadmin\n" +
215 "aaiClientConnectionTimeout=30000\n" +
218 "pmCluster=sendateodl5\n" +
220 "[toggleAlarmFilter]\n" +
226 private String getContent1() {
228 "dcaeUserCredentials=admin:admin\n" +
229 "dcaeUrl=http://localhost:45/abc\n" +
230 "dcaeHeartbeatPeriodSeconds=120\n" +
231 "dcaeTestCollector=no\n" +
234 "userPassword=passwd\n" +
236 "soapaddtimeout=10\n" +
237 "soapinqtimeout=20\n" +
239 "inqtemplate=inqreq.tmpl.xml\n" +
240 "assignedto=userid\n" +
241 "addtemplate=addreq.tmpl.xml\n" +
242 "severitypassthrough=critical,major,minor,warning\n" +
243 "systemuser=user\n" +
244 "prt-offset=1200\n" +
251 "#smtpReceivers=\n" +
254 "esCluster=sendateodl5\n" +
258 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
260 "aaiUserCredentials=AAI:AAI\n" +
261 "aaiDeleteOnMountpointRemove=true\n" +
262 "aaiTrustAllCerts=false\n" +
263 "aaiApiVersion=aai/v13\n" +
264 "aaiPropertiesFile=aaiclient.properties\n" +
267 "pmCluster=sendateodl5\n" +
269 "[toggleAlarmFilter]\n" +
270 "taEnabled=false\n" +
274 private String getAaiPropertiesConfig() {
275 return "org.onap.ccsdk.sli.adaptors.aai.ssl.key=keykey\"\"\n" +
276 "org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd=psswdpsswd\"\"\n" +
277 "org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=\"false\"\n" +
278 "org.onap.ccsdk.sli.adaptors.aai.application=appxyz\"\"\n" +
279 "org.onap.ccsdk.sli.adaptors.aai.uri=uriu\"\"\n" +
280 "connection.timeout=60000\n" +
281 "read.timeout=60000";