2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import com.google.common.io.Files;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 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.types.VESMessage;
36 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl;
37 import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.config.VESCollectorCfgImpl;
39 public class TestVESCollectorClient {
41 private static final String TESTCONFIG_CONTENT_NO_AUTH = "[VESCollector]\n" + "VES_COLLECTOR_IP=127.0.0.1\n"
42 + "VES_COLLECTOR_PORT=8080\n" + "VES_COLLECTOR_TLS_ENABLED=false\n" + "VES_COLLECTOR_USERNAME=sample1\n"
43 + "VES_COLLECTOR_PASSWORD=sample1\n" + "VES_COLLECTOR_VERSION=v7\n" + "REPORTING_ENTITY_NAME=ONAP SDN-R\n" + "";
45 private static final String TESTCONFIG_CONTENT_AUTH = "[VESCollector]\n" + "VES_COLLECTOR_IP=127.0.0.1\n"
46 + "VES_COLLECTOR_PORT=8080\n" + "VES_COLLECTOR_TLS_ENABLED=true\n" + "VES_COLLECTOR_USERNAME=sample1\n"
47 + "VES_COLLECTOR_PASSWORD=sample1\n" + "VES_COLLECTOR_VERSION=v7\n" + "REPORTING_ENTITY_NAME=ONAP SDN-R\n" + "";
49 private static final VESMessage message = new VESMessage("Test Message");
50 private static final String CONFIG_FILE = "test.properties";
51 private static final String CONFIG_FILE2 = "test2.properties";
54 public void testNoAuth() throws Exception {
55 ConfigurationFileRepresentation vesCfg;
56 VESCollectorServiceImpl vesClient;
58 Files.asCharSink(new File(CONFIG_FILE), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT_NO_AUTH);
59 vesCfg = new ConfigurationFileRepresentation(CONFIG_FILE);
60 vesClient = new VESCollectorServiceImpl(vesCfg);
62 vesClient.publishVESMessage(message);
68 public void testAuth() throws Exception {
69 ConfigurationFileRepresentation vesCfg;
70 VESCollectorServiceImpl vesClient;
72 Files.asCharSink(new File("test.properties"), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT_AUTH);
73 vesCfg = new ConfigurationFileRepresentation("test.properties");
75 vesClient = new VESCollectorServiceImpl(vesCfg);
76 vesClient.publishVESMessage(message);
81 public void testDefaultConfigValues() throws IOException {
82 Files.asCharSink(new File(CONFIG_FILE2), StandardCharsets.UTF_8).write("");
83 ConfigurationFileRepresentation cfg = new ConfigurationFileRepresentation(CONFIG_FILE2);
84 VESCollectorCfgImpl vesConfig = new VESCollectorCfgImpl(cfg);
85 assertEquals("ONAP SDN-R", vesConfig.getReportingEntityName());
86 assertEquals("SHORT", vesConfig.getEventLogMsgDetail());
87 assertEquals("v7",vesConfig.getVersion());
88 assertFalse(vesConfig.isVESCollectorEnabled());
89 assertFalse(vesConfig.isTrustAllCerts());
96 public void after() throws InterruptedException, IOException {
98 delete(new File(CONFIG_FILE));
99 delete(new File(CONFIG_FILE2));
103 private static void delete(File f) throws IOException {
104 if (f.isDirectory()) {
105 for (File c : f.listFiles()) {
111 throw new FileNotFoundException("Failed to delete file: " + f);