summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-03-14 08:52:17 +0100
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>2019-03-14 09:37:07 +0100
commitda01e853388b3715a4da488a73a10522e90bf0ed (patch)
tree9f25184027034f47c9f3a72b266e600fe7ad7aaa
parentc69d68d5669e45c969fd1293aa76c78d55a95dca (diff)
Revert IP information removal
Change-Id: I43cdc2f2086f884df1f74dfbf999addae2019b5e Issue-ID: DCAEGEN2-1312 Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java18
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PnfRegistrationFields.java2
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParserTest.java294
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java2
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java4
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java2
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java6
-rw-r--r--prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java8
-rw-r--r--prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java4
9 files changed, 336 insertions, 4 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
index 295cd7ca..f7141581 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/DmaapConsumerJsonParser.java
@@ -44,6 +44,8 @@ import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.EQUIP
import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.EQUIP_VENDOR;
import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.EVENT;
import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.NF_ROLE;
+import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.OAM_IPV_4_ADDRESS;
+import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.OAM_IPV_6_ADDRESS;
import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.PNF_REGISTRATION_FIELDS;
import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.SERIAL_NUMBER;
import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.SOURCE_NAME;
@@ -59,6 +61,8 @@ public class DmaapConsumerJsonParser {
private static final Logger LOGGER = LoggerFactory.getLogger(DmaapConsumerJsonParser.class);
private String pnfSourceName;
+ private String pnfOamIpv4Address;
+ private String pnfOamIpv6Address;
private String pnfSerialNumberOptionalField;
private String pnfEquipVendorOptionalField;
private String pnfEquipModelOptionalField;
@@ -120,6 +124,8 @@ public class DmaapConsumerJsonParser {
this.pnfSourceName = getValueFromJson(commonEventHeader, SOURCE_NAME);
this.pnfNfRoleOptionalField = getValueFromJson(commonEventHeader, NF_ROLE);
+ this.pnfOamIpv4Address = getValueFromJson(pnfRegistrationFields, OAM_IPV_4_ADDRESS);
+ this.pnfOamIpv6Address = getValueFromJson(pnfRegistrationFields, OAM_IPV_6_ADDRESS);
this.pnfSerialNumberOptionalField = getValueFromJson(pnfRegistrationFields, SERIAL_NUMBER);
this.pnfEquipVendorOptionalField = getValueFromJson(pnfRegistrationFields, EQUIP_VENDOR);
this.pnfEquipModelOptionalField = getValueFromJson(pnfRegistrationFields, EQUIP_MODEL);
@@ -127,11 +133,13 @@ public class DmaapConsumerJsonParser {
this.pnfSwVersionOptionalField = getValueFromJson(pnfRegistrationFields, SW_VERSION);
this.pnfAdditionalFields = pnfRegistrationFields.getAsJsonObject(ADDITIONAL_FIELDS);
- return (StringUtils.isEmpty(pnfSourceName))
+ return (StringUtils.isEmpty(pnfSourceName) || !ipPropertiesNotEmpty(pnfOamIpv4Address, pnfOamIpv6Address))
? logErrorAndReturnMonoEmpty("Incorrect json, consumerDmaapModel can not be created: "
+ printMessage()) :
Mono.just(ImmutableConsumerDmaapModel.builder()
.correlationId(pnfSourceName)
+ .ipv4(pnfOamIpv4Address)
+ .ipv6(pnfOamIpv6Address)
.serialNumber(pnfSerialNumberOptionalField)
.equipVendor(pnfEquipVendorOptionalField)
.equipModel(pnfEquipModelOptionalField)
@@ -145,6 +153,10 @@ public class DmaapConsumerJsonParser {
return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : "";
}
+ private boolean ipPropertiesNotEmpty(String ipv4, String ipv6) {
+ return (!StringUtils.isEmpty(ipv4)) || !(StringUtils.isEmpty(ipv6));
+ }
+
private boolean containsHeader(JsonObject jsonObject) {
return jsonObject.has(EVENT) && jsonObject.getAsJsonObject(EVENT).has(PNF_REGISTRATION_FIELDS);
}
@@ -152,6 +164,8 @@ public class DmaapConsumerJsonParser {
private String printMessage() {
return String.format("%n{"
+ "\"" + CORRELATION_ID + COMMON_FORMAT_FOR_STRING + ","
+ + "\"" + OAM_IPV_4_ADDRESS + COMMON_FORMAT_FOR_STRING + ","
+ + "\"" + OAM_IPV_6_ADDRESS + COMMON_FORMAT_FOR_STRING + ","
+ "\"" + SERIAL_NUMBER + COMMON_FORMAT_FOR_STRING + ","
+ "\"" + EQUIP_VENDOR + COMMON_FORMAT_FOR_STRING + ","
+ "\"" + EQUIP_MODEL + COMMON_FORMAT_FOR_STRING + ","
@@ -159,7 +173,7 @@ public class DmaapConsumerJsonParser {
+ "\"" + NF_ROLE + COMMON_FORMAT_FOR_STRING + ","
+ "\"" + SW_VERSION + COMMON_FORMAT_FOR_STRING + ","
+ "\"" + ADDITIONAL_FIELDS + COMMON_FORMAT_FOR_JSON_OBJECT
- + "%n}", this.pnfSourceName,
+ + "%n}", this.pnfSourceName, this.pnfOamIpv4Address, this.pnfOamIpv6Address,
this.pnfSerialNumberOptionalField, this.pnfEquipVendorOptionalField,
this.pnfEquipModelOptionalField, this.pnfEquipTypeOptionalField,
this.pnfNfRoleOptionalField, this.pnfSwVersionOptionalField, this.pnfAdditionalFields
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PnfRegistrationFields.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PnfRegistrationFields.java
index 696bbba6..a40795b1 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PnfRegistrationFields.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/service/PnfRegistrationFields.java
@@ -28,6 +28,8 @@ class PnfRegistrationFields {
static final String EVENT = "event";
static final String COMMON_EVENT_HEADER = "commonEventHeader";
static final String PNF_REGISTRATION_FIELDS = "pnfRegistrationFields";
+ static final String OAM_IPV_4_ADDRESS = "oamV4IpAddress";
+ static final String OAM_IPV_6_ADDRESS = "oamV6IpAddress";
static final String SOURCE_NAME = "sourceName";
static final String CORRELATION_ID = "correlationId";
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 0036961f..8261fcff 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
@@ -54,7 +54,9 @@ 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\"}"
+ "}}}]";
@@ -70,7 +72,9 @@ 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\"}"
+ "}}}";
@@ -81,6 +85,8 @@ class DmaapConsumerJsonParserTest {
+ " }").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")
@@ -117,6 +123,8 @@ class DmaapConsumerJsonParserTest {
+ " \"modelNumber\": \"3310\","
+ " \"unitType\": \"type\",\n"
+ " \"unitFamily\": \"BBU\","
+ + " \"oamV4IpAddress\": \"10.16.123.234\","
+ + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"softwareVersion\": \"v4.5.0.1\""
+ "}}}]";
@@ -132,12 +140,16 @@ class DmaapConsumerJsonParserTest {
+ " \"modelNumber\": \"3310\","
+ " \"unitType\": \"type\",\n"
+ " \"unitFamily\": \"BBU\","
+ + " \"oamV4IpAddress\": \"10.16.123.234\","
+ + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"softwareVersion\": \"v4.5.0.1\""
+ "}}}";
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
.correlationId("NOKQTFCOC540002E")
.serialNumber("QTFCOC540002E")
+ .ipv4("10.16.123.234")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.equipVendor("nokia")
.equipModel("3310")
.equipType("type")
@@ -173,6 +185,8 @@ class DmaapConsumerJsonParserTest {
+ " \"unitType\": \"type\",\n"
+ " \"unitFamily\": \"BBU\","
+ " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"oamV4IpAddress\": \"10.16.123.234\","
+ + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
+ "}}}]";
@@ -189,12 +203,16 @@ class DmaapConsumerJsonParserTest {
+ " \"unitType\": \"type\",\n"
+ " \"unitFamily\": \"BBU\","
+ " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"oamV4IpAddress\": \"10.16.123.234\","
+ + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
+ "}}}";
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder()
.correlationId("NOKQTFCOC540002E")
.serialNumber("QTFCOC540002E")
+ .ipv4("10.16.123.234")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.equipVendor("nokia")
.equipModel("3310")
.equipType("type")
@@ -228,6 +246,8 @@ 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\": {}"
+ "}}}";
@@ -247,6 +267,8 @@ 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(incorrectMessage)))
@@ -267,6 +289,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
+ " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
+ "}}}";
@@ -287,6 +310,7 @@ class DmaapConsumerJsonParserTest {
+ " \"unitFamily\": \"BBU\","
+ " \"vendorName\": \"Nokia\","
+ " \"softwareVersion\": \"v4.5.0.1\","
+ + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\","
+ " \"additionalFields\": {}"
+ "}}}]";
StepVerifier
@@ -310,6 +334,8 @@ 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\": {}"
+ "}}}";
@@ -330,9 +356,277 @@ 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 whenPassingCorrectJsonWithoutIpv4_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\""
+ + "}}}]";
+
+ 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\""
+ + "}}}";
+
+ //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();
+ //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")
+ .additionalFields(new JsonObject())
+ .build();
+ Assertions.assertNotNull(consumerDmaapModel);
+ Assertions.assertEquals(expectedObject, consumerDmaapModel);
+ }
+
+ @Test
+ void whenPassingCorrectJsonWithoutIpv6_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\""
+ + "}}}]";
+
+
+ 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\""
+ + "}}}";
+
+
+ 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")
+ .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();
+ //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\","
+ + " \"additionalFields\": {}"
+ + "}}}]";
+
+ 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\","
+ + " \"additionalFields\": {}"
+ + "}}}";
+
+ 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 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\": \"\","
+ + " \"additionalFields\": {}"
+ + "}}}";
+
+ 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\": \"\","
+ + " \"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\","
+ + " \"additionalFields\": {}"
+ + "}}},"
+ + " {\"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\","
+ + " \"additionalFields\": {}"
+ + "}}}]";
+
+ 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")
+ .additionalFields(new JsonObject())
+ .build();
+ //when
+ DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser();
+
+ //then
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(message)))
+ .expectSubscription().expectNext(expectedObject).expectNext(expectedObject).verifyComplete();
+ }
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
index de16cc59..d99d4f57 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImplTest.java
@@ -67,6 +67,8 @@ class AaiProducerTaskImplTest {
clientResponse = mock(ClientResponse.class);
aaiClientConfiguration = TestAppConfiguration.createDefaultAaiClientConfiguration();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
+ .ipv4("10.16.123.234")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.correlationId("NOKQTFCOC540002E")
.serialNumber("QTFCOC540002E")
.equipVendor("nokia")
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
index acd4c0d3..02b4b465 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
@@ -68,6 +68,8 @@ class DmaapConsumerTaskImplTest {
+ " }").getAsJsonObject();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
+ .ipv4("10.16.123.234")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.correlationId("NOKQTFCOC540002E")
.serialNumber("QTFCOC540002E")
.equipVendor("nokia")
@@ -91,7 +93,9 @@ class DmaapConsumerTaskImplTest {
+ " \"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\"}"
+ "}}}]";
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
index ed0d9ba0..078c280c 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
@@ -62,6 +62,8 @@ class DmaapPublisherTaskImplTest {
static void setUp() {
dmaapPublisherConfiguration = createDefaultDmaapPublisherConfiguration();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
+ .ipv4("10.16.123.234")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.correlationId("NOKQTFCOC540002E")
.serialNumber("QTFCOC540002E")
.equipVendor("nokia")
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
index d8eefec1..f6b817ef 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java
@@ -38,6 +38,12 @@ public interface ConsumerDmaapModel extends AaiModel, DmaapModel {
@SerializedName(value = "correlationId", alternate = "correlationId")
String getCorrelationId();
+ @SerializedName(value = "ipaddress-v4-oam", alternate = "ipaddress-v4-oam")
+ String getIpv4();
+
+ @SerializedName(value = "ipaddress-v6-oam", alternate = "ipaddress-v6-oam")
+ String getIpv6();
+
@SerializedName(value = "serial-number", alternate = "serial-number")
String getSerialNumber();
diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java
index f04168c2..d031b1b5 100644
--- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java
+++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/JsonBodyBuilderImpl.java
@@ -42,7 +42,9 @@ public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel>
public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) {
GsonBuilder gsonBuilder = new GsonBuilder();
ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
- return filterOutAdditionalFieldsIfEmpty(gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder()
+ return filterOutRedundantFields(gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder()
+ .ipv4(consumerDmaapModel.getIpv4())
+ .ipv6(consumerDmaapModel.getIpv6())
.correlationId(consumerDmaapModel.getCorrelationId())
.serialNumber(consumerDmaapModel.getSerialNumber())
.equipVendor(consumerDmaapModel.getEquipVendor())
@@ -54,11 +56,13 @@ public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel>
.build()));
}
- private String filterOutAdditionalFieldsIfEmpty(String json) {
+ private String filterOutRedundantFields(String json) {
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
if(jsonObject.get(ADDITIONAL_FIELDS).equals(new JsonObject())) {
jsonObject.remove(ADDITIONAL_FIELDS);
}
+ jsonObject.remove("ipaddress-v4-oam");
+ jsonObject.remove("ipaddress-v6-oam");
return jsonObject.toString();
}
} \ No newline at end of file
diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
index 6b2ddf56..8622a169 100644
--- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
+++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/model/CommonFunctionsTest.java
@@ -39,6 +39,8 @@ class CommonFunctionsTest {
ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder()
.correlationId("NOKnhfsadhff")
+ .ipv4("256.22.33.155")
+ .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334")
.serialNumber("1234")
.equipVendor("NOKIA")
.equipModel("3310")
@@ -66,6 +68,8 @@ class CommonFunctionsTest {
void createJsonBodyWithEmptyOptionalPnfRegistrationFields_shouldReturnJsonInString() {
ConsumerDmaapModel model = ImmutableConsumerDmaapModel.builder()
.correlationId("NOKnhfsadhff")
+ .ipv4("256.22.33.155")
+ .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334")
.serialNumber("")
.equipVendor("")
.equipModel("")