diff options
author | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2019-03-08 09:48:09 +0100 |
---|---|---|
committer | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2019-03-12 10:59:06 +0100 |
commit | c69d68d5669e45c969fd1293aa76c78d55a95dca (patch) | |
tree | fee7e38468fce8a49db12cf4fb2f2b1e0cefd9c5 | |
parent | df2c17cd5619d6ca069f73342a9aaafbdf0bba59 (diff) |
Add AdditionalFields in PNF_Ready event
Enhance the PNF_Ready event with AdditionalFields contents and remove IP information
Change-Id: Iacef7e11dd104868440984a0540b2ccd31c8b036
Issue-ID: DCAEGEN2-1312
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
9 files changed, 195 insertions, 333 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 7532c5d8..295cd7ca 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 @@ -36,19 +36,19 @@ import java.util.Optional; import java.util.stream.StreamSupport; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.COMMON_EVENT_HEADER; -import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.COMMON_FORMAT; +import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.COMMON_FORMAT_FOR_STRING; +import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.COMMON_FORMAT_FOR_JSON_OBJECT; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.CORRELATION_ID; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.EQUIP_MODEL; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.EQUIP_TYPE; 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; import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.SW_VERSION; +import static org.onap.dcaegen2.services.prh.service.PnfRegistrationFields.ADDITIONAL_FIELDS; /** @@ -59,14 +59,13 @@ public class DmaapConsumerJsonParser { private static final Logger LOGGER = LoggerFactory.getLogger(DmaapConsumerJsonParser.class); private String pnfSourceName; - private String pnfOamIpv4Address; - private String pnfOamIpv6Address; - private String pnfSerialNumberAdditionalField; - private String pnfEquipVendorAdditionalField; - private String pnfEquipModelAdditionalField; - private String pnfEquipTypeAdditionalField; - private String pnfNfRoleAdditionalField; - private String pnfSwVersionAdditionalField; + private String pnfSerialNumberOptionalField; + private String pnfEquipVendorOptionalField; + private String pnfEquipModelOptionalField; + private String pnfEquipTypeOptionalField; + private String pnfNfRoleOptionalField; + private String pnfSwVersionOptionalField; + private JsonObject pnfAdditionalFields; /** * Extract info from string and create @see {@link org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel}. @@ -119,58 +118,51 @@ public class DmaapConsumerJsonParser { .getAsJsonObject(PNF_REGISTRATION_FIELDS); this.pnfSourceName = getValueFromJson(commonEventHeader, SOURCE_NAME); - this.pnfNfRoleAdditionalField = getValueFromJson(commonEventHeader, NF_ROLE); + this.pnfNfRoleOptionalField = getValueFromJson(commonEventHeader, NF_ROLE); - this.pnfOamIpv4Address = getValueFromJson(pnfRegistrationFields, OAM_IPV_4_ADDRESS); - this.pnfOamIpv6Address = getValueFromJson(pnfRegistrationFields, OAM_IPV_6_ADDRESS); - this.pnfSerialNumberAdditionalField = getValueFromJson(pnfRegistrationFields, SERIAL_NUMBER); - this.pnfEquipVendorAdditionalField = getValueFromJson(pnfRegistrationFields, EQUIP_VENDOR); - this.pnfEquipModelAdditionalField = getValueFromJson(pnfRegistrationFields, EQUIP_MODEL); - this.pnfEquipTypeAdditionalField = getValueFromJson(pnfRegistrationFields, EQUIP_TYPE); - this.pnfSwVersionAdditionalField = getValueFromJson(pnfRegistrationFields, SW_VERSION); + this.pnfSerialNumberOptionalField = getValueFromJson(pnfRegistrationFields, SERIAL_NUMBER); + this.pnfEquipVendorOptionalField = getValueFromJson(pnfRegistrationFields, EQUIP_VENDOR); + this.pnfEquipModelOptionalField = getValueFromJson(pnfRegistrationFields, EQUIP_MODEL); + this.pnfEquipTypeOptionalField = getValueFromJson(pnfRegistrationFields, EQUIP_TYPE); + this.pnfSwVersionOptionalField = getValueFromJson(pnfRegistrationFields, SW_VERSION); + this.pnfAdditionalFields = pnfRegistrationFields.getAsJsonObject(ADDITIONAL_FIELDS); - return (StringUtils.isEmpty(pnfSourceName) || !ipPropertiesNotEmpty(pnfOamIpv4Address, pnfOamIpv6Address)) + return (StringUtils.isEmpty(pnfSourceName)) ? logErrorAndReturnMonoEmpty("Incorrect json, consumerDmaapModel can not be created: " + printMessage()) : Mono.just(ImmutableConsumerDmaapModel.builder() .correlationId(pnfSourceName) - .ipv4(pnfOamIpv4Address) - .ipv6(pnfOamIpv6Address) - .serialNumber(pnfSerialNumberAdditionalField) - .equipVendor(pnfEquipVendorAdditionalField) - .equipModel(pnfEquipModelAdditionalField) - .equipType(pnfEquipTypeAdditionalField) - .nfRole(pnfNfRoleAdditionalField) - .swVersion(pnfSwVersionAdditionalField).build()); + .serialNumber(pnfSerialNumberOptionalField) + .equipVendor(pnfEquipVendorOptionalField) + .equipModel(pnfEquipModelOptionalField) + .equipType(pnfEquipTypeOptionalField) + .nfRole(pnfNfRoleOptionalField) + .swVersion(pnfSwVersionOptionalField) + .additionalFields(Optional.ofNullable(pnfAdditionalFields).orElse(new JsonObject())).build()); } private String getValueFromJson(JsonObject jsonObject, String jsonKey) { 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); } private String printMessage() { return String.format("%n{" - + "\"" + CORRELATION_ID + COMMON_FORMAT + "," - + "\"" + OAM_IPV_4_ADDRESS + COMMON_FORMAT + "," - + "\"" + OAM_IPV_6_ADDRESS + COMMON_FORMAT + "," - + "\"" + SERIAL_NUMBER + COMMON_FORMAT + "," - + "\"" + EQUIP_VENDOR + COMMON_FORMAT + "," - + "\"" + EQUIP_MODEL + COMMON_FORMAT + "," - + "\"" + EQUIP_TYPE + COMMON_FORMAT + "," - + "\"" + NF_ROLE + COMMON_FORMAT + "," - + "\"" + SW_VERSION + COMMON_FORMAT - + "%n}", this.pnfSourceName, this.pnfOamIpv4Address, this.pnfOamIpv6Address, - this.pnfSerialNumberAdditionalField, this.pnfEquipVendorAdditionalField, - this.pnfEquipModelAdditionalField, this.pnfEquipTypeAdditionalField, - this.pnfNfRoleAdditionalField, this.pnfSwVersionAdditionalField + + "\"" + CORRELATION_ID + COMMON_FORMAT_FOR_STRING + "," + + "\"" + SERIAL_NUMBER + COMMON_FORMAT_FOR_STRING + "," + + "\"" + EQUIP_VENDOR + COMMON_FORMAT_FOR_STRING + "," + + "\"" + EQUIP_MODEL + COMMON_FORMAT_FOR_STRING + "," + + "\"" + EQUIP_TYPE + COMMON_FORMAT_FOR_STRING + "," + + "\"" + NF_ROLE + COMMON_FORMAT_FOR_STRING + "," + + "\"" + SW_VERSION + COMMON_FORMAT_FOR_STRING + "," + + "\"" + ADDITIONAL_FIELDS + COMMON_FORMAT_FOR_JSON_OBJECT + + "%n}", this.pnfSourceName, + 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 a9a28c0c..696bbba6 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 @@ -23,22 +23,22 @@ package org.onap.dcaegen2.services.prh.service; class PnfRegistrationFields { - static final String COMMON_FORMAT = "\": \"%s\""; + static final String COMMON_FORMAT_FOR_STRING = "\": \"%s\""; + static final String COMMON_FORMAT_FOR_JSON_OBJECT = "\": %s"; 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"; - // additional fields + // optional fields static final String SERIAL_NUMBER = "serialNumber"; static final String EQUIP_VENDOR = "vendorName"; static final String EQUIP_MODEL = "modelNumber"; static final String EQUIP_TYPE = "unitType"; static final String NF_ROLE = "nfNamingCode"; static final String SW_VERSION = "softwareVersion"; + static final String ADDITIONAL_FIELDS = "additionalFields"; private PnfRegistrationFields() {} } 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(); - } } 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 24d89df2..de16cc59 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 @@ -30,6 +30,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; +import com.google.gson.JsonObject; import javax.net.ssl.SSLException; import org.junit.jupiter.api.Assertions; @@ -66,8 +67,6 @@ 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") @@ -75,6 +74,7 @@ class AaiProducerTaskImplTest { .equipType("type") .nfRole("role") .swVersion("v4.5.0.1") + .additionalFields(new JsonObject()) .build(); appConfig = mock(AppConfig.class); 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 87b037f1..acd4c0d3 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 @@ -28,6 +28,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.dcaegen2.services.prh.TestAppConfiguration.createDefaultDmaapConsumerConfiguration; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -59,9 +61,13 @@ class DmaapConsumerTaskImplTest { static void setUp() { dmaapConsumerConfiguration = createDefaultDmaapConsumerConfiguration(); + JsonObject jsonObject = new JsonParser().parse("{\n" + + " \"attachmentPoint\": \"bla-bla-30-3\",\n" + + " \"cvlan\": \"678\",\n" + + " \"svlan\": \"1005\"\n" + + " }").getAsJsonObject(); + consumerDmaapModel = ImmutableConsumerDmaapModel.builder() - .ipv4("10.16.123.234") - .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") .correlationId("NOKQTFCOC540002E") .serialNumber("QTFCOC540002E") .equipVendor("nokia") @@ -69,6 +75,7 @@ class DmaapConsumerTaskImplTest { .equipType("type") .nfRole("gNB") .swVersion("v4.5.0.1") + .additionalFields(jsonObject) .build(); appConfig = mock(AppConfig.class); @@ -84,9 +91,8 @@ 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 33a05772..ed0d9ba0 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 @@ -30,6 +30,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; import static org.onap.dcaegen2.services.prh.TestAppConfiguration.createDefaultDmaapPublisherConfiguration; +import com.google.gson.JsonObject; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.function.Executable; @@ -61,8 +62,6 @@ 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") @@ -70,6 +69,7 @@ class DmaapPublisherTaskImplTest { .equipType("type") .nfRole("role") .swVersion("v4.5.0.1") + .additionalFields(new JsonObject()) .build(); appConfig = mock(AppConfig.class); } 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 9abbc3b4..d8eefec1 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 @@ -20,6 +20,7 @@ package org.onap.dcaegen2.services.prh.model; +import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; import org.immutables.gson.Gson; import org.immutables.value.Value; @@ -37,12 +38,6 @@ 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(); @@ -60,4 +55,7 @@ public interface ConsumerDmaapModel extends AaiModel, DmaapModel { @SerializedName(value = "sw-version", alternate = "sw-version") String getSwVersion(); + + @SerializedName(value = "additionalFields", alternate = "additionalFields") + JsonObject getAdditionalFields(); } 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 fd628834..f04168c2 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 @@ -21,6 +21,8 @@ package org.onap.dcaegen2.services.prh.model; import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.TypeAdapterFactory; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; @@ -29,6 +31,7 @@ import java.util.ServiceLoader; public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> { + public static final String ADDITIONAL_FIELDS = "additionalFields"; /** * Method for serialization object by GSON. @@ -39,9 +42,7 @@ public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { GsonBuilder gsonBuilder = new GsonBuilder(); ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); - return gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder() - .ipv4(consumerDmaapModel.getIpv4()) - .ipv6(consumerDmaapModel.getIpv6()) + return filterOutAdditionalFieldsIfEmpty(gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder() .correlationId(consumerDmaapModel.getCorrelationId()) .serialNumber(consumerDmaapModel.getSerialNumber()) .equipVendor(consumerDmaapModel.getEquipVendor()) @@ -49,6 +50,15 @@ public class JsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> .equipType(consumerDmaapModel.getEquipType()) .nfRole(consumerDmaapModel.getNfRole()) .swVersion(consumerDmaapModel.getSwVersion()) - .build()); + .additionalFields(consumerDmaapModel.getAdditionalFields()) + .build())); + } + + private String filterOutAdditionalFieldsIfEmpty(String json) { + JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject(); + if(jsonObject.get(ADDITIONAL_FIELDS).equals(new JsonObject())) { + jsonObject.remove(ADDITIONAL_FIELDS); + } + 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 5e259a64..6b2ddf56 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 @@ -22,6 +22,8 @@ package org.onap.dcaegen2.services.prh.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.junit.jupiter.api.Test; class CommonFunctionsTest { @@ -29,59 +31,58 @@ class CommonFunctionsTest { @Test void createJsonBody_shouldReturnJsonInString() { + JsonObject jsonObject = new JsonParser().parse("{\n" + + " \"attachmentPoint\": \"bla-bla-30-3\",\n" + + " \"cvlan\": \"678\",\n" + + " \"svlan\": \"1005\"\n" + + " }").getAsJsonObject(); + 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") .equipType("cell") .nfRole("role") .swVersion("1.2.3") + .additionalFields(jsonObject) .build(); - String expectedResult = "{" + "\"correlationId\":\"NOKnhfsadhff\"," - + "\"ipaddress-v4-oam\":\"256.22.33.155\"," - + "\"ipaddress-v6-oam\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"," + "\"serial-number\":\"1234\"," + "\"equip-vendor\":\"NOKIA\"," + "\"equip-model\":\"3310\"," + "\"equip-type\":\"cell\"," + "\"nf-role\":\"role\"," - + "\"sw-version\":\"1.2.3\"" + + "\"sw-version\":\"1.2.3\"," + + "\"additionalFields\":{\"attachmentPoint\":\"bla-bla-30-3\",\"cvlan\":\"678\",\"svlan\":\"1005\"}" + "}"; assertEquals(expectedResult, new JsonBodyBuilderImpl().createJsonBody(model)); } @Test - void createJsonBodyWithEmptyAdditionalFields_shouldReturnJsonInString() { + void createJsonBodyWithEmptyOptionalPnfRegistrationFields_shouldReturnJsonInString() { 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") - .equipType("cell") - .nfRole("role") - .swVersion("1.2.3") + .serialNumber("") + .equipVendor("") + .equipModel("") + .equipType("") + .nfRole("") + .swVersion("") + .additionalFields(new JsonObject()) .build(); - String expectedResult = "{" + "\"correlationId\":\"NOKnhfsadhff\"," - + "\"ipaddress-v4-oam\":\"256.22.33.155\"," - + "\"ipaddress-v6-oam\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"," - + "\"serial-number\":\"1234\"," - + "\"equip-vendor\":\"NOKIA\"," - + "\"equip-model\":\"3310\"," - + "\"equip-type\":\"cell\"," - + "\"nf-role\":\"role\"," - + "\"sw-version\":\"1.2.3\"" + + "\"serial-number\":\"\"," + + "\"equip-vendor\":\"\"," + + "\"equip-model\":\"\"," + + "\"equip-type\":\"\"," + + "\"nf-role\":\"\"," + + "\"sw-version\":\"\"" + "}"; assertEquals(expectedResult, new JsonBodyBuilderImpl().createJsonBody(model)); |