ec8ac55bc4b5eb046a77a6d81f303682a250f6ba
[dcaegen2/services/prh.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dcaegen2.services.prh.service;
22
23 import static org.mockito.Mockito.spy;
24
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonObject;
27 import com.google.gson.JsonParser;
28 import java.util.Optional;
29 import org.junit.jupiter.api.Assertions;
30 import org.junit.jupiter.api.Test;
31 import org.mockito.Mockito;
32 import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
33 import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
34 import reactor.core.publisher.Mono;
35 import reactor.test.StepVerifier;
36
37 /**
38  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18
39  */
40 class DmaapConsumerJsonParserTest {
41
42     @Test
43     void whenPassingCorrectJson_validationNotThrowingAnException() {
44         //given
45         String message = "[{\"event\": {"
46                 + "\"commonEventHeader\": { "
47                 + " \"sourceName\":\"NOKQTFCOC540002E\","
48                 + " \"nfNamingCode\":\"gNB\" "
49                 + "},"
50                 + "\"pnfRegistrationFields\": {"
51                 + " \"vendorName\": \"nokia\","
52                 + " \"serialNumber\": \"QTFCOC540002E\","
53                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
54                 + " \"modelNumber\": \"3310\","
55                 + " \"unitType\": \"type\",\n"
56                 + " \"unitFamily\": \"BBU\","
57                 + " \"oamV4IpAddress\": \"10.16.123.234\","
58                 + " \"softwareVersion\": \"v4.5.0.1\","
59                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
60                 + " \"additionalFields\": {\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}"
61                 + "}}}]";
62
63         String parsed = "{\"event\": {"
64                 + "\"commonEventHeader\": { "
65                 + " \"sourceName\":\"NOKQTFCOC540002E\","
66                 + " \"nfNamingCode\":\"gNB\" "
67                 + "},"
68                 + "\"pnfRegistrationFields\": {"
69                 + " \"vendorName\": \"nokia\","
70                 + " \"serialNumber\": \"QTFCOC540002E\","
71                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
72                 + " \"modelNumber\": \"3310\","
73                 + " \"unitType\": \"type\",\n"
74                 + " \"unitFamily\": \"BBU\","
75                 + " \"oamV4IpAddress\": \"10.16.123.234\","
76                 + " \"softwareVersion\": \"v4.5.0.1\","
77                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
78                 + " \"additionalFields\": {\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}"
79                 + "}}}";
80
81         JsonObject jsonObject = new JsonParser().parse("{\n"
82             + "        \"attachmentPoint\": \"bla-bla-30-3\",\n"
83             + "        \"cvlan\": \"678\",\n"
84             + "        \"svlan\": \"1005\"\n"
85             + "      }").getAsJsonObject();
86
87         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
88                 .ipv4("10.16.123.234")
89                 .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
90                 .correlationId("NOKQTFCOC540002E")
91                 .serialNumber("QTFCOC540002E")
92                 .equipVendor("nokia")
93                 .equipModel("3310")
94                 .equipType("type")
95                 .nfRole("gNB")
96                 .swVersion("v4.5.0.1")
97                 .additionalFields(jsonObject)
98                 .build();
99         //when
100         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
101         JsonElement jsonElement = new JsonParser().parse(parsed);
102         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
103             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
104         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
105             .getJsonObject(Mono.just((message))).blockFirst();
106         //then
107         Assertions.assertNotNull(consumerDmaapModel);
108         Assertions.assertEquals(expectedObject, consumerDmaapModel);
109     }
110
111     @Test
112     void whenPassingJsonWithoutAdditionalFields_validationNotThrowingAnException() {
113         //given
114         String message = "[{\"event\": {"
115             + "\"commonEventHeader\": { "
116             + " \"sourceName\":\"NOKQTFCOC540002E\","
117             + " \"nfNamingCode\":\"gNB\" "
118             + "},"
119             + "\"pnfRegistrationFields\": {"
120             + " \"vendorName\": \"nokia\","
121             + " \"serialNumber\": \"QTFCOC540002E\","
122             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
123             + " \"modelNumber\": \"3310\","
124             + " \"unitType\": \"type\",\n"
125             + " \"unitFamily\": \"BBU\","
126             + " \"oamV4IpAddress\": \"10.16.123.234\","
127             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
128             + " \"softwareVersion\": \"v4.5.0.1\""
129             + "}}}]";
130
131         String parsed = "{\"event\": {"
132             + "\"commonEventHeader\": { "
133             + " \"sourceName\":\"NOKQTFCOC540002E\","
134             + " \"nfNamingCode\":\"gNB\" "
135             + "},"
136             + "\"pnfRegistrationFields\": {"
137             + " \"vendorName\": \"nokia\","
138             + " \"serialNumber\": \"QTFCOC540002E\","
139             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
140             + " \"modelNumber\": \"3310\","
141             + " \"unitType\": \"type\",\n"
142             + " \"unitFamily\": \"BBU\","
143             + " \"oamV4IpAddress\": \"10.16.123.234\","
144             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
145             + " \"softwareVersion\": \"v4.5.0.1\""
146             + "}}}";
147
148         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
149             .correlationId("NOKQTFCOC540002E")
150             .serialNumber("QTFCOC540002E")
151             .ipv4("10.16.123.234")
152             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
153             .equipVendor("nokia")
154             .equipModel("3310")
155             .equipType("type")
156             .nfRole("gNB")
157             .swVersion("v4.5.0.1")
158             .build();
159         //when
160         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
161         JsonElement jsonElement = new JsonParser().parse(parsed);
162         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
163             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
164         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
165             .getJsonObject(Mono.just((message))).blockFirst();
166         //then
167         Assertions.assertNotNull(consumerDmaapModel);
168         Assertions.assertEquals(expectedObject, consumerDmaapModel);
169     }
170
171     @Test
172     void whenPassingJsonWithEmptyAdditionalFields_validationNotThrowingAnException() {
173         //given
174         String message = "[{\"event\": {"
175             + "\"commonEventHeader\": { "
176             + " \"sourceName\":\"NOKQTFCOC540002E\","
177             + " \"nfNamingCode\":\"gNB\" "
178             + "},"
179             + "\"pnfRegistrationFields\": {"
180             + " \"vendorName\": \"nokia\","
181             + " \"serialNumber\": \"QTFCOC540002E\","
182             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
183             + " \"modelNumber\": \"3310\","
184             + " \"unitType\": \"type\",\n"
185             + " \"unitFamily\": \"BBU\","
186             + " \"softwareVersion\": \"v4.5.0.1\","
187             + " \"oamV4IpAddress\": \"10.16.123.234\","
188             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
189             + " \"additionalFields\": {}"
190             + "}}}]";
191
192         String parsed = "{\"event\": {"
193             + "\"commonEventHeader\": { "
194             + " \"sourceName\":\"NOKQTFCOC540002E\","
195             + " \"nfNamingCode\":\"gNB\" "
196             + "},"
197             + "\"pnfRegistrationFields\": {"
198             + " \"vendorName\": \"nokia\","
199             + " \"serialNumber\": \"QTFCOC540002E\","
200             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
201             + " \"modelNumber\": \"3310\","
202             + " \"unitType\": \"type\",\n"
203             + " \"unitFamily\": \"BBU\","
204             + " \"softwareVersion\": \"v4.5.0.1\","
205             + " \"oamV4IpAddress\": \"10.16.123.234\","
206             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
207             + " \"additionalFields\": {}"
208             + "}}}";
209
210         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
211             .correlationId("NOKQTFCOC540002E")
212             .serialNumber("QTFCOC540002E")
213             .ipv4("10.16.123.234")
214             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
215             .equipVendor("nokia")
216             .equipModel("3310")
217             .equipType("type")
218             .nfRole("gNB")
219             .swVersion("v4.5.0.1")
220             .additionalFields(new JsonObject())
221             .build();
222         //when
223         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
224         JsonElement jsonElement = new JsonParser().parse(parsed);
225         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
226             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
227         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
228             .getJsonObject(Mono.just((message))).blockFirst();
229         //then
230         Assertions.assertNotNull(consumerDmaapModel);
231         Assertions.assertEquals(expectedObject, consumerDmaapModel);
232     }
233
234     @Test
235     void whenPassingJsonWithoutMandatoryHeaderInformation_validationAddingAnException() {
236         String parsed = "{\"event\": {"
237             + "\"commonEventHeader\": {},"
238             + "\"pnfRegistrationFields\": {"
239             + " \"unitType\": \"AirScale\","
240             + " \"serialNumber\": \"QTFCOC540002E\","
241             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
242             + " \"manufactureDate\": \"1535014037024\","
243             + " \"modelNumber\": \"7BEA\",\n"
244             + " \"lastServiceDate\": \"1535014037024\","
245             + " \"unitFamily\": \"BBU\","
246             + " \"vendorName\": \"Nokia\","
247             + " \"softwareVersion\": \"v4.5.0.1\","
248             + " \"oamV4IpAddress\": \"10.16.123.234\","
249             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
250             + " \"additionalFields\": {}"
251             + "}}}";
252
253         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
254         JsonElement jsonElement = new JsonParser().parse(parsed);
255         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
256             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
257         String incorrectMessage = "[{\"event\": {"
258             + "\"commonEventHeader\": {},"
259             + "\"pnfRegistrationFields\": {"
260             + " \"unitType\": \"AirScale\","
261             + " \"serialNumber\": \"QTFCOC540002E\","
262             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
263             + " \"manufactureDate\": \"1535014037024\","
264             + " \"modelNumber\": \"7BEA\",\n"
265             + " \"lastServiceDate\": \"1535014037024\","
266             + " \"unitFamily\": \"BBU\","
267             + " \"vendorName\": \"Nokia\","
268             + " \"softwareVersion\": \"v4.5.0.1\","
269             + " \"oamV4IpAddress\": \"10.16.123.234\","
270             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
271             + " \"additionalFields\": {}"
272             + "}}}]";
273         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage)))
274             .expectSubscription().thenRequest(1).verifyComplete();
275     }
276
277     @Test
278     void whenPassingJsonWithoutSourceName_validationAddingAnException() {
279         String parsed = "{\"event\": {"
280             + "\"commonEventHeader\": {},"
281             + "\"pnfRegistrationFields\": {"
282             + " \"unitType\": \"AirScale\","
283             + " \"serialNumber\": \"QTFCOC540002E\","
284             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
285             + " \"manufactureDate\": \"1535014037024\","
286             + " \"modelNumber\": \"7BEA\",\n"
287             + " \"lastServiceDate\": \"1535014037024\","
288             + " \"unitFamily\": \"BBU\","
289             + " \"vendorName\": \"Nokia\","
290             + " \"softwareVersion\": \"v4.5.0.1\","
291             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
292             + " \"additionalFields\": {}"
293             + "}}}";
294
295         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
296         JsonElement jsonElement = new JsonParser().parse(parsed);
297         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
298             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
299         String jsonWithoutSourceName =
300             "[{\"event\": {"
301                 + "\"commonEventHeader\": {},"
302                 + "\"pnfRegistrationFields\": {"
303                 + " \"unitType\": \"AirScale\","
304                 + " \"serialNumber\": \"QTFCOC540002E\","
305                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
306                 + " \"manufactureDate\": \"1535014037024\","
307                 + " \"modelNumber\": \"7BEA\",\n"
308                 + " \"lastServiceDate\": \"1535014037024\","
309                 + " \"unitFamily\": \"BBU\","
310                 + " \"vendorName\": \"Nokia\","
311                 + " \"softwareVersion\": \"v4.5.0.1\","
312                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
313                 + " \"additionalFields\": {}"
314                 + "}}}]";
315         StepVerifier
316             .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutSourceName)))
317             .expectSubscription().thenRequest(1)
318             .verifyComplete();
319     }
320
321     @Test
322     void whenPassingJsonWithoutSourceNameValue_validationAddingAnException() {
323         String parsed =
324             "{\"event\": {"
325                 + "\"commonEventHeader\": {\"sourceName\": \"\"},"
326                 + "\"pnfRegistrationFields\": {"
327                 + " \"unitType\": \"AirScale\","
328                 + " \"serialNumber\": \"QTFCOC540002E\","
329                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
330                 + " \"manufactureDate\": \"1535014037024\","
331                 + " \"modelNumber\": \"7BEA\",\n"
332                 + " \"lastServiceDate\": \"1535014037024\","
333                 + " \"unitFamily\": \"BBU\","
334                 + " \"vendorName\": \"Nokia\","
335                 + " \"softwareVersion\": \"v4.5.0.1\","
336                 + " \"oamV4IpAddress\": \"10.16.123.234\","
337                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
338                 + " \"additionalFields\": {}"
339                 + "}}}";
340
341         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
342         JsonElement jsonElement = new JsonParser().parse(parsed);
343         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
344             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
345         String jsonWithoutIpInformation =
346             "[{\"event\": {"
347                 + "\"commonEventHeader\": {\"sourceName\": \"\"},"
348                 + "\"pnfRegistrationFields\": {"
349                 + " \"unitType\": \"AirScale\","
350                 + " \"serialNumber\": \"QTFCOC540002E\","
351                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
352                 + " \"manufactureDate\": \"1535014037024\","
353                 + " \"modelNumber\": \"7BEA\",\n"
354                 + " \"lastServiceDate\": \"1535014037024\","
355                 + " \"unitFamily\": \"BBU\","
356                 + " \"vendorName\": \"Nokia\","
357                 + " \"softwareVersion\": \"v4.5.0.1\","
358                 + " \"oamV4IpAddress\": \"10.16.123.234\","
359                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
360                 + " \"additionalFields\": {}"
361                 + "}}}]";
362         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
363             .expectSubscription().thenRequest(1).verifyComplete();
364     }
365
366     @Test
367     void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() {
368         //given
369         String message = "[{\"event\": {"
370             + "\"commonEventHeader\": { "
371             + " \"sourceName\":\"NOKQTFCOC540002E\","
372             + " \"nfNamingCode\":\"gNB\" "
373             + "},"
374             + "\"pnfRegistrationFields\": {"
375             + " \"vendorName\": \"nokia\","
376             + " \"serialNumber\": \"QTFCOC540002E\","
377             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
378             + " \"modelNumber\": \"3310\","
379             + " \"unitType\": \"type\",\n"
380             + " \"unitFamily\": \"BBU\","
381             + " \"softwareVersion\": \"v4.5.0.1\","
382             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
383             + "}}}]";
384
385         String parsed = "{\"event\": {"
386             + "\"commonEventHeader\": { "
387             + " \"sourceName\":\"NOKQTFCOC540002E\","
388             + " \"nfNamingCode\":\"gNB\" "
389             + "},"
390             + "\"pnfRegistrationFields\": {"
391             + " \"vendorName\": \"nokia\","
392             + " \"serialNumber\": \"QTFCOC540002E\","
393             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
394             + " \"modelNumber\": \"3310\","
395             + " \"unitType\": \"type\",\n"
396             + " \"unitFamily\": \"BBU\","
397             + " \"softwareVersion\": \"v4.5.0.1\","
398             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
399             + "}}}";
400
401         //when
402         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
403         JsonElement jsonElement = new JsonParser().parse(parsed);
404         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
405             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
406         dmaapConsumerJsonParser.getJsonObject(Mono.just((message)));
407         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
408             .blockFirst();
409         //then
410         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
411             .ipv4("")
412             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
413             .correlationId("NOKQTFCOC540002E")
414             .serialNumber("QTFCOC540002E")
415             .equipVendor("nokia")
416             .equipModel("3310")
417             .equipType("type")
418             .nfRole("gNB")
419             .swVersion("v4.5.0.1")
420             .build();
421         Assertions.assertNotNull(consumerDmaapModel);
422         Assertions.assertEquals(expectedObject, consumerDmaapModel);
423     }
424
425     @Test
426     void whenPassingCorrectJsonWithoutIpv6_validationNotThrowingAnException() {
427         //given
428         String message = "[{\"event\": {"
429             + "\"commonEventHeader\": { "
430             + " \"sourceName\":\"NOKQTFCOC540002E\","
431             + " \"nfNamingCode\":\"gNB\" "
432             + "},"
433             + "\"pnfRegistrationFields\": {"
434             + " \"vendorName\": \"nokia\","
435             + " \"serialNumber\": \"QTFCOC540002E\","
436             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
437             + " \"modelNumber\": \"3310\","
438             + " \"unitType\": \"type\",\n"
439             + " \"unitFamily\": \"BBU\","
440             + " \"oamV4IpAddress\": \"10.16.123.234\","
441             + " \"softwareVersion\": \"v4.5.0.1\""
442             + "}}}]";
443
444
445         String parsed = "{\"event\": {"
446             + "\"commonEventHeader\": { "
447             + " \"sourceName\":\"NOKQTFCOC540002E\","
448             + " \"nfNamingCode\":\"gNB\" "
449             + "},"
450             + "\"pnfRegistrationFields\": {"
451             + " \"vendorName\": \"nokia\","
452             + " \"serialNumber\": \"QTFCOC540002E\","
453             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
454             + " \"modelNumber\": \"3310\","
455             + " \"unitType\": \"type\",\n"
456             + " \"unitFamily\": \"BBU\","
457             + " \"oamV4IpAddress\": \"10.16.123.234\","
458             + " \"softwareVersion\": \"v4.5.0.1\""
459             + "}}}";
460
461
462         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
463             .ipv4("10.16.123.234")
464             .ipv6("")
465             .correlationId("NOKQTFCOC540002E")
466             .serialNumber("QTFCOC540002E")
467             .equipVendor("nokia")
468             .equipModel("3310")
469             .equipType("type")
470             .nfRole("gNB")
471             .swVersion("v4.5.0.1")
472             .build();
473         //when
474         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
475         JsonElement jsonElement = new JsonParser().parse(parsed);
476         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
477             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
478         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
479             .blockFirst();
480         //then
481         Assertions.assertNotNull(consumerDmaapModel);
482         Assertions.assertEquals(expectedObject, consumerDmaapModel);
483     }
484
485     @Test
486     void whenPassingCorrectJsonWithoutIpv4andIpv6_validationAddingAnException() {
487         //given
488         String message = "[{\"event\": {"
489             + "\"commonEventHeader\": { "
490             + " \"sourceName\":\"NOKQTFCOC540002E\","
491             + " \"nfNamingCode\":\"gNB\" "
492             + "},"
493             + "\"pnfRegistrationFields\": {"
494             + " \"vendorName\": \"nokia\","
495             + " \"serialNumber\": \"QTFCOC540002E\","
496             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
497             + " \"modelNumber\": \"3310\","
498             + " \"unitType\": \"type\",\n"
499             + " \"unitFamily\": \"BBU\","
500             + " \"softwareVersion\": \"v4.5.0.1\","
501             + " \"additionalFields\": {}"
502             + "}}}]";
503
504         String parsed = "{\"event\": {"
505             + "\"commonEventHeader\": { "
506             + " \"sourceName\":\"NOKQTFCOC540002E\","
507             + " \"nfNamingCode\":\"gNB\" "
508             + "},"
509             + "\"pnfRegistrationFields\": {"
510             + " \"vendorName\": \"nokia\","
511             + " \"serialNumber\": \"QTFCOC540002E\","
512             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
513             + " \"modelNumber\": \"3310\","
514             + " \"unitType\": \"type\",\n"
515             + " \"unitFamily\": \"BBU\","
516             + " \"softwareVersion\": \"v4.5.0.1\","
517             + " \"additionalFields\": {}"
518             + "}}}";
519
520         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
521         JsonElement jsonElement = new JsonParser().parse(parsed);
522         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
523             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
524         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
525             .expectSubscription().thenRequest(1).verifyComplete();
526
527     }
528
529     @Test
530     void whenPassingJsonWithoutIpInformation_validationAddingAnException() {
531         String parsed =
532             "{\"event\": {"
533                 + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
534                 + "\"pnfRegistrationFields\": {"
535                 + " \"unitType\": \"AirScale\","
536                 + " \"serialNumber\": \"QTFCOC540002E\","
537                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
538                 + " \"manufactureDate\": \"1535014037024\","
539                 + " \"modelNumber\": \"7BEA\",\n"
540                 + " \"lastServiceDate\": \"1535014037024\","
541                 + " \"unitFamily\": \"BBU\","
542                 + " \"vendorName\": \"Nokia\","
543                 + " \"softwareVersion\": \"v4.5.0.1\","
544                 + " \"oamV4IpAddress\": \"\","
545                 + " \"oamV6IpAddress\": \"\","
546                 + " \"additionalFields\": {}"
547                 + "}}}";
548
549         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
550         JsonElement jsonElement = new JsonParser().parse(parsed);
551         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
552             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
553         String jsonWithoutIpInformation =
554             "[{\"event\": {"
555                 + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
556                 + "\"pnfRegistrationFields\": {"
557                 + " \"unitType\": \"AirScale\","
558                 + " \"serialNumber\": \"QTFCOC540002E\","
559                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
560                 + " \"manufactureDate\": \"1535014037024\","
561                 + " \"modelNumber\": \"7BEA\",\n"
562                 + " \"lastServiceDate\": \"1535014037024\","
563                 + " \"unitFamily\": \"BBU\","
564                 + " \"vendorName\": \"Nokia\","
565                 + " \"softwareVersion\": \"v4.5.0.1\","
566                 + " \"oamV4IpAddress\": \"\","
567                 + " \"oamV6IpAddress\": \"\","
568                 + " \"additionalFields\": {}"
569                 + "}}}]";
570         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
571             .expectSubscription().thenRequest(1).verifyComplete();
572     }
573
574     @Test
575     void whenPassingCorrectJsoArrayWithoutIpv4_validationNotThrowingAnException() {
576         //given
577         String message = "[{\"event\": {"
578             + "\"commonEventHeader\": { "
579             + "  \"sourceName\":\"NOKQTFCOC540002E\","
580             + "  \"nfNamingCode\":\"gNB\" "
581             + "  },"
582             + "\"pnfRegistrationFields\": {"
583             + " \"vendorName\": \"nokia\","
584             + " \"serialNumber\": \"QTFCOC540002E\","
585             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
586             + " \"modelNumber\": \"3310\","
587             + " \"unitType\": \"type\",\n"
588             + " \"unitFamily\": \"BBU\","
589             + " \"softwareVersion\": \"v4.5.0.1\","
590             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
591             + " \"additionalFields\": {}"
592             + "}}},"
593             + " {\"event\": {"
594             + "\"commonEventHeader\": { "
595             + " \"sourceName\":\"NOKQTFCOC540002E\","
596             + " \"nfNamingCode\":\"gNB\" "
597             + "},"
598             + "\"pnfRegistrationFields\": {"
599             + " \"vendorName\": \"nokia\","
600             + " \"serialNumber\": \"QTFCOC540002E\","
601             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
602             + " \"modelNumber\": \"3310\","
603             + " \"unitType\": \"type\",\n"
604             + " \"unitFamily\": \"BBU\","
605             + " \"softwareVersion\": \"v4.5.0.1\","
606             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
607             + " \"additionalFields\": {}"
608             + "}}}]";
609
610         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
611             .ipv4("")
612             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
613             .correlationId("NOKQTFCOC540002E")
614             .serialNumber("QTFCOC540002E")
615             .equipVendor("nokia")
616             .equipModel("3310")
617             .equipType("type")
618             .nfRole("gNB")
619             .swVersion("v4.5.0.1")
620             .additionalFields(new JsonObject())
621             .build();
622         //when
623         DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser();
624
625         //then
626         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
627             .expectSubscription().expectNext(expectedObject).expectNext(expectedObject).verifyComplete();
628     }
629 }