diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2018-12-10 01:37:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-12-10 01:37:54 +0000 |
commit | 289448b5c2da86c7c9255e84ea62e0b703f6117d (patch) | |
tree | e1bcd8a3babf2a813ad7368273b5f7df53bd5df2 /datafile-app-server/src/test | |
parent | 67dd4223056a2c6a56ffef34076db7dc1a2740b0 (diff) | |
parent | 03cc930719ef77373dacfbb151f11f42fc01f0ea (diff) |
Merge "Make DFC handle multiple messages from MR DMaaP" into casablanca3.0.1-ONAP1.0.5casablanca
Diffstat (limited to 'datafile-app-server/src/test')
-rw-r--r-- | datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java | 238 |
1 files changed, 191 insertions, 47 deletions
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java index b5457b82..0c483008 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParserTest.java @@ -49,17 +49,32 @@ class DmaapConsumerJsonParserTest { private static final String NOTIFICATION_FIELDS_VERSION = "1.0"; @Test - void whenPassingCorrectJson_validationNotThrowingAnException() throws DmaapNotFoundException { - AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name(PM_FILE_NAME).location(LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION) + void whenPassingCorrectJson_oneFileData() throws DmaapNotFoundException { + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) .build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) - .addAdditionalField(additionalField).build(); - FileData expectedFileData = ImmutableFileData.builder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).name(PM_FILE_NAME).location(LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); + FileData expectedFileData = ImmutableFileData.builder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); @@ -73,13 +88,91 @@ class DmaapConsumerJsonParserTest { } @Test + void whenPassingCorrectJsonWithTwoEvents_twoFileData() throws DmaapNotFoundException { + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + + FileData expectedFileData = ImmutableFileData.builder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on + String parsedString = message.getParsed(); + String messageString = "[" + parsedString + "," + parsedString + "]"; + DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser(); + + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription() + .expectNext(expectedFileData).expectNext(expectedFileData).verifyComplete(); + } + + @Test + void whenPassingCorrectJsonWithTwoEventsFirstNoHeader_oneFileDatan() throws DmaapNotFoundException { + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + + FileData expectedFileData = ImmutableFileData.builder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on + String parsedString = message.getParsed(); + String messageString = "[{\"event\":{}}," + parsedString + "]"; + DmaapConsumerJsonParser dmaapConsumerJsonParser = new DmaapConsumerJsonParser(); + + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription() + .expectNext(expectedFileData).verifyComplete(); + } + + @Test void whenPassingCorrectJsonWihoutName_noFileData() { - AdditionalField additionalField = - new JsonMessage.AdditionalFieldBuilder().location(LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) - .addAdditionalField(additionalField).build(); + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); @@ -94,12 +187,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWihoutLocation_noFileData() { - AdditionalField additionalField = - new JsonMessage.AdditionalFieldBuilder().name(PM_FILE_NAME).compression(GZIP_COMPRESSION) - .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) - .addAdditionalField(additionalField).build(); + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); @@ -114,11 +215,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWihoutCompression_noFileData() { - AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name(PM_FILE_NAME).location(LOCATION) - .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) - .addAdditionalField(additionalField).build(); + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); @@ -133,11 +243,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWihoutFileFormatType_noFileData() { - AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name(PM_FILE_NAME).location(LOCATION) - .compression(GZIP_COMPRESSION).fileFormatVersion(FILE_FORMAT_VERSION).build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) - .addAdditionalField(additionalField).build(); + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); @@ -152,18 +271,38 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingOneCorrectJsonWihoutFileFormatVersionAndOneCorrect_oneFileData() { - AdditionalField additionalFaultyField = new JsonMessage.AdditionalFieldBuilder().name(PM_FILE_NAME) - .location(LOCATION).compression(GZIP_COMPRESSION).fileFormatType(FILE_FORMAT_TYPE).build(); - AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name(PM_FILE_NAME).location(LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION) + // @formatter:off + AdditionalField additionalFaultyField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .build(); + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalFaultyField) + .addAdditionalField(additionalField) .build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) - .addAdditionalField(additionalFaultyField).addAdditionalField(additionalField).build(); - FileData expectedFileData = ImmutableFileData.builder().changeIdentifier(CHANGE_IDENTIFIER) - .changeType(CHANGE_TYPE).name(PM_FILE_NAME).location(LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); + FileData expectedFileData = ImmutableFileData.builder() + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .name(PM_FILE_NAME) + .location(LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); @@ -177,9 +316,14 @@ class DmaapConsumerJsonParserTest { } @Test - void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() { - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES_INVALID") - .changeType("FileReady_INVALID").notificationFieldsVersion("1.0_INVALID").build(); + void whenPassingJsonWithoutMandatoryHeaderInformation_noFileData() { + // @formatter:off + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier("PM_MEAS_FILES_INVALID") + .changeType("FileReady_INVALID") + .notificationFieldsVersion("1.0_INVALID") + .build(); + // @formatter:on String incorrectMessageString = message.toString(); String parsedString = message.getParsed(); @@ -189,11 +333,11 @@ class DmaapConsumerJsonParserTest { .getJsonObjectFromAnArray(jsonElement); StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString))) - .expectSubscription().expectError(DmaapNotFoundException.class).verify(); + .expectSubscription().verifyComplete(); } @Test - void whenPassingJsonWithNullJsonElement_validationThrowingAnException() { + void whenPassingJsonWithNullJsonElement_noFileData() { JsonMessage message = new JsonMessage.JsonMessageBuilder().build(); String incorrectMessageString = message.toString(); @@ -205,6 +349,6 @@ class DmaapConsumerJsonParserTest { .getJsonObjectFromAnArray(jsonElement); StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessageString))) - .expectSubscription().expectError(DmaapNotFoundException.class).verify(); + .expectSubscription().verifyComplete(); } } |