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=========================================================
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;
26 import com.google.common.io.Files;
28 import java.io.IOException;
29 import java.nio.charset.StandardCharsets;
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
34 import org.onap.ccsdk.features.sdnr.wt.devicemanager.aaiconnector.impl.config.AaiConfig;
35 import org.onap.ccsdk.features.sdnr.wt.devicemanager.archiveservice.ArchiveCleanService;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.config.DcaeConfig;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.config.PmConfig;
38 import org.onap.ccsdk.features.sdnr.wt.devicemanager.toggleAlarmFilter.conf.ToggleAlarmConfig;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 public class TestDevMgrPropertiesFile {
44 private static final Logger LOG = LoggerFactory.getLogger(ArchiveCleanService.class);
46 private static final File FILENAME = new File("testdevmgrpropertiesfile.properties");
47 private static final File AAIPROP_FILE = new File("testdevmgrpropertiesfileaaiclient.properties");
48 private int hasChanged;
57 public void deinit() {
62 public void testBasicConfiguration() {
64 writeFile(FILENAME, this.getContent1());
65 writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
67 LOG.info("Read and verify");
68 ConfigurationFileRepresentation cfg2 = new ConfigurationFileRepresentation(FILENAME.getPath());
70 AaiConfig aaiConfig = new AaiConfig(cfg2);
71 assertNotNull(aaiConfig);
72 DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
73 assertNotNull(dcaeConfig);
74 PmConfig pmConfig = new PmConfig(cfg2);
75 assertNotNull(pmConfig);
76 ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
77 assertNotNull(toggleAlarmConfig);
79 LOG.info("Verify {} ", aaiConfig);
82 //-- Observer not working with all testcases, because config does not support different file types.
84 public void testChangeConfiguration() {
86 LOG.info("Read and verify");
88 writeFile(FILENAME, this.getContent1());
89 writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
91 ConfigurationFileRepresentation cfg2 = new ConfigurationFileRepresentation(FILENAME.getPath());
93 cfg2.registerConfigChangedListener(() -> {
95 LOG.info("file changed listener triggered: {}", hasChanged);
98 AaiConfig aaiConfig = new AaiConfig(cfg2);
99 assertNotNull(aaiConfig);
100 DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
101 assertNotNull(dcaeConfig);
102 PmConfig pmConfig = new PmConfig(cfg2);
103 assertNotNull(pmConfig);
104 ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
105 assertNotNull(toggleAlarmConfig);
107 LOG.info("Write new content. Changes {}", hasChanged);
108 writeFile(FILENAME, this.getContent2());
111 while (hasChanged == 0 && i-- > 0) {
112 LOG.info("Wait for Change indication.");
115 LOG.info("Changes {}", hasChanged);
117 assertTrue("fileChanged counter " + hasChanged, hasChanged > 0);
118 LOG.info("Test done");
123 private static void sleep(int milliseconds) {
125 Thread.sleep(milliseconds);
126 } catch (InterruptedException e) {
127 Thread.currentThread().interrupt();
131 public static void writeFile(File f, String content) {
133 Files.asCharSink(f, StandardCharsets.UTF_8).write(content);
134 } catch (IOException e) {
135 fail(e.getMessage());
140 private void delete(File f) {
147 private String getContent2() {
150 "dcaeUserCredentials=admin:admin\n" +
151 "dcaeUrl=http://localhost:45451/abc\n" +
152 "dcaeHeartbeatPeriodSeconds=120\n" +
153 "dcaeTestCollector=no\n" +
156 "userPassword=passwd\n" +
158 "soapaddtimeout=10\n" +
159 "soapinqtimeout=20\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" +
173 "#smtpReceivers=\n" +
176 "esCluster=sendateodl5\n" +
180 "aaiHeaders=[\"X-TransactionId: 9999\"]\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" +
193 "pmCluster=sendateodl5\n" +
195 "[toggleAlarmFilter]\n" +
202 private String getContent1() {
205 "dcaeUserCredentials=admin:admin\n" +
206 "dcaeUrl=http://localhost:45/abc\n" +
207 "dcaeHeartbeatPeriodSeconds=120\n" +
208 "dcaeTestCollector=no\n" +
211 "userPassword=passwd\n" +
213 "soapaddtimeout=10\n" +
214 "soapinqtimeout=20\n" +
216 "inqtemplate=inqreq.tmpl.xml\n" +
217 "assignedto=userid\n" +
218 "addtemplate=addreq.tmpl.xml\n" +
219 "severitypassthrough=critical,major,minor,warning\n" +
220 "systemuser=user\n" +
221 "prt-offset=1200\n" +
228 "#smtpReceivers=\n" +
231 "esCluster=sendateodl5\n" +
235 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
237 "aaiUserCredentials=AAI:AAI\n" +
238 "aaiDeleteOnMountpointRemove=true\n" +
239 "aaiTrustAllCerts=false\n" +
240 "aaiApiVersion=aai/v13\n" +
241 "aaiPropertiesFile=aaiclient.properties\n" +
244 "pmCluster=sendateodl5\n" +
246 "[toggleAlarmFilter]\n" +
247 "taEnabled=false\n" +
253 private String getAaiPropertiesConfig() {
255 return "org.onap.ccsdk.sli.adaptors.aai.ssl.key=keykey\"\"\n" +
256 "org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd=psswdpsswd\"\"\n" +
257 "org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=\"false\"\n" +
258 "org.onap.ccsdk.sli.adaptors.aai.application=appxyz\"\"\n" +
259 "org.onap.ccsdk.sli.adaptors.aai.uri=uriu\"\"\n" +
260 "connection.timeout=60000\n" +
261 "read.timeout=60000";