diff options
Diffstat (limited to 'prh-app-server/src/test/java/org')
2 files changed, 215 insertions, 155 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 cc2a593f..8cf7bcec 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 @@ -42,29 +42,37 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJson_validationNotThrowingAnException() { //given - String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" - + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":" - + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400" - + ",\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" - + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":" - + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":" - + "\"Nokia\"}}}]"; - String parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":" - + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":" - + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" - + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":" - + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":" - + "\"Nokia\"}}}"; + String message = "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}]"; + + String parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}"; + ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234") .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") .pnfName("NOKQTFCOC540002E").build(); @@ -83,27 +91,31 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() { //given - String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" - + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}" - + ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv6Address\":" - + "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\"" - + ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]"; + String message = "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\",\"modelNumber\":\"7BEA\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\",\"vendorName\":\"Nokia\"" + + "}}]"; - String parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}" - + ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400," - + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv6Address\":" - + "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\"" - + ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}"; + String parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}"; //when DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -122,28 +134,35 @@ class DmaapConsumerJsonParserTest { } @Test - void whenPassingCorrectJsonWihoutIpv6_validationNotThrowingAnException() { + void whenPassingCorrectJsonWithoutIpv6_validationNotThrowingAnException() { //given - String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" - + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682," - + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate" - + "\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address" - + "\":\"10.16.123.234\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\"," - + "\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]"; - String parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682," - + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate" - + "\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address" - + "\":\"10.16.123.234\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\"," - + "\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}"; + String message = "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}]"; + + String parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}"; ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234").ipv6("") .pnfName("NOKQTFCOC540002E").build(); @@ -160,25 +179,33 @@ class DmaapConsumerJsonParserTest { } @Test - void whenPassingCorrectJsonWihoutIpv4andIpv6_validationThrowingAnException() { - String message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" - + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" - + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" - + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSoftwareVersion\":" - + "\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]"; - String parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" - + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" - + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSoftwareVersion\":" - + "\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}"; + void whenPassingCorrectJsonWithoutIpv4andIpv6_validationThrowingAnException() { + String message = "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}]"; + + String parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}"; + DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) @@ -190,82 +217,107 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() { - String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"" - + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\"" - + ":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\"," - + "\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}}}"; + String parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"" + + "}}"; + DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - String incorrectMessage = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"" - + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":" - + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3" - + "}}}]"; + String incorrectMessage = "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"1517206400\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"" + + "}}]"; StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage))) .expectSubscription().expectError(DmaapNotFoundException.class).verify(); } @Test - void whenPassingJsonWithoutPnfSerialNumberOrPnfVendorName_validationThrowingAnException() { - String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":" - + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"" - + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\"," - + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0," - + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"" - + "version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" - + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" - + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":" - + "\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}"; + void whenPassingJsonWithoutSerialNumberOrVendorName_validationThrowingAnException() { + String parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"" + + "}}"; + DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); JsonElement jsonElement = new JsonParser().parse(parsed); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())) .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement); - String jsonWithoutPnfVendorAndSerialNumber = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":" - + "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"" - + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\"," - + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0," - + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682," - + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\"," - + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\"," - + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," - + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}]"; + String jsonWithoutVendorAndSerialNumber = + "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"" + + "}}]"; StepVerifier - .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutPnfVendorAndSerialNumber))) + .create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutVendorAndSerialNumber))) .expectSubscription().expectError(DmaapNotFoundException.class).verify(); } @Test void whenPassingJsonWithoutIpInformation_validationThrowingAnException() { String parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" - + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" - + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":" - + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":" - + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":" - + "\"AirScale\"," + "\"pnfVendorName\":\"Nokia\"}}}"; + "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}"; + 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\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" - + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" - + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\"" - + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSerialNumber\"" - + ":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"," - + "\"pnfVendorName\":\"Nokia\"}}}]"; + "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}]"; StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation))) .expectSubscription().expectError(DmaapNotFoundException.class).verify(); } 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 6baa7463..c8676c7c 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 @@ -69,28 +69,36 @@ class DmaapConsumerTaskImplTest { .ipv6("0:0:0:0:0:FFFF:0A10:7BEA") .pnfName("NOKQTFCOC540002E").build(); appConfig = mock(AppConfig.class); - message = - "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\"" - + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\"" - + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":" - + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":" - + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":" - + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":" - + "\"Nokia\"}}}]"; - parsed = - "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\"" - + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":" - + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682," - + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\"," - + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\"," - + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," - + "\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"," - + "\"pnfVendorName\":\"Nokia\"}}}"; + + message = "[{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}]"; + + parsed = "{\"pnfRegistrationFields\":{" + + "\"lastServiceDate\":\"1517206400\"," + + "\"macAddress\":\"FFFF:0A10:7BEA\"," + + "\"manufactureDate\":\"1517206400\"," + + "\"modelNumber\":\"7BEA\"," + + "\"oamV4IpAddress\":\"10.16.123.234\"," + + "\"oamV6IpAddress\":\"0:0:0:0:0:FFFF:0A10:7BEA\"," + + "\"pnfRegistrationFieldsVersion\":\"1517206400\"," + + "\"serialNumber\":\"QTFCOC540002E\"," + + "\"softwareVersion\":\"v4.5.0.1\"," + + "\"unitFamily\":\"BBU\"," + + "\"unitType\":\"AirScale\"," + + "\"vendorName\":\"Nokia\"" + + "}}"; } @Test |