diff options
Diffstat (limited to 'datafile-app-server/src/test')
4 files changed, 89 insertions, 55 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 d5491f5e..a9bc546f 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 @@ -27,7 +27,9 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.collectors.datafile.model.FileData; +import org.onap.dcaegen2.collectors.datafile.model.FileMetaData; import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData; +import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileMetaData; import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage; import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField; @@ -39,6 +41,7 @@ import reactor.test.StepVerifier; * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ class DmaapConsumerJsonParserTest { + private static final String NR_RADIO_ERICSSON_EVENT_NAME = "Noti_NrRadio-Ericsson_FileReady"; private static final String PRODUCT_NAME = "NrRadio"; private static final String VENDOR_NAME = "Ericsson"; private static final String LAST_EPOCH_MICROSEC = "1519837825682"; @@ -67,13 +70,14 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) .addAdditionalField(additionalField) .build(); - FileData expectedFileData = ImmutableFileData.builder() + FileMetaData fileMetaData = ImmutableFileMetaData.builder() .productName(PRODUCT_NAME) .vendorName(VENDOR_NAME) .lastEpochMicrosec(LAST_EPOCH_MICROSEC) @@ -82,6 +86,9 @@ class DmaapConsumerJsonParserTest { .timeZoneOffset(TIME_ZONE_OFFSET) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) + .build(); + FileData expectedFileData = ImmutableFileData.builder() + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(LOCATION) .compression(GZIP_COMPRESSION) @@ -101,6 +108,34 @@ class DmaapConsumerJsonParserTest { } @Test + void whenPassingCorrectJsonWithFaultyEventName_validationThrowingAnException() { + // @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() + .eventName("Faulty event name") + .changeIdentifier(CHANGE_IDENTIFIER) + .changeType(CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + // @formatter:on + String messageString = message.toString(); + String parsedString = message.getParsed(); + DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); + JsonElement jsonElement = new JsonParser().parse(parsedString); + Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(dmaapConsumerJsonParser) + .getJsonObjectFromAnArray(jsonElement); + + StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(messageString))).expectSubscription() + .expectError(DmaapNotFoundException.class).verify(); + } + + @Test void whenPassingCorrectJsonWithoutName_noFileData() { // @formatter:off AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() @@ -110,6 +145,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) @@ -137,6 +173,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) @@ -164,6 +201,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) @@ -191,6 +229,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) @@ -225,6 +264,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) @@ -232,7 +272,7 @@ class DmaapConsumerJsonParserTest { .addAdditionalField(additionalField) .build(); - FileData expectedFileData = ImmutableFileData.builder() + FileMetaData fileMetaData = ImmutableFileMetaData.builder() .productName(PRODUCT_NAME) .vendorName(VENDOR_NAME) .lastEpochMicrosec(LAST_EPOCH_MICROSEC) @@ -241,6 +281,9 @@ class DmaapConsumerJsonParserTest { .timeZoneOffset(TIME_ZONE_OFFSET) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) + .build(); + FileData expectedFileData = ImmutableFileData.builder() + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(LOCATION) .compression(GZIP_COMPRESSION) @@ -263,6 +306,7 @@ class DmaapConsumerJsonParserTest { void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() { // @formatter:off JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier("PM_MEAS_FILES_INVALID") .changeType("FileReady_INVALID") .notificationFieldsVersion("1.0_INVALID") @@ -305,6 +349,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(CHANGE_IDENTIFIER) .changeType(INCORRECT_CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) @@ -332,6 +377,7 @@ class DmaapConsumerJsonParserTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(INCORRECT_CHANGE_IDENTIFIER) .changeType(CHANGE_TYPE) .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java index 8810c921..c6d115f6 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapConsumerTaskImplTest.java @@ -36,8 +36,10 @@ import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; import org.onap.dcaegen2.collectors.datafile.exceptions.DmaapEmptyResponseException; import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.FileData; +import org.onap.dcaegen2.collectors.datafile.model.FileMetaData; import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData; +import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileMetaData; import org.onap.dcaegen2.collectors.datafile.service.DmaapConsumerJsonParser; import org.onap.dcaegen2.collectors.datafile.service.consumer.DmaapConsumerReactiveHttpClient; import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage; @@ -52,6 +54,7 @@ import reactor.test.StepVerifier; * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ class DmaapConsumerTaskImplTest { + private static final String NR_RADIO_ERICSSON_EVENT_NAME = "Noti_NrRadio-Ericsson_FileReady"; private static final String PRODUCT_NAME = "NrRadio"; private static final String VENDOR_NAME = "Ericsson"; private static final String LAST_EPOCH_MICROSEC = "8745745764578"; @@ -112,6 +115,7 @@ class DmaapConsumerTaskImplTest { .build(); JsonMessage ftpesJsonMessage = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) .changeType(FILE_READY_CHANGE_TYPE) .notificationFieldsVersion("1.0") @@ -119,7 +123,7 @@ class DmaapConsumerTaskImplTest { .build(); ftpesMessage = ftpesJsonMessage.toString(); - ftpesFileData = ImmutableFileData.builder() + FileMetaData fileMetaData = ImmutableFileMetaData.builder() .productName(PRODUCT_NAME) .vendorName(VENDOR_NAME) .lastEpochMicrosec(LAST_EPOCH_MICROSEC) @@ -128,6 +132,9 @@ class DmaapConsumerTaskImplTest { .timeZoneOffset(TIME_ZONE_OFFSET) .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) .changeType(FILE_READY_CHANGE_TYPE) + .build(); + ftpesFileData = ImmutableFileData.builder() + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(FTPES_LOCATION) .compression(GZIP_COMPRESSION) @@ -142,6 +149,7 @@ class DmaapConsumerTaskImplTest { .fileFormatVersion(FILE_FORMAT_VERSION) .build(); JsonMessage sftpJsonMessage = new JsonMessage.JsonMessageBuilder() + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) .changeType(FILE_READY_CHANGE_TYPE) .notificationFieldsVersion("1.0") @@ -149,14 +157,7 @@ class DmaapConsumerTaskImplTest { .build(); sftpMessage = sftpJsonMessage.toString(); sftpFileData = ImmutableFileData.builder() - .productName(PRODUCT_NAME) - .vendorName(VENDOR_NAME) - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) - .sourceName(SOURCE_NAME) - .startEpochMicrosec(START_EPOCH_MICROSEC) - .timeZoneOffset(TIME_ZONE_OFFSET) - .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) - .changeType(FILE_READY_CHANGE_TYPE) + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(SFTP_LOCATION) .compression(GZIP_COMPRESSION) diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImplTest.java index acd0c0bd..55fa639f 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImplTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImplTest.java @@ -37,8 +37,10 @@ import org.onap.dcaegen2.collectors.datafile.ftp.ImmutableFileServerData; import org.onap.dcaegen2.collectors.datafile.ftp.SftpClient; import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.FileData; +import org.onap.dcaegen2.collectors.datafile.model.FileMetaData; import org.onap.dcaegen2.collectors.datafile.model.ImmutableConsumerDmaapModel; import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData; +import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileMetaData; import reactor.test.StepVerifier; @@ -53,7 +55,7 @@ public class XnfCollectorTaskImplTest { private static final String SOURCE_NAME = "oteNB5309"; private static final String START_EPOCH_MICROSEC = "8745745764578"; private static final String TIME_ZONE_OFFSET = "UTC+05:00"; - private static final String PM_MEAS_CHANGE_IDINTIFIER = "PM_MEAS_FILES"; + private static final String PM_MEAS_CHANGE_IDENTIFIER = "PM_MEAS_FILES"; private static final String FILE_READY_CHANGE_TYPE = "FileReady"; private static final String FTPES_SCHEME = "ftpes://"; private static final String SFTP_SCHEME = "sftp://"; @@ -83,7 +85,18 @@ public class XnfCollectorTaskImplTest { private SftpClient sftpClientMock = mock(SftpClient.class); private RetryTimer retryTimerMock = mock(RetryTimer.class); - + // @formatter:off + private FileMetaData fileMetaData = ImmutableFileMetaData.builder() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) + .changeType(FILE_READY_CHANGE_TYPE) + .build();; + // @formatter:on @BeforeAll public static void setUpConfiguration() { @@ -99,16 +112,9 @@ public class XnfCollectorTaskImplTest { XnfCollectorTaskImpl collectorUndetTest = new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); - // @formatter:off + // @formatter:off FileData fileData = ImmutableFileData.builder() - .productName(PRODUCT_NAME) - .vendorName(VENDOR_NAME) - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) - .sourceName(SOURCE_NAME) - .startEpochMicrosec(START_EPOCH_MICROSEC) - .timeZoneOffset(TIME_ZONE_OFFSET) - .changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE) + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(FTPES_LOCATION) .compression(GZIP_COMPRESSION) @@ -160,14 +166,7 @@ public class XnfCollectorTaskImplTest { new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); // @formatter:off FileData fileData = ImmutableFileData.builder() - .productName(PRODUCT_NAME) - .vendorName(VENDOR_NAME) - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) - .sourceName(SOURCE_NAME) - .startEpochMicrosec(START_EPOCH_MICROSEC) - .timeZoneOffset(TIME_ZONE_OFFSET) - .changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE) + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(SFTP_LOCATION) .compression(GZIP_COMPRESSION) @@ -215,14 +214,7 @@ public class XnfCollectorTaskImplTest { collectorUndetTest.setRetryTimer(retryTimerMock); // @formatter:off FileData fileData = ImmutableFileData.builder() - .productName(PRODUCT_NAME) - .vendorName(VENDOR_NAME) - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) - .sourceName(SOURCE_NAME) - .startEpochMicrosec(START_EPOCH_MICROSEC) - .timeZoneOffset(TIME_ZONE_OFFSET) - .changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE) + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(FTPES_LOCATION) .compression(GZIP_COMPRESSION) @@ -256,14 +248,7 @@ public class XnfCollectorTaskImplTest { collectorUndetTest.setRetryTimer(retryTimerMock); // @formatter:off FileData fileData = ImmutableFileData.builder() - .productName(PRODUCT_NAME) - .vendorName(VENDOR_NAME) - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) - .sourceName(SOURCE_NAME) - .startEpochMicrosec(START_EPOCH_MICROSEC) - .timeZoneOffset(TIME_ZONE_OFFSET) - .changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE) + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location(FTPES_LOCATION) .compression(GZIP_COMPRESSION) @@ -313,14 +298,7 @@ public class XnfCollectorTaskImplTest { new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); // @formatter:off FileData fileData = ImmutableFileData.builder() - .productName(PRODUCT_NAME) - .vendorName(VENDOR_NAME) - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) - .sourceName(SOURCE_NAME) - .startEpochMicrosec(START_EPOCH_MICROSEC) - .timeZoneOffset(TIME_ZONE_OFFSET) - .changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE) + .fileMetaData(fileMetaData) .name(PM_FILE_NAME) .location("http://host.com/file.zip") .compression(GZIP_COMPRESSION) diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java index 8a25d72f..76c33bb4 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/JsonMessage.java @@ -27,6 +27,7 @@ import java.util.List; * */ public class JsonMessage { + private String eventName; private String changeIdentifier; private String changeType; private String notificationFieldsVersion; @@ -61,7 +62,7 @@ public class JsonMessage { + "\"commonEventHeader\":{" + "\"domain\":\"notification\"," + "\"eventId\":\"<<SerialNumber>>-reg\"," - + "\"eventName\":\"Noti_NrRadio-Ericsson_FileReady\"," + + "\"eventName\":\"" + eventName + "\"," + "\"eventType\":\"fileReady\"," + "\"internalHeaderFields\":{}," + "\"lastEpochMicrosec\":1519837825682," @@ -88,6 +89,7 @@ public class JsonMessage { } private JsonMessage(final JsonMessageBuilder builder) { + this.eventName = builder.eventName; this.changeIdentifier = builder.changeIdentifier; this.changeType = builder.changeType; this.notificationFieldsVersion = builder.notificationFieldsVersion; @@ -161,11 +163,17 @@ public class JsonMessage { } public static class JsonMessageBuilder { + private String eventName; private String changeIdentifier; private String changeType; private String notificationFieldsVersion; private List<AdditionalField> arrayOfAdditionalFields = new ArrayList<AdditionalField>(); + public JsonMessageBuilder eventName(String eventName) { + this.eventName = eventName; + return this; + } + public JsonMessageBuilder changeIdentifier(String changeIdentifier) { this.changeIdentifier = changeIdentifier; return this; @@ -227,6 +235,7 @@ public class JsonMessage { .fileFormatVersion("V10") .build(); JsonMessage message = new JsonMessage.JsonMessageBuilder() + .eventName("Noti_NrRadio-Ericsson_FileReady") .changeIdentifier("PM_MEAS_FILES") .changeType("FileReady") .notificationFieldsVersion("2.0") |