8261fcffa8bb211b829250ab58fa0e8b67f56c8a
[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             .additionalFields(new JsonObject())
159             .build();
160         //when
161         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
162         JsonElement jsonElement = new JsonParser().parse(parsed);
163         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
164             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
165         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
166             .getJsonObject(Mono.just((message))).blockFirst();
167         //then
168         Assertions.assertNotNull(consumerDmaapModel);
169         Assertions.assertEquals(expectedObject, consumerDmaapModel);
170     }
171
172     @Test
173     void whenPassingJsonWithEmptyAdditionalFields_validationNotThrowingAnException() {
174         //given
175         String message = "[{\"event\": {"
176             + "\"commonEventHeader\": { "
177             + " \"sourceName\":\"NOKQTFCOC540002E\","
178             + " \"nfNamingCode\":\"gNB\" "
179             + "},"
180             + "\"pnfRegistrationFields\": {"
181             + " \"vendorName\": \"nokia\","
182             + " \"serialNumber\": \"QTFCOC540002E\","
183             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
184             + " \"modelNumber\": \"3310\","
185             + " \"unitType\": \"type\",\n"
186             + " \"unitFamily\": \"BBU\","
187             + " \"softwareVersion\": \"v4.5.0.1\","
188             + " \"oamV4IpAddress\": \"10.16.123.234\","
189             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
190             + " \"additionalFields\": {}"
191             + "}}}]";
192
193         String parsed = "{\"event\": {"
194             + "\"commonEventHeader\": { "
195             + " \"sourceName\":\"NOKQTFCOC540002E\","
196             + " \"nfNamingCode\":\"gNB\" "
197             + "},"
198             + "\"pnfRegistrationFields\": {"
199             + " \"vendorName\": \"nokia\","
200             + " \"serialNumber\": \"QTFCOC540002E\","
201             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
202             + " \"modelNumber\": \"3310\","
203             + " \"unitType\": \"type\",\n"
204             + " \"unitFamily\": \"BBU\","
205             + " \"softwareVersion\": \"v4.5.0.1\","
206             + " \"oamV4IpAddress\": \"10.16.123.234\","
207             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
208             + " \"additionalFields\": {}"
209             + "}}}";
210
211         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
212             .correlationId("NOKQTFCOC540002E")
213             .serialNumber("QTFCOC540002E")
214             .ipv4("10.16.123.234")
215             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
216             .equipVendor("nokia")
217             .equipModel("3310")
218             .equipType("type")
219             .nfRole("gNB")
220             .swVersion("v4.5.0.1")
221             .additionalFields(new JsonObject())
222             .build();
223         //when
224         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
225         JsonElement jsonElement = new JsonParser().parse(parsed);
226         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
227             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
228         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
229             .getJsonObject(Mono.just((message))).blockFirst();
230         //then
231         Assertions.assertNotNull(consumerDmaapModel);
232         Assertions.assertEquals(expectedObject, consumerDmaapModel);
233     }
234
235     @Test
236     void whenPassingJsonWithoutMandatoryHeaderInformation_validationAddingAnException() {
237         String parsed = "{\"event\": {"
238             + "\"commonEventHeader\": {},"
239             + "\"pnfRegistrationFields\": {"
240             + " \"unitType\": \"AirScale\","
241             + " \"serialNumber\": \"QTFCOC540002E\","
242             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
243             + " \"manufactureDate\": \"1535014037024\","
244             + " \"modelNumber\": \"7BEA\",\n"
245             + " \"lastServiceDate\": \"1535014037024\","
246             + " \"unitFamily\": \"BBU\","
247             + " \"vendorName\": \"Nokia\","
248             + " \"softwareVersion\": \"v4.5.0.1\","
249             + " \"oamV4IpAddress\": \"10.16.123.234\","
250             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
251             + " \"additionalFields\": {}"
252             + "}}}";
253
254         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
255         JsonElement jsonElement = new JsonParser().parse(parsed);
256         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
257             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
258         String incorrectMessage = "[{\"event\": {"
259             + "\"commonEventHeader\": {},"
260             + "\"pnfRegistrationFields\": {"
261             + " \"unitType\": \"AirScale\","
262             + " \"serialNumber\": \"QTFCOC540002E\","
263             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
264             + " \"manufactureDate\": \"1535014037024\","
265             + " \"modelNumber\": \"7BEA\",\n"
266             + " \"lastServiceDate\": \"1535014037024\","
267             + " \"unitFamily\": \"BBU\","
268             + " \"vendorName\": \"Nokia\","
269             + " \"softwareVersion\": \"v4.5.0.1\","
270             + " \"oamV4IpAddress\": \"10.16.123.234\","
271             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
272             + " \"additionalFields\": {}"
273             + "}}}]";
274         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage)))
275             .expectSubscription().thenRequest(1).verifyComplete();
276     }
277
278     @Test
279     void whenPassingJsonWithoutSourceName_validationAddingAnException() {
280         String parsed = "{\"event\": {"
281             + "\"commonEventHeader\": {},"
282             + "\"pnfRegistrationFields\": {"
283             + " \"unitType\": \"AirScale\","
284             + " \"serialNumber\": \"QTFCOC540002E\","
285             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
286             + " \"manufactureDate\": \"1535014037024\","
287             + " \"modelNumber\": \"7BEA\",\n"
288             + " \"lastServiceDate\": \"1535014037024\","
289             + " \"unitFamily\": \"BBU\","
290             + " \"vendorName\": \"Nokia\","
291             + " \"softwareVersion\": \"v4.5.0.1\","
292             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
293             + " \"additionalFields\": {}"
294             + "}}}";
295
296         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
297         JsonElement jsonElement = new JsonParser().parse(parsed);
298         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
299             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
300         String jsonWithoutSourceName =
301             "[{\"event\": {"
302                 + "\"commonEventHeader\": {},"
303                 + "\"pnfRegistrationFields\": {"
304                 + " \"unitType\": \"AirScale\","
305                 + " \"serialNumber\": \"QTFCOC540002E\","
306                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
307                 + " \"manufactureDate\": \"1535014037024\","
308                 + " \"modelNumber\": \"7BEA\",\n"
309                 + " \"lastServiceDate\": \"1535014037024\","
310                 + " \"unitFamily\": \"BBU\","
311                 + " \"vendorName\": \"Nokia\","
312                 + " \"softwareVersion\": \"v4.5.0.1\","
313                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
314                 + " \"additionalFields\": {}"
315                 + "}}}]";
316         StepVerifier
317             .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutSourceName)))
318             .expectSubscription().thenRequest(1)
319             .verifyComplete();
320     }
321
322     @Test
323     void whenPassingJsonWithoutSourceNameValue_validationAddingAnException() {
324         String parsed =
325             "{\"event\": {"
326                 + "\"commonEventHeader\": {\"sourceName\": \"\"},"
327                 + "\"pnfRegistrationFields\": {"
328                 + " \"unitType\": \"AirScale\","
329                 + " \"serialNumber\": \"QTFCOC540002E\","
330                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
331                 + " \"manufactureDate\": \"1535014037024\","
332                 + " \"modelNumber\": \"7BEA\",\n"
333                 + " \"lastServiceDate\": \"1535014037024\","
334                 + " \"unitFamily\": \"BBU\","
335                 + " \"vendorName\": \"Nokia\","
336                 + " \"softwareVersion\": \"v4.5.0.1\","
337                 + " \"oamV4IpAddress\": \"10.16.123.234\","
338                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
339                 + " \"additionalFields\": {}"
340                 + "}}}";
341
342         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
343         JsonElement jsonElement = new JsonParser().parse(parsed);
344         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
345             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
346         String jsonWithoutIpInformation =
347             "[{\"event\": {"
348                 + "\"commonEventHeader\": {\"sourceName\": \"\"},"
349                 + "\"pnfRegistrationFields\": {"
350                 + " \"unitType\": \"AirScale\","
351                 + " \"serialNumber\": \"QTFCOC540002E\","
352                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
353                 + " \"manufactureDate\": \"1535014037024\","
354                 + " \"modelNumber\": \"7BEA\",\n"
355                 + " \"lastServiceDate\": \"1535014037024\","
356                 + " \"unitFamily\": \"BBU\","
357                 + " \"vendorName\": \"Nokia\","
358                 + " \"softwareVersion\": \"v4.5.0.1\","
359                 + " \"oamV4IpAddress\": \"10.16.123.234\","
360                 + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
361                 + " \"additionalFields\": {}"
362                 + "}}}]";
363         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
364             .expectSubscription().thenRequest(1).verifyComplete();
365     }
366
367     @Test
368     void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() {
369         //given
370         String message = "[{\"event\": {"
371             + "\"commonEventHeader\": { "
372             + " \"sourceName\":\"NOKQTFCOC540002E\","
373             + " \"nfNamingCode\":\"gNB\" "
374             + "},"
375             + "\"pnfRegistrationFields\": {"
376             + " \"vendorName\": \"nokia\","
377             + " \"serialNumber\": \"QTFCOC540002E\","
378             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
379             + " \"modelNumber\": \"3310\","
380             + " \"unitType\": \"type\",\n"
381             + " \"unitFamily\": \"BBU\","
382             + " \"softwareVersion\": \"v4.5.0.1\","
383             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
384             + "}}}]";
385
386         String parsed = "{\"event\": {"
387             + "\"commonEventHeader\": { "
388             + " \"sourceName\":\"NOKQTFCOC540002E\","
389             + " \"nfNamingCode\":\"gNB\" "
390             + "},"
391             + "\"pnfRegistrationFields\": {"
392             + " \"vendorName\": \"nokia\","
393             + " \"serialNumber\": \"QTFCOC540002E\","
394             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
395             + " \"modelNumber\": \"3310\","
396             + " \"unitType\": \"type\",\n"
397             + " \"unitFamily\": \"BBU\","
398             + " \"softwareVersion\": \"v4.5.0.1\","
399             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
400             + "}}}";
401
402         //when
403         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
404         JsonElement jsonElement = new JsonParser().parse(parsed);
405         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
406             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
407         dmaapConsumerJsonParser.getJsonObject(Mono.just((message)));
408         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
409             .blockFirst();
410         //then
411         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
412             .ipv4("")
413             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
414             .correlationId("NOKQTFCOC540002E")
415             .serialNumber("QTFCOC540002E")
416             .equipVendor("nokia")
417             .equipModel("3310")
418             .equipType("type")
419             .nfRole("gNB")
420             .swVersion("v4.5.0.1")
421             .additionalFields(new JsonObject())
422             .build();
423         Assertions.assertNotNull(consumerDmaapModel);
424         Assertions.assertEquals(expectedObject, consumerDmaapModel);
425     }
426
427     @Test
428     void whenPassingCorrectJsonWithoutIpv6_validationNotThrowingAnException() {
429         //given
430         String message = "[{\"event\": {"
431             + "\"commonEventHeader\": { "
432             + " \"sourceName\":\"NOKQTFCOC540002E\","
433             + " \"nfNamingCode\":\"gNB\" "
434             + "},"
435             + "\"pnfRegistrationFields\": {"
436             + " \"vendorName\": \"nokia\","
437             + " \"serialNumber\": \"QTFCOC540002E\","
438             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
439             + " \"modelNumber\": \"3310\","
440             + " \"unitType\": \"type\",\n"
441             + " \"unitFamily\": \"BBU\","
442             + " \"oamV4IpAddress\": \"10.16.123.234\","
443             + " \"softwareVersion\": \"v4.5.0.1\""
444             + "}}}]";
445
446
447         String parsed = "{\"event\": {"
448             + "\"commonEventHeader\": { "
449             + " \"sourceName\":\"NOKQTFCOC540002E\","
450             + " \"nfNamingCode\":\"gNB\" "
451             + "},"
452             + "\"pnfRegistrationFields\": {"
453             + " \"vendorName\": \"nokia\","
454             + " \"serialNumber\": \"QTFCOC540002E\","
455             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
456             + " \"modelNumber\": \"3310\","
457             + " \"unitType\": \"type\",\n"
458             + " \"unitFamily\": \"BBU\","
459             + " \"oamV4IpAddress\": \"10.16.123.234\","
460             + " \"softwareVersion\": \"v4.5.0.1\""
461             + "}}}";
462
463
464         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
465             .ipv4("10.16.123.234")
466             .ipv6("")
467             .correlationId("NOKQTFCOC540002E")
468             .serialNumber("QTFCOC540002E")
469             .equipVendor("nokia")
470             .equipModel("3310")
471             .equipType("type")
472             .nfRole("gNB")
473             .swVersion("v4.5.0.1")
474             .additionalFields(new JsonObject())
475             .build();
476         //when
477         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
478         JsonElement jsonElement = new JsonParser().parse(parsed);
479         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
480             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
481         ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
482             .blockFirst();
483         //then
484         Assertions.assertNotNull(consumerDmaapModel);
485         Assertions.assertEquals(expectedObject, consumerDmaapModel);
486     }
487
488     @Test
489     void whenPassingCorrectJsonWithoutIpv4andIpv6_validationAddingAnException() {
490         //given
491         String message = "[{\"event\": {"
492             + "\"commonEventHeader\": { "
493             + " \"sourceName\":\"NOKQTFCOC540002E\","
494             + " \"nfNamingCode\":\"gNB\" "
495             + "},"
496             + "\"pnfRegistrationFields\": {"
497             + " \"vendorName\": \"nokia\","
498             + " \"serialNumber\": \"QTFCOC540002E\","
499             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
500             + " \"modelNumber\": \"3310\","
501             + " \"unitType\": \"type\",\n"
502             + " \"unitFamily\": \"BBU\","
503             + " \"softwareVersion\": \"v4.5.0.1\","
504             + " \"additionalFields\": {}"
505             + "}}}]";
506
507         String parsed = "{\"event\": {"
508             + "\"commonEventHeader\": { "
509             + " \"sourceName\":\"NOKQTFCOC540002E\","
510             + " \"nfNamingCode\":\"gNB\" "
511             + "},"
512             + "\"pnfRegistrationFields\": {"
513             + " \"vendorName\": \"nokia\","
514             + " \"serialNumber\": \"QTFCOC540002E\","
515             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
516             + " \"modelNumber\": \"3310\","
517             + " \"unitType\": \"type\",\n"
518             + " \"unitFamily\": \"BBU\","
519             + " \"softwareVersion\": \"v4.5.0.1\","
520             + " \"additionalFields\": {}"
521             + "}}}";
522
523         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
524         JsonElement jsonElement = new JsonParser().parse(parsed);
525         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
526             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
527         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
528             .expectSubscription().thenRequest(1).verifyComplete();
529
530     }
531
532     @Test
533     void whenPassingJsonWithoutIpInformation_validationAddingAnException() {
534         String parsed =
535             "{\"event\": {"
536                 + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
537                 + "\"pnfRegistrationFields\": {"
538                 + " \"unitType\": \"AirScale\","
539                 + " \"serialNumber\": \"QTFCOC540002E\","
540                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
541                 + " \"manufactureDate\": \"1535014037024\","
542                 + " \"modelNumber\": \"7BEA\",\n"
543                 + " \"lastServiceDate\": \"1535014037024\","
544                 + " \"unitFamily\": \"BBU\","
545                 + " \"vendorName\": \"Nokia\","
546                 + " \"softwareVersion\": \"v4.5.0.1\","
547                 + " \"oamV4IpAddress\": \"\","
548                 + " \"oamV6IpAddress\": \"\","
549                 + " \"additionalFields\": {}"
550                 + "}}}";
551
552         DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
553         JsonElement jsonElement = new JsonParser().parse(parsed);
554         Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
555             .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
556         String jsonWithoutIpInformation =
557             "[{\"event\": {"
558                 + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
559                 + "\"pnfRegistrationFields\": {"
560                 + " \"unitType\": \"AirScale\","
561                 + " \"serialNumber\": \"QTFCOC540002E\","
562                 + " \"pnfRegistrationFieldsVersion\": \"2.0\","
563                 + " \"manufactureDate\": \"1535014037024\","
564                 + " \"modelNumber\": \"7BEA\",\n"
565                 + " \"lastServiceDate\": \"1535014037024\","
566                 + " \"unitFamily\": \"BBU\","
567                 + " \"vendorName\": \"Nokia\","
568                 + " \"softwareVersion\": \"v4.5.0.1\","
569                 + " \"oamV4IpAddress\": \"\","
570                 + " \"oamV6IpAddress\": \"\","
571                 + " \"additionalFields\": {}"
572                 + "}}}]";
573         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
574             .expectSubscription().thenRequest(1).verifyComplete();
575     }
576
577     @Test
578     void whenPassingCorrectJsoArrayWithoutIpv4_validationNotThrowingAnException() {
579         //given
580         String message = "[{\"event\": {"
581             + "\"commonEventHeader\": { "
582             + "  \"sourceName\":\"NOKQTFCOC540002E\","
583             + "  \"nfNamingCode\":\"gNB\" "
584             + "  },"
585             + "\"pnfRegistrationFields\": {"
586             + " \"vendorName\": \"nokia\","
587             + " \"serialNumber\": \"QTFCOC540002E\","
588             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
589             + " \"modelNumber\": \"3310\","
590             + " \"unitType\": \"type\",\n"
591             + " \"unitFamily\": \"BBU\","
592             + " \"softwareVersion\": \"v4.5.0.1\","
593             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
594             + " \"additionalFields\": {}"
595             + "}}},"
596             + " {\"event\": {"
597             + "\"commonEventHeader\": { "
598             + " \"sourceName\":\"NOKQTFCOC540002E\","
599             + " \"nfNamingCode\":\"gNB\" "
600             + "},"
601             + "\"pnfRegistrationFields\": {"
602             + " \"vendorName\": \"nokia\","
603             + " \"serialNumber\": \"QTFCOC540002E\","
604             + " \"pnfRegistrationFieldsVersion\": \"2.0\","
605             + " \"modelNumber\": \"3310\","
606             + " \"unitType\": \"type\",\n"
607             + " \"unitFamily\": \"BBU\","
608             + " \"softwareVersion\": \"v4.5.0.1\","
609             + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
610             + " \"additionalFields\": {}"
611             + "}}}]";
612
613         ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
614             .ipv4("")
615             .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
616             .correlationId("NOKQTFCOC540002E")
617             .serialNumber("QTFCOC540002E")
618             .equipVendor("nokia")
619             .equipModel("3310")
620             .equipType("type")
621             .nfRole("gNB")
622             .swVersion("v4.5.0.1")
623             .additionalFields(new JsonObject())
624             .build();
625         //when
626         DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser();
627
628         //then
629         StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
630             .expectSubscription().expectNext(expectedObject).expectNext(expectedObject).verifyComplete();
631     }
632 }