fb38879a52cac9ce86115103ccd909fb6f6261b3
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.test;
20
21 import java.io.IOException;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.DMaaPPNFRegVESMsgConsumer;
26
27 public class TestDMaaPPNFRegVESMsgConsumer {
28
29     private static final String DEFAULT_SDNRUSER = "admin";
30     private static final String DEFAULT_SDNRPASSWD = "admin";
31     private static final String DEFAULT_SDNRBASEURL = "http://localhost:8181";
32     private static final String CONFIGURATIONFILE = "test4.properties";
33
34     // @formatter:off
35     private static final String pnfRegMsg_TLS = "{\n"
36     + "  \"event\": {\n"
37             + "    \"commonEventHeader\": {\n"
38             + "      \"domain\": \"pnfRegistration\",\n"
39             + "      \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n"
40             + "      \"eventName\": \"pnfRegistration_EventType5G\",\n"
41             + "      \"eventType\": \"EventType5G\",\n"
42             + "      \"sequence\": 0,\n"
43             + "      \"priority\": \"Low\",\n"
44             + "      \"reportingEntityId\": \"\",\n"
45             + "      \"reportingEntityName\": \"pendurty-virtual-machine\",\n"
46             + "      \"sourceId\": \"\",\n"
47             + "      \"sourceName\": \"NSHMRIACQ01M01123401\",\n"
48             + "      \"startEpochMicrosec\": 1571300004203,\n"
49             + "      \"lastEpochMicrosec\": 1571300004203,\n"
50             + "      \"nfNamingCode\": \"1234\",\n"
51             + "      \"nfVendorName\": \"VENDORA\",\n"
52             + "      \"timeZoneOffset\": \"+00:00\",\n"
53             + "      \"version\": \"4.0.1\",\n"
54             + "      \"vesEventListenerVersion\":\"7.0.1\"\n"
55             + "    },\n"
56             + "    \"pnfRegistrationFields\": {\n"
57             + "      \"pnfRegistrationFieldsVersion\": \"2.0\",\n"
58             + "         \"additionalFields\": \n"
59             + "         { \n"
60             + "                 \"protocol\":\"TLS\",\n"
61             + "                 \"keyId\":\"netconf\",\n"
62             + "                 \"oamPort\":\"50000\",\n"
63             + "                 \"betweenAttemptsTimeout\":\"2000\",\n"
64             + "                 \"keepaliveDelay\":\"120\",\n"
65             + "                 \"sleep-factor\":\"1.5\",\n"
66             + "                 \"reconnectOnChangedSchema\":\"false\",\n"
67             + "                 \"connectionTimeout\":\"20000\",\n"
68             + "                 \"maxConnectionAttempts\":\"100\",\n"
69             + "                 \"username\":\"netconf\",\n"
70             + "                 \"tcpOnly\":\"false\"\n"
71             + "         },\n"
72             + "      \"lastServiceDate\":\"2019-08-16\",\n"
73             + "      \"macAddress\":\"02:42:f7:d4:62:ce\",\n"
74             + "      \"manufactureDate\":\"2019-08-16\",\n"
75             + "      \"modelNumbsdnrer\": \"1234 BestInClass\",\n"
76             + "      \"oamV4IpAddress\": \"10.10.10.11\",\n"
77             + "    \"oamPort\":\"17380\",\n"
78             + "      \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n"
79             + "      \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n"
80             + "      \"softwareVersion\": \"2.3.5\",\n"
81             + "      \"unitFamily\": \"VENDORA-1234\",\n"
82             + "      \"unitType\": \"1234\",\n"
83             + "      \"vendorName\": \"VENDORA\"\n"
84             + "    }\n"
85             + "  }\n"
86             + "}\n"
87             + "";
88     private static final String pnfRegMsg_SSH = "{\n"
89             + "  \"event\": {\n"
90             + "    \"commonEventHeader\": {\n"
91             + "      \"domain\": \"pnfRegistration\",\n"
92             + "      \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n"
93             + "      \"eventName\": \"pnfRegistration_EventType5G\",\n"
94             + "      \"eventType\": \"EventType5G\",\n"
95             + "      \"sequence\": 0,\n"
96             + "      \"priority\": \"Low\",\n"
97             + "      \"reportingEntityId\": \"\",\n"
98             + "      \"reportingEntityName\": \"pendurty-virtual-machine\",\n"
99             + "      \"sourceId\": \"\",\n"
100             + "      \"sourceName\": \"NSHMRIACQ01M01123401\",\n"
101             + "      \"startEpochMicrosec\": 1571300004203,\n"
102             + "      \"lastEpochMicrosec\": 1571300004203,\n"
103             + "      \"nfNamingCode\": \"1234\",\n"
104             + "      \"nfVendorName\": \"VENDORA\",\n"
105             + "      \"timeZoneOffset\": \"+00:00\",\n"
106             + "      \"version\": \"4.0.1\",\n"
107             + "      \"vesEventListenerVersion\":\"7.0.1\"\n"
108             + "    },\n"
109             + "    \"pnfRegistrationFields\": {\n"
110             + "      \"pnfRegistrationFieldsVersion\": \"2.0\",\n"
111             + "         \"additionalFields\": \n"
112             + "         { \n"
113             + "                 \"protocol\":\"SSH\",\n"
114             + "                 \"password\":\"netconf\",\n"
115             + "                 \"oamPort\":\"50000\",\n"
116             + "                 \"betweenAttemptsTimeout\":\"2000\",\n"
117             + "                 \"keepaliveDelay\":\"120\",\n"
118             + "                 \"sleep-factor\":\"1.5\",\n"
119             + "                 \"reconnectOnChangedSchema\":\"false\",\n"
120             + "                 \"connectionTimeout\":\"20000\",\n"
121             + "                 \"maxConnectionAttempts\":\"100\",\n"
122             + "                 \"username\":\"netconf\",\n"
123             + "                 \"tcpOnly\":\"false\"\n"
124             + "         },\n"
125             + "      \"lastServiceDate\":\"2019-08-16\",\n"
126             + "      \"macAddress\":\"02:42:f7:d4:62:ce\",\n"
127             + "      \"manufactureDate\":\"2019-08-16\",\n"
128             + "      \"modelNumbsdnrer\": \"1234 BestInClass\",\n"
129             + "      \"oamV4IpAddress\": \"10.10.10.11\",\n"
130             + "    \"oamPort\":\"17380\",\n"
131             + "      \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n"
132             + "      \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n"
133             + "      \"softwareVersion\": \"2.3.5\",\n"
134             + "      \"unitFamily\": \"VENDORA-1234\",\n"
135             + "      \"unitType\": \"1234\",\n"
136             + "      \"vendorName\": \"VENDORA\"\n"
137             + "    }\n"
138             + "  }\n"
139             + "}\n"
140             + "";
141     private static final String pnfRegMsg_OTHER = "{\n"
142             + "  \"event\": {\n"
143             + "    \"commonEventHeader\": {\n"
144             + "      \"domain\": \"pnfRegistration\",\n"
145             + "      \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n"
146             + "      \"eventName\": \"pnfRegistration_EventType5G\",\n"
147             + "      \"eventType\": \"EventType5G\",\n"
148             + "      \"sequence\": 0,\n"
149             + "      \"priority\": \"Low\",\n"
150             + "      \"reportingEntityId\": \"\",\n"
151             + "      \"reportingEntityName\": \"pendurty-virtual-machine\",\n"
152             + "      \"sourceId\": \"\",\n"
153             + "      \"sourceName\": \"NSHMRIACQ01M01123401\",\n"
154             + "      \"startEpochMicrosec\": 1571300004203,\n"
155             + "      \"lastEpochMicrosec\": 1571300004203,\n"
156             + "      \"nfNamingCode\": \"1234\",\n"
157             + "      \"nfVendorName\": \"VENDORA\",\n"
158             + "      \"timeZoneOffset\": \"+00:00\",\n"
159             + "      \"version\": \"4.0.1\",\n"
160             + "      \"vesEventListenerVersion\":\"7.0.1\"\n"
161             + "    },\n"
162             + "    \"pnfRegistrationFields\": {\n"
163             + "      \"pnfRegistrationFieldsVersion\": \"2.0\",\n"
164             + "         \"additionalFields\": \n"
165             + "         { \n"
166             + "                 \"protocol\":\"OTHER\",\n"
167             + "                 \"password\":\"netconf\",\n"
168             + "                 \"oamPort\":\"50000\",\n"
169             + "                 \"betweenAttemptsTimeout\":\"2000\",\n"
170             + "                 \"keepaliveDelay\":\"120\",\n"
171             + "                 \"sleep-factor\":\"1.5\",\n"
172             + "                 \"reconnectOnChangedSchema\":\"false\",\n"
173             + "                 \"connectionTimeout\":\"20000\",\n"
174             + "                 \"maxConnectionAttempts\":\"100\",\n"
175             + "                 \"username\":\"netconf\",\n"
176             + "                 \"tcpOnly\":\"false\"\n"
177             + "         },\n"
178             + "      \"lastServiceDate\":\"2019-08-16\",\n"
179             + "      \"macAddress\":\"02:42:f7:d4:62:ce\",\n"
180             + "      \"manufactureDate\":\"2019-08-16\",\n"
181             + "      \"modelNumbsdnrer\": \"1234 BestInClass\",\n"
182             + "      \"oamV4IpAddress\": \"10.10.10.11\",\n"
183             + "    \"oamPort\":\"17380\",\n"
184             + "      \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n"
185             + "      \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n"
186             + "      \"softwareVersion\": \"2.3.5\",\n"
187             + "      \"unitFamily\": \"VENDORA-1234\",\n"
188             + "      \"unitType\": \"1234\",\n"
189             + "      \"vendorName\": \"VENDORA\"\n"
190             + "    }\n"
191             + "  }\n"
192             + "}\n"
193             + "";
194     private static final String pnfRegMsg = "{\n"
195             + "  \"event\": {\n"
196             + "    \"commonEventHeader\": {\n"
197             + "      \"domain\": \"pnfRegistration\",\n"
198             + "      \"eventId\": \"NSHMRIACQ01M01123401_1234 BestInClass\",\n"
199             + "      \"eventName\": \"pnfRegistration_EventType5G\",\n"
200             + "      \"eventType\": \"EventType5G\",\n"
201             + "      \"sequence\": 0,\n"
202             + "      \"priority\": \"Low\",\n"
203             + "      \"reportingEntityId\": \"\",\n"
204             + "      \"reportingEntityName\": \"pendurty-virtual-machine\",\n"
205             + "      \"sourceId\": \"\",\n"
206             + "      \"sourceName\": \"NSHMRIACQ01M01123401\",\n"
207             + "      \"startEpochMicrosec\": 1571300004203,\n"
208             + "      \"lastEpochMicrosec\": 1571300004203,\n"
209             + "      \"nfNamingCode\": \"1234\",\n"
210             + "      \"nfVendorName\": \"VENDORA\",\n"
211             + "      \"timeZoneOffset\": \"+00:00\",\n"
212             + "      \"version\": \"4.0.1\",\n"
213             + "      \"vesEventListenerVersion\":\"7.0.1\"\n"
214             + "    },\n"
215             + "    \"pnfRegistrationFields\": {\n"
216             + "      \"pnfRegistrationFieldsVersion\": \"2.0\",\n"
217             + "      \"lastServiceDate\":\"2019-08-16\",\n"
218             + "      \"macAddress\":\"02:42:f7:d4:62:ce\",\n"
219             + "      \"manufactureDate\":\"2019-08-16\",\n"
220             + "      \"modelNumbsdnrer\": \"1234 BestInClass\",\n"
221             + "      \"oamV4IpAddress\": \"10.10.10.11\",\n"
222             + "    \"oamPort\":\"17380\",\n"
223             + "      \"oamV6IpAddress\": \"0:0:0:0:0:ffff:a0a:011\",\n"
224             + "      \"serialNumber\": \"VENDORA-1234-10.10.10.11-1234 BestInClass\",\n"
225             + "      \"softwareVersion\": \"2.3.5\",\n"
226             + "      \"unitFamily\": \"VENDORA-1234\",\n"
227             + "      \"unitType\": \"1234\",\n"
228             + "      \"vendorName\": \"VENDORA\"\n"
229             + "    }\n"
230             + "  }\n"
231             + "}\n"
232             + "";
233     // @formatter:on
234
235     private GeneralConfigForTest cfgTest;
236
237     @Before
238     public void before() throws IOException {
239         cfgTest = new GeneralConfigForTest(CONFIGURATIONFILE);
240     }
241
242     @After
243     public void after() {
244         cfgTest.close();
245     }
246
247     @Test
248     public void processMsgTest() {
249
250         DMaaPPNFRegVESMsgConsumer pnfRegMsgConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg());
251         try {
252             pnfRegMsgConsumer.processMsg(pnfRegMsg);
253             pnfRegMsgConsumer.processMsg(pnfRegMsg_SSH);
254             pnfRegMsgConsumer.processMsg(pnfRegMsg_TLS);
255             pnfRegMsgConsumer.processMsg(pnfRegMsg_OTHER);
256         } catch (Exception e) {
257             e.printStackTrace();
258             System.out.println("Exception while processing PNF Registration Message - " + e.getMessage());
259         }
260     }
261
262     @Test
263     public void Test1() {
264         DMaaPPNFRegVESMsgConsumer pnfConsumer = new DMaaPPNFRegVESMsgConsumer(cfgTest.getCfg());
265         System.out.println(pnfConsumer.getBaseUrl());
266         System.out.println(pnfConsumer.getSDNRUser());
267         System.out.println(pnfConsumer.getSDNRPasswd());
268     }
269 }