aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java339
1 files changed, 97 insertions, 242 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
index 44651a54..0036961f 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java
@@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.prh.service;
import static org.mockito.Mockito.spy;
import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.util.Optional;
import org.junit.jupiter.api.Assertions;
@@ -53,9 +54,8 @@ class DmaapConsumerJsonParserTest {
+ " \"modelNumber\": \"3310\","
+ " \"unitType\": \"type\",\n"
+ " \"unitFamily\": \"BBU\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ + " \"additionalFields\": {\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}"
+ "}}}]";
String parsed = "{\"event\": {"
@@ -70,14 +70,17 @@ class DmaapConsumerJsonParserTest {
+ " \"modelNumber\": \"3310\","
+ " \"unitType\": \"type\",\n"
+ " \"unitFamily\": \"BBU\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
+ " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ + " \"additionalFields\": {\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}"
+ "}}}";
+ JsonObject jsonObject = new JsonParser().parse("{\n"
+ + " \"attachmentPoint\": \"bla-bla-30-3\",\n"
+ + " \"cvlan\": \"678\",\n"
+ + " \"svlan\": \"1005\"\n"
+ + " }").getAsJsonObject();
+
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
- .ipv4("10.16.123.234")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.correlationId("NOKQTFCOC540002E")
.serialNumber("QTFCOC540002E")
.equipVendor("nokia")
@@ -85,6 +88,7 @@ class DmaapConsumerJsonParserTest {
.equipType("type")
.nfRole("gNB")
.swVersion("v4.5.0.1")
+ .additionalFields(jsonObject)
.build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -99,167 +103,118 @@ class DmaapConsumerJsonParserTest {
}
@Test
- void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() {
+ void whenPassingJsonWithoutAdditionalFields_validationNotThrowingAnException() {
//given
String message = "[{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
- + "}}}]";
+ + "\"commonEventHeader\": { "
+ + " \"sourceName\":\"NOKQTFCOC540002E\","
+ + " \"nfNamingCode\":\"gNB\" "
+ + "},"
+ + "\"pnfRegistrationFields\": {"
+ + " \"vendorName\": \"nokia\","
+ + " \"serialNumber\": \"QTFCOC540002E\","
+ + " \"pnfRegistrationFieldsVersion\": \"2.0\","
+ + " \"modelNumber\": \"3310\","
+ + " \"unitType\": \"type\",\n"
+ + " \"unitFamily\": \"BBU\","
+ + " \"softwareVersion\": \"v4.5.0.1\""
+ + "}}}]";
String parsed = "{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
- + "}}}";
+ + "\"commonEventHeader\": { "
+ + " \"sourceName\":\"NOKQTFCOC540002E\","
+ + " \"nfNamingCode\":\"gNB\" "
+ + "},"
+ + "\"pnfRegistrationFields\": {"
+ + " \"vendorName\": \"nokia\","
+ + " \"serialNumber\": \"QTFCOC540002E\","
+ + " \"pnfRegistrationFieldsVersion\": \"2.0\","
+ + " \"modelNumber\": \"3310\","
+ + " \"unitType\": \"type\",\n"
+ + " \"unitFamily\": \"BBU\","
+ + " \"softwareVersion\": \"v4.5.0.1\""
+ + "}}}";
+ ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
+ .correlationId("NOKQTFCOC540002E")
+ .serialNumber("QTFCOC540002E")
+ .equipVendor("nokia")
+ .equipModel("3310")
+ .equipType("type")
+ .nfRole("gNB")
+ .swVersion("v4.5.0.1")
+ .additionalFields(new JsonObject())
+ .build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsed);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- dmaapConsumerJsonParser.getJsonObject(Mono.just((message)));
- ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
- .blockFirst();
+ ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
+ .getJsonObject(Mono.just((message))).blockFirst();
//then
- ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
- .ipv4("")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .correlationId("NOKQTFCOC540002E")
- .serialNumber("QTFCOC540002E")
- .equipVendor("nokia")
- .equipModel("3310")
- .equipType("type")
- .nfRole("gNB")
- .swVersion("v4.5.0.1")
- .build();
Assertions.assertNotNull(consumerDmaapModel);
Assertions.assertEquals(expectedObject, consumerDmaapModel);
}
@Test
- void whenPassingCorrectJsonWithoutIpv6_validationNotThrowingAnException() {
+ void whenPassingJsonWithEmptyAdditionalFields_validationNotThrowingAnException() {
//given
String message = "[{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
- + " \"softwareVersion\": \"v4.5.0.1\""
- + "}}}]";
-
+ + "\"commonEventHeader\": { "
+ + " \"sourceName\":\"NOKQTFCOC540002E\","
+ + " \"nfNamingCode\":\"gNB\" "
+ + "},"
+ + "\"pnfRegistrationFields\": {"
+ + " \"vendorName\": \"nokia\","
+ + " \"serialNumber\": \"QTFCOC540002E\","
+ + " \"pnfRegistrationFieldsVersion\": \"2.0\","
+ + " \"modelNumber\": \"3310\","
+ + " \"unitType\": \"type\",\n"
+ + " \"unitFamily\": \"BBU\","
+ + " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"additionalFields\": {}"
+ + "}}}]";
String parsed = "{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
- + " \"softwareVersion\": \"v4.5.0.1\""
- + "}}}";
-
+ + "\"commonEventHeader\": { "
+ + " \"sourceName\":\"NOKQTFCOC540002E\","
+ + " \"nfNamingCode\":\"gNB\" "
+ + "},"
+ + "\"pnfRegistrationFields\": {"
+ + " \"vendorName\": \"nokia\","
+ + " \"serialNumber\": \"QTFCOC540002E\","
+ + " \"pnfRegistrationFieldsVersion\": \"2.0\","
+ + " \"modelNumber\": \"3310\","
+ + " \"unitType\": \"type\",\n"
+ + " \"unitFamily\": \"BBU\","
+ + " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"additionalFields\": {}"
+ + "}}}";
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
- .ipv4("10.16.123.234")
- .ipv6("")
- .correlationId("NOKQTFCOC540002E")
- .serialNumber("QTFCOC540002E")
- .equipVendor("nokia")
- .equipModel("3310")
- .equipType("type")
- .nfRole("gNB")
- .swVersion("v4.5.0.1")
- .build();
+ .correlationId("NOKQTFCOC540002E")
+ .serialNumber("QTFCOC540002E")
+ .equipVendor("nokia")
+ .equipModel("3310")
+ .equipType("type")
+ .nfRole("gNB")
+ .swVersion("v4.5.0.1")
+ .additionalFields(new JsonObject())
+ .build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsed);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
- .blockFirst();
+ ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser
+ .getJsonObject(Mono.just((message))).blockFirst();
//then
Assertions.assertNotNull(consumerDmaapModel);
Assertions.assertEquals(expectedObject, consumerDmaapModel);
}
@Test
- void whenPassingCorrectJsonWithoutIpv4andIpv6_validationAddingAnException() {
- //given
- String message = "[{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\""
- + "}}}]";
-
- String parsed = "{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\""
- + "}}}";
-
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
- .expectSubscription().thenRequest(1).verifyComplete();
-
- }
-
- @Test
void whenPassingJsonWithoutMandatoryHeaderInformation_validationAddingAnException() {
String parsed = "{\"event\": {"
+ "\"commonEventHeader\": {},"
@@ -272,7 +227,8 @@ class DmaapConsumerJsonParserTest {
+ " \"lastServiceDate\": \"1535014037024\","
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
- + " \"softwareVersion\": \"v4.5.0.1\""
+ + " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"additionalFields\": {}"
+ "}}}";
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -290,7 +246,8 @@ class DmaapConsumerJsonParserTest {
+ " \"lastServiceDate\": \"1535014037024\","
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
- + " \"softwareVersion\": \"v4.5.0.1\""
+ + " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"additionalFields\": {}"
+ "}}}]";
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage)))
.expectSubscription().thenRequest(1).verifyComplete();
@@ -310,7 +267,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
+ " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ + " \"additionalFields\": {}"
+ "}}}";
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -330,7 +287,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
+ " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ + " \"additionalFields\": {}"
+ "}}}]";
StepVerifier
.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutSourceName)))
@@ -339,49 +296,6 @@ class DmaapConsumerJsonParserTest {
}
@Test
- void whenPassingJsonWithoutIpInformation_validationAddingAnException() {
- String parsed =
- "{\"event\": {"
- + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
- + "\"pnfRegistrationFields\": {"
- + " \"unitType\": \"AirScale\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"manufactureDate\": \"1535014037024\","
- + " \"modelNumber\": \"7BEA\",\n"
- + " \"lastServiceDate\": \"1535014037024\","
- + " \"unitFamily\": \"BBU\","
- + " \"vendorName\": \"Nokia\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV4IpAddress\": \"\","
- + " \"oamV6IpAddress\": \"\""
- + "}}}";
-
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String jsonWithoutIpInformation =
- "[{\"event\": {"
- + "\"commonEventHeader\": {\"sourceName\": \"NOKQTFCOC540002E\"},"
- + "\"pnfRegistrationFields\": {"
- + " \"unitType\": \"AirScale\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"manufactureDate\": \"1535014037024\","
- + " \"modelNumber\": \"7BEA\",\n"
- + " \"lastServiceDate\": \"1535014037024\","
- + " \"unitFamily\": \"BBU\","
- + " \"vendorName\": \"Nokia\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV4IpAddress\": \"\","
- + " \"oamV6IpAddress\": \"\""
- + "}}}]";
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
- .expectSubscription().thenRequest(1).verifyComplete();
- }
-
- @Test
void whenPassingJsonWithoutSourceNameValue_validationAddingAnException() {
String parsed =
"{\"event\": {"
@@ -396,8 +310,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
+ " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ + " \"additionalFields\": {}"
+ "}}}";
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
@@ -417,67 +330,9 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
+ " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ + " \"additionalFields\": {}"
+ "}}}]";
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
.expectSubscription().thenRequest(1).verifyComplete();
}
-
- @Test
- void whenPassingCorrectJsoArrayWithoutIpv4_validationNotThrowingAnException() {
- //given
- String message = "[{\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + " },"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
- + "}}},"
- + " {\"event\": {"
- + "\"commonEventHeader\": { "
- + " \"sourceName\":\"NOKQTFCOC540002E\","
- + " \"nfNamingCode\":\"gNB\" "
- + "},"
- + "\"pnfRegistrationFields\": {"
- + " \"vendorName\": \"nokia\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"modelNumber\": \"3310\","
- + " \"unitType\": \"type\",\n"
- + " \"unitFamily\": \"BBU\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
- + "}}}]";
-
-
-
-
-
- ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
- .ipv4("")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .correlationId("NOKQTFCOC540002E")
- .serialNumber("QTFCOC540002E")
- .equipVendor("nokia")
- .equipModel("3310")
- .equipType("type")
- .nfRole("gNB")
- .swVersion("v4.5.0.1")
- .build();
- //when
- DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser();
-
- //then
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
- .expectSubscription().expectNext(expectedObject).expectNext(expectedObject).verifyComplete();
- }
}