Add support to 7.1 VES data-stream in-parallel to 5.4
[holmes/engine-management.git] / engine-d / src / test / java / org / onap / holmes / dsa / dmaappolling / DMaaPResponseUtilTest.java
1 /*
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.holmes.dsa.dmaappolling;
17
18 import org.junit.Before;
19 import org.junit.Rule;
20 import org.junit.Test;
21 import org.junit.rules.ExpectedException;
22 import org.onap.holmes.common.api.stat.AlarmAdditionalField;
23 import org.onap.holmes.common.api.stat.VesAlarm;
24 import org.powermock.core.classloader.annotations.PrepareForTest;
25
26 import java.io.IOException;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.TimeZone;
30
31 import static org.hamcrest.CoreMatchers.equalTo;
32 import static org.junit.Assert.assertThat;
33
34
35 @PrepareForTest(DMaaPResponseUtil.class)
36 public class DMaaPResponseUtilTest {
37
38     @Rule
39     public ExpectedException thrown = ExpectedException.none();
40
41     private DMaaPResponseUtil dMaaPResponseUtil;
42
43     @Before
44     public void setUp() {
45         dMaaPResponseUtil = new DMaaPResponseUtil();
46     }
47
48     @Test
49     public void testDMaaPResponseUtil_input_normal() throws IOException {
50         String json = "{\"event\":{"
51                 + "\"commonEventHeader\":{"
52                 + "\"domain\":\"fault\","
53                 + "\"eventId\":\"112355255-24345\","
54                 + "\"eventName\":\"4333454333\","
55                 + "\"eventType\":\"remote\","
56                 + "\"lastEpochMicrosec\":333434333,"
57                 + "\"nfcNamingCode\":\"567422\","
58                 + "\"nfNamingCode\":\"qweertrr\","
59                 + "\"priority\":\"High\","
60                 + "\"reportingEntityId\":\"99888888888\","
61                 + "\"reportingEntityName\":\"tianshisdlsdjf\","
62                 + "\"sequence\":34566,"
63                 + "\"sourceId\":\"3345556444\","
64                 + "\"sourceName\":\"nihoahh\","
65                 + "\"startEpochMicrosec\":54545454,"
66                 + "\"version\":\"4.0\""
67                 + "},"
68                 + "\"faultFields\":{"
69                 + "\"alarmAdditionalInformation\":["
70                 + "{"
71                 + "\"name\":\"niaho\","
72                 + "\"value\":\"1111\""
73                 + "},"
74                 + "{"
75                 + "\"name\":\"tian\","
76                 + "\"value\":\"22222\""
77                 + "}"
78                 + "],"
79                 + "\"alarmCondition\":\"fadilel\","
80                 + "\"alarmInterfaceA\":\"generating the alarm\","
81                 + "\"eventCategory\":\"Event category\","
82                 + "\"eventSeverity\":\"CRITICAL\","
83                 + "\"eventSourceType\":\"type of event source\","
84                 + "\"faultFieldsVersion\":\"2.0\","
85                 + "\"specificProblem\":\"short description\","
86                 + "\"vfStatus\":\"Preparing to terminate\""
87                 + "}"
88                 + "}"
89                 + "}";
90         VesAlarm expected = new VesAlarm();
91         expected.setDomain("fault");
92         expected.setEventId("112355255-24345");
93         expected.setEventName("4333454333");
94         expected.setEventType("remote");
95         expected.setLastEpochMicrosec((long) 333434333);
96         expected.setNfcNamingCode("567422");
97         expected.setNfNamingCode("qweertrr");
98         expected.setPriority("High");
99         expected.setReportingEntityId("99888888888");
100         expected.setReportingEntityName("tianshisdlsdjf");
101         expected.setSequence(34566);
102         expected.setSourceId("3345556444");
103         expected.setSourceName("nihoahh");
104         expected.setStartEpochMicrosec((long) 54545454);
105         expected.setVersion("4.0");
106
107         Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
108         alarmAdditionalFields.put("niaho", "1111");
109         alarmAdditionalFields.put("titan", "22222");
110         expected.setAlarmAdditionalInformation(alarmAdditionalFields);
111         expected.setAlarmCondition("fadilel");
112         expected.setAlarmInterfaceA("generating the alarm");
113         expected.setEventCategory("Event category");
114         expected.setEventSeverity("CRITICAL");
115         expected.setEventSourceType("type of event source");
116         expected.setFaultFieldsVersion("2.0");
117         expected.setSpecificProblem("short description");
118         expected.setVfStatus("Preparing to terminate");
119
120         VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
121
122         assertThat(expected.getDomain(), equalTo(result.getDomain()));
123         assertThat(expected.getEventId(), equalTo(result.getEventId()));
124         assertThat(expected.getEventName(), equalTo(result.getEventName()));
125         assertThat(expected.getEventType(), equalTo(result.getEventType()));
126         assertThat(expected.getLastEpochMicrosec(), equalTo(result.getLastEpochMicrosec()));
127         assertThat(expected.getNfcNamingCode(), equalTo(result.getNfcNamingCode()));
128         assertThat(expected.getNfNamingCode(), equalTo(result.getNfNamingCode()));
129         assertThat(expected.getPriority(), equalTo(result.getPriority()));
130         assertThat(expected.getReportingEntityId(), equalTo(result.getReportingEntityId()));
131         assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
132         assertThat(expected.getSequence(), equalTo(result.getSequence()));
133         assertThat(expected.getSourceId(), equalTo(result.getSourceId()));
134         assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
135         assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
136         assertThat(expected.getVersion(), equalTo(result.getVersion()));
137
138         assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
139         assertThat(expected.getAlarmInterfaceA(), equalTo(result.getAlarmInterfaceA()));
140         assertThat(expected.getEventCategory(), equalTo(result.getEventCategory()));
141         assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
142         assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
143         assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
144         assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
145         assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
146
147     }
148
149     @Test
150     public void testDMaaPResponseUtil_v7_input_normal() throws IOException {
151         String json = "{\"event\":{"
152                 + "\"commonEventHeader\":{"
153                 + "\"domain\":\"fault\","
154                 + "\"eventId\":\"112355255-24345\","
155                 + "\"eventName\":\"4333454333\","
156                 + "\"eventType\":\"remote\","
157                 + "\"lastEpochMicrosec\":333434333,"
158                 + "\"nfcNamingCode\":\"567422\","
159                 + "\"nfNamingCode\":\"qweertrr\","
160                 + "\"priority\":\"High\","
161                 + "\"reportingEntityId\":\"99888888888\","
162                 + "\"reportingEntityName\":\"tianshisdlsdjf\","
163                 + "\"sequence\":34566,"
164                 + "\"sourceId\":\"3345556444\","
165                 + "\"sourceName\":\"nihoahh\","
166                 + "\"startEpochMicrosec\":54545454,"
167                 + "\"version\":\"998989879\","
168                 + "\"timeZoneOffset\":\"UTC-05:30\","
169                         + "\"nfVendorName\": \"Ericsson\","
170                 + "\"vesEventListenerVersion\": \"7.2.1\""
171                 + "},"
172                 + "\"faultFields\":{"
173                 + "\"alarmAdditionalInformation\":"
174                 + "{"
175                 + "\"niaho\":\"1111\","
176                 + "\"titan\":\"2222\""
177                 + "}"
178                 + ","
179                 + "\"alarmCondition\":\"fadilel\","
180                 + "\"alarmInterfaceA\":\"generating the alarm\","
181                 + "\"eventCategory\":\"Event category\","
182                 + "\"eventSeverity\":\"CRITICAL\","
183                 + "\"eventSourceType\":\"type of event source\","
184                 + "\"faultFieldsVersion\":4.0,"
185                 + "\"specificProblem\":\"short description\","
186                 + "\"vfStatus\":\"Preparing to terminate\""
187                 + "}"
188                 + "}"
189                 + "}";
190         VesAlarm expected = new VesAlarm();
191         expected.setDomain("fault");
192         expected.setEventId("112355255-24345");
193         expected.setEventName("4333454333");
194         expected.setEventType("remote");
195         expected.setLastEpochMicrosec((long) 333434333);
196         expected.setNfcNamingCode("567422");
197         expected.setNfNamingCode("qweertrr");
198         expected.setPriority("High");
199         expected.setReportingEntityId("99888888888");
200         expected.setReportingEntityName("tianshisdlsdjf");
201         expected.setSequence(34566);
202         expected.setSourceId("3345556444");
203         expected.setSourceName("nihoahh");
204         expected.setStartEpochMicrosec((long) 54545454);
205         expected.setVersion("998989879");
206         expected.setNfVendorName("Ericsson");
207         expected.setVesEventListenerVersion("7.2.1");
208         TimeZone timeZone = TimeZone.getTimeZone("UTC-05:30");
209         expected.setTimeZoneOffset(timeZone);
210         Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
211         alarmAdditionalFields.put("niaho", "1111");
212         alarmAdditionalFields.put("titan", "22222");
213         expected.setAlarmAdditionalInformation(alarmAdditionalFields);
214
215         expected.setAlarmCondition("fadilel");
216         expected.setAlarmInterfaceA("generating the alarm");
217         expected.setEventCategory("Event category");
218         expected.setEventSeverity("CRITICAL");
219         expected.setEventSourceType("type of event source");
220         expected.setFaultFieldsVersion("4.0");
221         expected.setSpecificProblem("short description");
222         expected.setVfStatus("Preparing to terminate");
223
224         VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
225
226         assertThat(expected.getDomain(), equalTo(result.getDomain()));
227         assertThat(expected.getEventId(), equalTo(result.getEventId()));
228         assertThat(expected.getEventName(), equalTo(result.getEventName()));
229         assertThat(expected.getEventType(), equalTo(result.getEventType()));
230         assertThat(expected.getLastEpochMicrosec(), equalTo(result.getLastEpochMicrosec()));
231         assertThat(expected.getNfcNamingCode(), equalTo(result.getNfcNamingCode()));
232         assertThat(expected.getNfNamingCode(), equalTo(result.getNfNamingCode()));
233         assertThat(expected.getPriority(), equalTo(result.getPriority()));
234         assertThat(expected.getReportingEntityId(), equalTo(result.getReportingEntityId()));
235         assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
236         assertThat(expected.getSequence(), equalTo(result.getSequence()));
237         assertThat(expected.getSourceId(), equalTo(result.getSourceId()));
238         assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
239         assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
240         assertThat(expected.getVersion(), equalTo(result.getVersion()));
241
242         assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
243         assertThat(expected.getAlarmInterfaceA(), equalTo(result.getAlarmInterfaceA()));
244         assertThat(expected.getEventCategory(), equalTo(result.getEventCategory()));
245         assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
246         assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
247         assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
248         assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
249         assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
250         assertThat(expected.getVesEventListenerVersion(), equalTo(result.getVesEventListenerVersion()));
251         assertThat(expected.getNfVendorName(), equalTo(result.getNfVendorName()));
252         assertThat(expected.getTimeZoneOffset(), equalTo(result.getTimeZoneOffset()));
253
254     }
255
256     @Test
257     public void testDMaaPResponseUtil_throws_nullPointerException() throws Exception {
258         String json = "{}";
259         thrown.expect(NullPointerException.class);
260         dMaaPResponseUtil.convertJsonToVesAlarm(json);
261     }
262
263     @Test
264     public void testDMaaPResponseUtil_input_illegal() throws Exception {
265         String json = "***";
266         thrown.expect(Exception.class);
267         dMaaPResponseUtil.convertJsonToVesAlarm(json);
268     }
269
270     @Test
271     public void testDMaaPResponseUtil_only_necessary_information() throws IOException {
272         String json = "{\"event\":{"
273                 + "\"commonEventHeader\":{"
274                 + "\"domain\":\"fault\","
275                 + "\"eventId\":\"112355255-24345\","
276                 + "\"eventName\":\"4333454333\","
277                 + "\"eventType\":\"remote\","
278                 + "\"lastEpochMicrosec\":333434333,"
279                 + "\"priority\":\"High\","
280                 + "\"reportingEntityName\":\"tianshisdlsdjf\","
281                 + "\"sequence\":34566,"
282                 + "\"sourceName\":\"nihoahh\","
283                 + "\"startEpochMicrosec\":54545454,"
284                 + "\"version\":\"4.0\""
285                 + "},"
286                 + "\"faultFields\":{"
287                 + "\"alarmAdditionalInformation\":["
288                 + "{"
289                 + "\"name\":\"niaho\","
290                 + "\"value\":\"1111\""
291                 + "},"
292                 + "{"
293                 + "\"name\":\"tian\","
294                 + "\"value\":\"22222\""
295                 + "}"
296                 + "],"
297                 + "\"alarmCondition\":\"fadilel\","
298                 + "\"eventSeverity\":\"CRITICAL\","
299                 + "\"eventSourceType\":\"type of event source\","
300                 + "\"faultFieldsVersion\":\"2.0\","
301                 + "\"specificProblem\":\"short description\","
302                 + "\"vfStatus\":\"Preparing to terminate\""
303                 + "}"
304                 + "}"
305                 + "}";
306         VesAlarm expected = new VesAlarm();
307         expected.setDomain("fault");
308         expected.setEventId("112355255-24345");
309         expected.setEventName("4333454333");
310         expected.setPriority("High");
311         expected.setReportingEntityName("tianshisdlsdjf");
312         expected.setSequence(34566);
313         expected.setSourceName("nihoahh");
314         expected.setStartEpochMicrosec((long) 54545454);
315         expected.setVersion("4.0");
316         Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
317         alarmAdditionalFields.put("niaho", "1111");
318         alarmAdditionalFields.put("titan", "22222");
319         expected.setAlarmAdditionalInformation(alarmAdditionalFields);
320
321         expected.setAlarmCondition("fadilel");
322         expected.setEventSeverity("CRITICAL");
323         expected.setEventSourceType("type of event source");
324         expected.setFaultFieldsVersion("2.0");
325         expected.setSpecificProblem("short description");
326         expected.setVfStatus("Preparing to terminate");
327
328         VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
329
330         assertThat(expected.getDomain(), equalTo(result.getDomain()));
331         assertThat(expected.getEventId(), equalTo(result.getEventId()));
332         assertThat(expected.getEventName(), equalTo(result.getEventName()));
333         assertThat(expected.getPriority(), equalTo(result.getPriority()));
334         assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
335         assertThat(expected.getSequence(), equalTo(result.getSequence()));
336         assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
337         assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
338         assertThat(expected.getVersion(), equalTo(result.getVersion()));
339
340         assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
341         assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
342         assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
343         assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
344         assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
345         assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
346     }
347
348     @Test
349     public void testDMaaPResponseUtil_input_array_illegal() throws IOException {
350         String json = "{\"event\":{"
351                 + "\"commonEventHeader\":{"
352                 + "\"domain\":\"fault\","
353                 + "\"eventId\":\"112355255-24345\","
354                 + "\"eventName\":\"4333454333\","
355                 + "\"eventType\":\"remote\","
356                 + "\"lastEpochMicrosec\":333434333,"
357                 + "\"priority\":\"High\","
358                 + "\"reportingEntityName\":\"tianshisdlsdjf\","
359                 + "\"sequence\":34566,"
360                 + "\"sourceName\":\"nihoahh\","
361                 + "\"startEpochMicrosec\":54545454,"
362                 + "\"version\":\"4.0\""
363                 + "},"
364                 + "\"faultFields\":{"
365                 + "\"alarmAdditionalInformation\":["
366                 + "{"
367                 + "\"nam\":\"niaho\","
368                 + "\"value\":\"1111\""
369                 + "},"
370                 + "{"
371                 + "\"name\":\"tian\","
372                 + "\"value\":\"22222\""
373                 + "}"
374                 + "],"
375                 + "\"alarmCondition\":\"fadilel\","
376                 + "\"eventSeverity\":\"CRITICAL\","
377                 + "\"eventSourceType\":\"type of event source\","
378                 + "\"faultFieldsVersion\":\"2.0\","
379                 + "\"specificProblem\":\"short description\","
380                 + "\"vfStatus\":\"Preparing to terminate\""
381                 + "}"
382                 + "}"
383                 + "}";
384         VesAlarm expected = new VesAlarm();
385         expected.setDomain("fault");
386         expected.setEventId("112355255-24345");
387         expected.setEventName("4333454333");
388         expected.setPriority("High");
389         expected.setReportingEntityName("tianshisdlsdjf");
390         expected.setSequence(34566);
391         expected.setSourceName("nihoahh");
392         expected.setStartEpochMicrosec((long) 54545454);
393         expected.setVersion("4.0");
394         Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
395         alarmAdditionalFields.put(null, "1111");
396         expected.setAlarmAdditionalInformation(alarmAdditionalFields);
397
398         expected.setAlarmCondition("fadilel");
399         expected.setEventSeverity("CRITICAL");
400         expected.setEventSourceType("type of event source");
401         expected.setFaultFieldsVersion("2.0");
402         expected.setSpecificProblem("short description");
403         expected.setVfStatus("Preparing to terminate");
404
405         VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
406
407         assertThat(expected.getDomain(), equalTo(result.getDomain()));
408         assertThat(expected.getEventId(), equalTo(result.getEventId()));
409         assertThat(expected.getEventName(), equalTo(result.getEventName()));
410         assertThat(expected.getPriority(), equalTo(result.getPriority()));
411         assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
412         assertThat(expected.getSequence(), equalTo(result.getSequence()));
413         assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
414         assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
415         assertThat(expected.getVersion(), equalTo(result.getVersion()));
416         assertThat(expected.getAlarmAdditionalInformation().get("niaho"),
417         equalTo(result.getAlarmAdditionalInformation().get("niaho")));
418
419
420         assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
421         assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
422         assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
423         assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
424         assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
425         assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
426     }
427 }