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.fail;
26 import java.io.IOException;
27 import java.io.OutputStream;
28 import java.net.InetSocketAddress;
29 import java.nio.charset.StandardCharsets;
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.concurrent.ExecutorService;
33 import java.util.concurrent.Executors;
35 import org.junit.After;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
39 import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient;
40 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
41 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
42 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
43 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.InventoryInformationDcae;
44 import com.google.common.io.Files;
45 import com.sun.net.httpserver.HttpExchange;
46 import com.sun.net.httpserver.HttpHandler;
47 import com.sun.net.httpserver.HttpServer;
49 @SuppressWarnings("restriction")
50 public class TestDcae {
52 private static final String ENABLEDDCAE_TESTCONFIG_FILENAME = "test2.properties";
53 private static final File ENABLEDDCAE_TESTCONFIG_FILE = new File(ENABLEDDCAE_TESTCONFIG_FILENAME);
54 private static final int DCAE_SERVER_PORT = 45451;
55 private static final String URI = "/abc";
56 private static final String TESTCONFIG_CONTENT = "[dcae]\n" + "dcaeUserCredentials=admin:admin\n"
57 + "dcaeUrl=http://localhost:" + DCAE_SERVER_PORT + URI + "\n" + "dcaeHeartbeatPeriodSeconds=120\n"
58 + "dcaeTestCollector=no\n" + "\n" + "[aots]\n" + "userPassword=passwd\n" + "soapurladd=off\n"
59 + "soapaddtimeout=10\n" + "soapinqtimeout=20\n" + "userName=user\n" + "inqtemplate=inqreq.tmpl.xml\n"
60 + "assignedto=userid\n" + "addtemplate=addreq.tmpl.xml\n"
61 + "severitypassthrough=critical,major,minor,warning\n" + "systemuser=user\n" + "prt-offset=1200\n"
62 + "soapurlinq=off\n" + "#smtpHost=\n" + "#smtpPort=\n" + "#smtpUsername=\n" + "#smtpPassword=\n"
63 + "#smtpSender=\n" + "#smtpReceivers=\n" + "\n" + "[es]\n" + "esCluster=sendateodl5\n" + "\n" + "[aai]\n"
64 + "#keep comment\n" + "aaiHeaders=[\"X-TransactionId: 9999\"]\n" + "aaiUrl=off\n"
65 + "aaiUserCredentials=AAI:AAI\n" + "aaiDeleteOnMountpointRemove=true\n" + "aaiTrustAllCerts=false\n"
66 + "aaiApiVersion=aai/v13\n" + "aaiPropertiesFile=aaiclient.properties\n" + "aaiApplicationId=SDNR\n"
67 + "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n"
68 + "aaiPcks12ClientCertPassphrase=adminadmin\n" + "aaiClientConnectionTimeout=30000\n" + "\n" + "[pm]\n"
69 + "pmCluster=sendateodl5\n" + "pmEnabled=true\n" + "\n" + "";
70 private HttpServer server;
71 private ExecutorService httpThreadPool;
72 private ConfigurationFileRepresentation cfg;
78 } catch (InterruptedException e1) {
81 DcaeProviderClient provider = new DcaeProviderClient(cfg, "mountpoint", null);
83 String mountPointName = "testDevice 01";
85 String model = "Horizon Compact+";
86 String vendor = "DragonWave-X";
87 String ipv4 = "127.0.0.1";
89 List<String> ifInfos = new ArrayList<>();
90 ifInfos.add("LP-MWPS-RADIO");
91 new InventoryInformationDcae(type, model, vendor, ipv4, ipv6, ifInfos);
92 System.out.println("registering device");
93 boolean neDeviceAlarm = false;
94 ProblemNotificationXml notification = new ProblemNotificationXml(mountPointName, "network-element",
95 "problemName", InternalSeverity.Critical, 123, InternalDateAndTime.getTestpattern());
96 provider.sendProblemNotification(mountPointName, notification, neDeviceAlarm);
100 } catch (InterruptedException e) {
105 } catch (Exception e) {
111 public void initDcaeTestWebserver() throws IOException {
113 Files.asCharSink(ENABLEDDCAE_TESTCONFIG_FILE, StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT);
114 } catch (IOException e1) {
115 fail(e1.getMessage());
117 cfg = new ConfigurationFileRepresentation(ENABLEDDCAE_TESTCONFIG_FILENAME);
118 // cfg.reload(ENABLEDDCAE_TESTCONFIG_FILENAME);
120 * cfg = new HtDevicemanagerConfiguration(ENABLEDDCAE_TESTCONFIG_FILENAME);
121 * DcaeConfig.reload();
124 this.server = HttpServer.create(new InetSocketAddress(DCAE_SERVER_PORT), 0);
125 } catch (Exception e) {
126 fail(e.getMessage());
128 this.httpThreadPool = Executors.newFixedThreadPool(5);
129 this.server.setExecutor(this.httpThreadPool);
130 this.server.createContext(URI, new MyHandler());
131 // server.createContext("/", new MyRootHandler());
132 this.server.setExecutor(null); // creates a default executor
134 System.out.println("http server started");
138 public void stopTestWebserver() {
139 if (this.server != null) {
141 this.httpThreadPool.shutdownNow();
142 System.out.println("http server stopped");
144 if (ENABLEDDCAE_TESTCONFIG_FILE.exists()) {
145 ENABLEDDCAE_TESTCONFIG_FILE.delete();
149 static class MyHandler implements HttpHandler {
151 public void handle(HttpExchange t) throws IOException {
152 String method = t.getRequestMethod();
153 System.out.println("req method: " + method);
154 OutputStream os = null;
157 if (method.equals("POST")) {
158 t.sendResponseHeaders(200, res.length());
159 os = t.getResponseBody();
160 os.write(res.getBytes());
162 t.sendResponseHeaders(404, 0);
164 System.out.println("req handled successful");
166 } catch (Exception e) {
167 System.out.println(e.getMessage());