2 * Copyright 2017 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.holmes.dsa.dmaappolling;
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.VesAlarm;
23 import org.powermock.core.classloader.annotations.PrepareForTest;
25 import java.io.IOException;
26 import java.util.HashMap;
28 import java.util.TimeZone;
30 import static org.hamcrest.CoreMatchers.equalTo;
31 import static org.junit.Assert.assertThat;
34 @PrepareForTest(DMaaPResponseUtil.class)
35 public class DMaaPResponseUtilTest {
38 public ExpectedException thrown = ExpectedException.none();
40 private DMaaPResponseUtil dMaaPResponseUtil;
44 dMaaPResponseUtil = new DMaaPResponseUtil();
48 public void testDMaaPResponseUtil_input_normal() throws IOException {
49 String json = "{\"event\":{"
50 + "\"commonEventHeader\":{"
51 + "\"domain\":\"fault\","
52 + "\"eventId\":\"112355255-24345\","
53 + "\"eventName\":\"4333454333\","
54 + "\"eventType\":\"remote\","
55 + "\"lastEpochMicrosec\":333434333,"
56 + "\"nfcNamingCode\":\"567422\","
57 + "\"nfNamingCode\":\"qweertrr\","
58 + "\"priority\":\"High\","
59 + "\"reportingEntityId\":\"99888888888\","
60 + "\"reportingEntityName\":\"tianshisdlsdjf\","
61 + "\"sequence\":34566,"
62 + "\"sourceId\":\"3345556444\","
63 + "\"sourceName\":\"nihoahh\","
64 + "\"startEpochMicrosec\":54545454,"
65 + "\"version\":\"4.0\""
68 + "\"alarmAdditionalInformation\":["
70 + "\"name\":\"niaho\","
71 + "\"value\":\"1111\""
74 + "\"name\":\"tian\","
75 + "\"value\":\"22222\""
78 + "\"alarmCondition\":\"fadilel\","
79 + "\"alarmInterfaceA\":\"generating the alarm\","
80 + "\"eventCategory\":\"Event category\","
81 + "\"eventSeverity\":\"CRITICAL\","
82 + "\"eventSourceType\":\"type of event source\","
83 + "\"faultFieldsVersion\":\"2.0\","
84 + "\"specificProblem\":\"short description\","
85 + "\"vfStatus\":\"Preparing to terminate\""
89 VesAlarm expected = new VesAlarm();
90 expected.setDomain("fault");
91 expected.setEventId("112355255-24345");
92 expected.setEventName("4333454333");
93 expected.setEventType("remote");
94 expected.setLastEpochMicrosec((long) 333434333);
95 expected.setNfcNamingCode("567422");
96 expected.setNfNamingCode("qweertrr");
97 expected.setPriority("High");
98 expected.setReportingEntityId("99888888888");
99 expected.setReportingEntityName("tianshisdlsdjf");
100 expected.setSequence(34566);
101 expected.setSourceId("3345556444");
102 expected.setSourceName("nihoahh");
103 expected.setStartEpochMicrosec((long) 54545454);
104 expected.setVersion("4.0");
106 Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
107 alarmAdditionalFields.put("niaho", "1111");
108 alarmAdditionalFields.put("titan", "22222");
109 expected.setAlarmAdditionalInformation(alarmAdditionalFields);
110 expected.setAlarmCondition("fadilel");
111 expected.setAlarmInterfaceA("generating the alarm");
112 expected.setEventCategory("Event category");
113 expected.setEventSeverity("CRITICAL");
114 expected.setEventSourceType("type of event source");
115 expected.setFaultFieldsVersion("2.0");
116 expected.setSpecificProblem("short description");
117 expected.setVfStatus("Preparing to terminate");
119 VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
121 assertThat(expected.getDomain(), equalTo(result.getDomain()));
122 assertThat(expected.getEventId(), equalTo(result.getEventId()));
123 assertThat(expected.getEventName(), equalTo(result.getEventName()));
124 assertThat(expected.getEventType(), equalTo(result.getEventType()));
125 assertThat(expected.getLastEpochMicrosec(), equalTo(result.getLastEpochMicrosec()));
126 assertThat(expected.getNfcNamingCode(), equalTo(result.getNfcNamingCode()));
127 assertThat(expected.getNfNamingCode(), equalTo(result.getNfNamingCode()));
128 assertThat(expected.getPriority(), equalTo(result.getPriority()));
129 assertThat(expected.getReportingEntityId(), equalTo(result.getReportingEntityId()));
130 assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
131 assertThat(expected.getSequence(), equalTo(result.getSequence()));
132 assertThat(expected.getSourceId(), equalTo(result.getSourceId()));
133 assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
134 assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
135 assertThat(expected.getVersion(), equalTo(result.getVersion()));
137 assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
138 assertThat(expected.getAlarmInterfaceA(), equalTo(result.getAlarmInterfaceA()));
139 assertThat(expected.getEventCategory(), equalTo(result.getEventCategory()));
140 assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
141 assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
142 assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
143 assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
144 assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
149 public void testDMaaPResponseUtil_v7_input_normal() throws IOException {
150 String json = "{\"event\":{"
151 + "\"commonEventHeader\":{"
152 + "\"domain\":\"fault\","
153 + "\"eventId\":\"112355255-24345\","
154 + "\"eventName\":\"4333454333\","
155 + "\"eventType\":\"remote\","
156 + "\"lastEpochMicrosec\":333434333,"
157 + "\"nfcNamingCode\":\"567422\","
158 + "\"nfNamingCode\":\"qweertrr\","
159 + "\"priority\":\"High\","
160 + "\"reportingEntityId\":\"99888888888\","
161 + "\"reportingEntityName\":\"tianshisdlsdjf\","
162 + "\"sequence\":34566,"
163 + "\"sourceId\":\"3345556444\","
164 + "\"sourceName\":\"nihoahh\","
165 + "\"startEpochMicrosec\":54545454,"
166 + "\"version\":\"998989879\","
167 + "\"timeZoneOffset\":\"UTC-05:30\","
168 + "\"nfVendorName\": \"Ericsson\","
169 + "\"vesEventListenerVersion\": \"7.2.1\""
171 + "\"faultFields\":{"
172 + "\"alarmAdditionalInformation\":"
174 + "\"niaho\":\"1111\","
175 + "\"titan\":\"2222\""
178 + "\"alarmCondition\":\"fadilel\","
179 + "\"alarmInterfaceA\":\"generating the alarm\","
180 + "\"eventCategory\":\"Event category\","
181 + "\"eventSeverity\":\"CRITICAL\","
182 + "\"eventSourceType\":\"type of event source\","
183 + "\"faultFieldsVersion\":4.0,"
184 + "\"specificProblem\":\"short description\","
185 + "\"vfStatus\":\"Preparing to terminate\""
189 VesAlarm expected = new VesAlarm();
190 expected.setDomain("fault");
191 expected.setEventId("112355255-24345");
192 expected.setEventName("4333454333");
193 expected.setEventType("remote");
194 expected.setLastEpochMicrosec((long) 333434333);
195 expected.setNfcNamingCode("567422");
196 expected.setNfNamingCode("qweertrr");
197 expected.setPriority("High");
198 expected.setReportingEntityId("99888888888");
199 expected.setReportingEntityName("tianshisdlsdjf");
200 expected.setSequence(34566);
201 expected.setSourceId("3345556444");
202 expected.setSourceName("nihoahh");
203 expected.setStartEpochMicrosec((long) 54545454);
204 expected.setVersion("998989879");
205 expected.setNfVendorName("Ericsson");
206 expected.setVesEventListenerVersion("7.2.1");
207 TimeZone timeZone = TimeZone.getTimeZone("UTC-05:30");
208 expected.setTimeZoneOffset(timeZone);
209 Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
210 alarmAdditionalFields.put("niaho", "1111");
211 alarmAdditionalFields.put("titan", "22222");
212 expected.setAlarmAdditionalInformation(alarmAdditionalFields);
214 expected.setAlarmCondition("fadilel");
215 expected.setAlarmInterfaceA("generating the alarm");
216 expected.setEventCategory("Event category");
217 expected.setEventSeverity("CRITICAL");
218 expected.setEventSourceType("type of event source");
219 expected.setFaultFieldsVersion("4.0");
220 expected.setSpecificProblem("short description");
221 expected.setVfStatus("Preparing to terminate");
223 VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
225 assertThat(expected.getDomain(), equalTo(result.getDomain()));
226 assertThat(expected.getEventId(), equalTo(result.getEventId()));
227 assertThat(expected.getEventName(), equalTo(result.getEventName()));
228 assertThat(expected.getEventType(), equalTo(result.getEventType()));
229 assertThat(expected.getLastEpochMicrosec(), equalTo(result.getLastEpochMicrosec()));
230 assertThat(expected.getNfcNamingCode(), equalTo(result.getNfcNamingCode()));
231 assertThat(expected.getNfNamingCode(), equalTo(result.getNfNamingCode()));
232 assertThat(expected.getPriority(), equalTo(result.getPriority()));
233 assertThat(expected.getReportingEntityId(), equalTo(result.getReportingEntityId()));
234 assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
235 assertThat(expected.getSequence(), equalTo(result.getSequence()));
236 assertThat(expected.getSourceId(), equalTo(result.getSourceId()));
237 assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
238 assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
239 assertThat(expected.getVersion(), equalTo(result.getVersion()));
241 assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
242 assertThat(expected.getAlarmInterfaceA(), equalTo(result.getAlarmInterfaceA()));
243 assertThat(expected.getEventCategory(), equalTo(result.getEventCategory()));
244 assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
245 assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
246 assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
247 assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
248 assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
249 assertThat(expected.getVesEventListenerVersion(), equalTo(result.getVesEventListenerVersion()));
250 assertThat(expected.getNfVendorName(), equalTo(result.getNfVendorName()));
251 assertThat(expected.getTimeZoneOffset(), equalTo(result.getTimeZoneOffset()));
256 public void testDMaaPResponseUtil_throws_nullPointerException() throws Exception {
258 thrown.expect(NullPointerException.class);
259 dMaaPResponseUtil.convertJsonToVesAlarm(json);
263 public void testDMaaPResponseUtil_input_illegal() throws Exception {
265 thrown.expect(Exception.class);
266 dMaaPResponseUtil.convertJsonToVesAlarm(json);
270 public void testDMaaPResponseUtil_only_necessary_information() throws IOException {
271 String json = "{\"event\":{"
272 + "\"commonEventHeader\":{"
273 + "\"domain\":\"fault\","
274 + "\"eventId\":\"112355255-24345\","
275 + "\"eventName\":\"4333454333\","
276 + "\"eventType\":\"remote\","
277 + "\"lastEpochMicrosec\":333434333,"
278 + "\"priority\":\"High\","
279 + "\"reportingEntityName\":\"tianshisdlsdjf\","
280 + "\"sequence\":34566,"
281 + "\"sourceName\":\"nihoahh\","
282 + "\"startEpochMicrosec\":54545454,"
283 + "\"version\":\"4.0\""
285 + "\"faultFields\":{"
286 + "\"alarmAdditionalInformation\":["
288 + "\"name\":\"niaho\","
289 + "\"value\":\"1111\""
292 + "\"name\":\"tian\","
293 + "\"value\":\"22222\""
296 + "\"alarmCondition\":\"fadilel\","
297 + "\"eventSeverity\":\"CRITICAL\","
298 + "\"eventSourceType\":\"type of event source\","
299 + "\"faultFieldsVersion\":\"2.0\","
300 + "\"specificProblem\":\"short description\","
301 + "\"vfStatus\":\"Preparing to terminate\""
305 VesAlarm expected = new VesAlarm();
306 expected.setDomain("fault");
307 expected.setEventId("112355255-24345");
308 expected.setEventName("4333454333");
309 expected.setPriority("High");
310 expected.setReportingEntityName("tianshisdlsdjf");
311 expected.setSequence(34566);
312 expected.setSourceName("nihoahh");
313 expected.setStartEpochMicrosec((long) 54545454);
314 expected.setVersion("4.0");
315 Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
316 alarmAdditionalFields.put("niaho", "1111");
317 alarmAdditionalFields.put("titan", "22222");
318 expected.setAlarmAdditionalInformation(alarmAdditionalFields);
320 expected.setAlarmCondition("fadilel");
321 expected.setEventSeverity("CRITICAL");
322 expected.setEventSourceType("type of event source");
323 expected.setFaultFieldsVersion("2.0");
324 expected.setSpecificProblem("short description");
325 expected.setVfStatus("Preparing to terminate");
327 VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
329 assertThat(expected.getDomain(), equalTo(result.getDomain()));
330 assertThat(expected.getEventId(), equalTo(result.getEventId()));
331 assertThat(expected.getEventName(), equalTo(result.getEventName()));
332 assertThat(expected.getPriority(), equalTo(result.getPriority()));
333 assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
334 assertThat(expected.getSequence(), equalTo(result.getSequence()));
335 assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
336 assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
337 assertThat(expected.getVersion(), equalTo(result.getVersion()));
339 assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
340 assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
341 assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
342 assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
343 assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
344 assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));
348 public void testDMaaPResponseUtil_input_array_illegal() throws IOException {
349 String json = "{\"event\":{"
350 + "\"commonEventHeader\":{"
351 + "\"domain\":\"fault\","
352 + "\"eventId\":\"112355255-24345\","
353 + "\"eventName\":\"4333454333\","
354 + "\"eventType\":\"remote\","
355 + "\"lastEpochMicrosec\":333434333,"
356 + "\"priority\":\"High\","
357 + "\"reportingEntityName\":\"tianshisdlsdjf\","
358 + "\"sequence\":34566,"
359 + "\"sourceName\":\"nihoahh\","
360 + "\"startEpochMicrosec\":54545454,"
361 + "\"version\":\"4.0\""
363 + "\"faultFields\":{"
364 + "\"alarmAdditionalInformation\":["
366 + "\"nam\":\"niaho\","
367 + "\"value\":\"1111\""
370 + "\"name\":\"tian\","
371 + "\"value\":\"22222\""
374 + "\"alarmCondition\":\"fadilel\","
375 + "\"eventSeverity\":\"CRITICAL\","
376 + "\"eventSourceType\":\"type of event source\","
377 + "\"faultFieldsVersion\":\"2.0\","
378 + "\"specificProblem\":\"short description\","
379 + "\"vfStatus\":\"Preparing to terminate\""
383 VesAlarm expected = new VesAlarm();
384 expected.setDomain("fault");
385 expected.setEventId("112355255-24345");
386 expected.setEventName("4333454333");
387 expected.setPriority("High");
388 expected.setReportingEntityName("tianshisdlsdjf");
389 expected.setSequence(34566);
390 expected.setSourceName("nihoahh");
391 expected.setStartEpochMicrosec((long) 54545454);
392 expected.setVersion("4.0");
393 Map<String, String> alarmAdditionalFields = new HashMap<String, String>();
394 alarmAdditionalFields.put(null, "1111");
395 expected.setAlarmAdditionalInformation(alarmAdditionalFields);
397 expected.setAlarmCondition("fadilel");
398 expected.setEventSeverity("CRITICAL");
399 expected.setEventSourceType("type of event source");
400 expected.setFaultFieldsVersion("2.0");
401 expected.setSpecificProblem("short description");
402 expected.setVfStatus("Preparing to terminate");
404 VesAlarm result = dMaaPResponseUtil.convertJsonToVesAlarm(json);
406 assertThat(expected.getDomain(), equalTo(result.getDomain()));
407 assertThat(expected.getEventId(), equalTo(result.getEventId()));
408 assertThat(expected.getEventName(), equalTo(result.getEventName()));
409 assertThat(expected.getPriority(), equalTo(result.getPriority()));
410 assertThat(expected.getReportingEntityName(), equalTo(result.getReportingEntityName()));
411 assertThat(expected.getSequence(), equalTo(result.getSequence()));
412 assertThat(expected.getSourceName(), equalTo(result.getSourceName()));
413 assertThat(expected.getStartEpochMicrosec(), equalTo(result.getStartEpochMicrosec()));
414 assertThat(expected.getVersion(), equalTo(result.getVersion()));
415 assertThat(expected.getAlarmAdditionalInformation().get("niaho"),
416 equalTo(result.getAlarmAdditionalInformation().get("niaho")));
419 assertThat(expected.getAlarmCondition(), equalTo(result.getAlarmCondition()));
420 assertThat(expected.getEventSeverity(), equalTo(result.getEventSeverity()));
421 assertThat(expected.getEventSourceType(), equalTo(result.getEventSourceType()));
422 assertThat(expected.getFaultFieldsVersion(), equalTo(result.getFaultFieldsVersion()));
423 assertThat(expected.getSpecificProblem(), equalTo(result.getSpecificProblem()));
424 assertThat(expected.getVfStatus(), equalTo(result.getVfStatus()));