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.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;
43 import com.google.common.io.Files;
45 public class TestDevMgrPropertiesFile {
47 private static final Logger LOG = LoggerFactory.getLogger(ArchiveCleanService.class);
49 private static final File FILENAME = new File("test.properties");
50 private static final File AAIPROP_FILE=new File("aaiclient.properties");
51 private int hasChanged;
55 //if (! LOG.isDebugEnabled()) {
61 public void deinit() {
68 writeFile(FILENAME, this.getContent1());
69 writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
71 System.out.println("Read and verify");
72 ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(FILENAME.getPath());
73 ConfigurationFileRepresentation cfg2 = cfg;
75 AaiConfig aaiConfig = new AaiConfig(cfg2);
76 assertNotNull(aaiConfig);
77 DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
78 assertNotNull(dcaeConfig);
79 PmConfig pmConfig = new PmConfig(cfg2);
80 assertNotNull(pmConfig);
81 ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
82 assertNotNull(toggleAlarmConfig);
84 System.out.println("Verify\n"+aaiConfig+"\n");
85 @SuppressWarnings("unused")
88 res = cfg.getAai().equals(AaiConfig.getDefaultConfiguration());
89 res = cfg.getDcae().equals(DcaeConfig.getDefaultConfiguration());
90 res = cfg.getPm().equals(PmConfig.getDefaultConfiguration());
91 res = cfg.getEs().equals(EsConfig.getDefaultConfiguration());
92 res = cfg.getToggleAlarm().equals(ToggleAlarmConfig.getDefaultConfiguration());
94 res = cfg.getAai().hashCode() == AaiConfig.getDefaultConfiguration().hashCode();
95 res = cfg.getDcae().hashCode() == DcaeConfig.getDefaultConfiguration().hashCode();
96 res = cfg.getPm().hashCode() == PmConfig.getDefaultConfiguration().hashCode();
97 res = cfg.getEs().hashCode() == EsConfig.getDefaultConfiguration().hashCode();
98 res = cfg.getToggleAlarm().hashCode() == ToggleAlarmConfig.getDefaultConfiguration().hashCode();
102 //-- Observer not working with all testcases, because config does not support different file types.
104 public void test2() {
107 writeFile(FILENAME, this.getContent1());
108 writeFile(AAIPROP_FILE, this.getAaiPropertiesConfig());
110 System.out.println("Read and verify");
111 ConfigurationFileRepresentation cfg2 = new ConfigurationFileRepresentation(FILENAME.getPath());
113 AaiConfig aaiConfig = new AaiConfig(cfg2);
114 assertNotNull(aaiConfig);
115 DcaeConfig dcaeConfig = new DcaeConfig(cfg2);
116 assertNotNull(dcaeConfig);
117 PmConfig pmConfig = new PmConfig(cfg2);
118 assertNotNull(pmConfig);
119 ToggleAlarmConfig toggleAlarmConfig = new ToggleAlarmConfig(cfg2);
120 assertNotNull(toggleAlarmConfig);
122 cfg2.registerConfigChangedListener(() -> {
124 System.out.println("file changed listener triggered: "+hasChanged);
128 System.out.println("Write new content. Changes "+hasChanged);
129 writeFile(FILENAME, this.getContent2());
133 while(hasChanged == 0 && i-- > 0) {
134 System.out.println("Wait for Change indication.");
137 System.out.println("Changes "+hasChanged);
139 assertTrue("fileChanged counter"+hasChanged, hasChanged > 0);
140 System.out.println("Test done");
145 private static void sleep(int milliseconds) {
147 Thread.sleep(milliseconds);
148 } catch (InterruptedException e) {
152 public static void writeFile(File f, String content) {
154 Files.asCharSink(f, StandardCharsets.UTF_8).write(content);
155 } catch (IOException e) {
156 fail(e.getMessage());
161 private void delete(File f) {
168 private String getContent2() {
170 "dcaeUserCredentials=admin:admin\n" +
171 "dcaeUrl=http://localhost:45451/abc\n" +
172 "dcaeHeartbeatPeriodSeconds=120\n" +
173 "dcaeTestCollector=no\n" +
176 "userPassword=passwd\n" +
178 "soapaddtimeout=10\n" +
179 "soapinqtimeout=20\n" +
181 "inqtemplate=inqreq.tmpl.xml\n" +
182 "assignedto=userid\n" +
183 "addtemplate=addreq.tmpl.xml\n" +
184 "severitypassthrough=critical,major,minor,warning\n" +
185 "systemuser=user\n" +
186 "prt-offset=1200\n" +
193 "#smtpReceivers=\n" +
196 "esCluster=sendateodl5\n" +
200 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
202 "aaiUserCredentials=AAI:AAI\n" +
203 "aaiDeleteOnMountpointRemove=true\n" +
204 "aaiTrustAllCerts=false\n" +
205 "aaiApiVersion=aai/v13\n" +
206 "aaiPropertiesFile=aaiclient.properties\n" +
207 "aaiApplicationId=SDNR\n" +
208 "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n" +
209 "aaiPcks12ClientCertPassphrase=adminadmin\n" +
210 "aaiClientConnectionTimeout=30000\n" +
213 "pmCluster=sendateodl5\n" +
215 "[toggleAlarmFilter]\n" +
221 private String getContent1() {
223 "dcaeUserCredentials=admin:admin\n" +
224 "dcaeUrl=http://localhost:45/abc\n" +
225 "dcaeHeartbeatPeriodSeconds=120\n" +
226 "dcaeTestCollector=no\n" +
229 "userPassword=passwd\n" +
231 "soapaddtimeout=10\n" +
232 "soapinqtimeout=20\n" +
234 "inqtemplate=inqreq.tmpl.xml\n" +
235 "assignedto=userid\n" +
236 "addtemplate=addreq.tmpl.xml\n" +
237 "severitypassthrough=critical,major,minor,warning\n" +
238 "systemuser=user\n" +
239 "prt-offset=1200\n" +
246 "#smtpReceivers=\n" +
249 "esCluster=sendateodl5\n" +
253 "aaiHeaders=[\"X-TransactionId: 9999\"]\n" +
255 "aaiUserCredentials=AAI:AAI\n" +
256 "aaiDeleteOnMountpointRemove=true\n" +
257 "aaiTrustAllCerts=false\n" +
258 "aaiApiVersion=aai/v13\n" +
259 "aaiPropertiesFile=aaiclient.properties\n" +
262 "pmCluster=sendateodl5\n" +
264 "[toggleAlarmFilter]\n" +
265 "taEnabled=false\n" +
269 private String getAaiPropertiesConfig() {
270 return "org.onap.ccsdk.sli.adaptors.aai.ssl.key=keykey\"\"\n" +
271 "org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd=psswdpsswd\"\"\n" +
272 "org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=\"false\"\n" +
273 "org.onap.ccsdk.sli.adaptors.aai.application=appxyz\"\"\n" +
274 "org.onap.ccsdk.sli.adaptors.aai.uri=uriu\"\"\n" +
275 "connection.timeout=60000\n" +
276 "read.timeout=60000";