diff options
Diffstat (limited to 'datafile-app-server/src')
8 files changed, 636 insertions, 190 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java index 221f5cb6..1098aeed 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileData.java @@ -29,6 +29,18 @@ import org.immutables.value.Value; @Value.Immutable @Gson.TypeAdapters public interface FileData { + String productName(); + + String vendorName(); + + String lastEpochMicrosec(); + + String sourceName(); + + String startEpochMicrosec(); + + String timeZoneOffset(); + String changeIdentifier(); String changeType(); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java index 29885f99..629f3ef9 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapConsumerJsonParser.java @@ -46,6 +46,13 @@ import reactor.core.publisher.Mono; public class DmaapConsumerJsonParser { private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerJsonParser.class); + private static final String COMMON_EVENT_HEADER = "commonEventHeader"; + private static final String EVENT_NAME = "eventName"; + private static final String LAST_EPOCH_MICROSEC = "lastEpochMicrosec"; + private static final String SOURCE_NAME = "sourceName"; + private static final String START_EPOCH_MICROSEC = "startEpochMicrosec"; + private static final String TIME_ZONE_OFFSET = "timeZoneOffset"; + private static final String EVENT = "event"; private static final String NOTIFICATION_FIELDS = "notificationFields"; private static final String CHANGE_IDENTIFIER = "changeIdentifier"; @@ -103,6 +110,15 @@ public class DmaapConsumerJsonParser { private Flux<FileData> transform(JsonObject jsonObject) { if (containsHeader(jsonObject, EVENT, NOTIFICATION_FIELDS)) { + JsonObject commonEventHeader = jsonObject.getAsJsonObject(EVENT).getAsJsonObject(COMMON_EVENT_HEADER); + String eventName = getValueFromJson(commonEventHeader, EVENT_NAME); + String productName = getProductNameFromEventName(eventName); + String vendorName = getVendorNameFromEventName(eventName); + String lastEpochMicrosec = getValueFromJson(commonEventHeader, LAST_EPOCH_MICROSEC); + String sourceName = getValueFromJson(commonEventHeader, SOURCE_NAME); + String startEpochMicrosec = getValueFromJson(commonEventHeader, START_EPOCH_MICROSEC); + String timeZoneOffset = getValueFromJson(commonEventHeader, TIME_ZONE_OFFSET); + JsonObject notificationFields = jsonObject.getAsJsonObject(EVENT).getAsJsonObject(NOTIFICATION_FIELDS); String changeIdentifier = getValueFromJson(notificationFields, CHANGE_IDENTIFIER); String changeType = getValueFromJson(notificationFields, CHANGE_TYPE); @@ -111,7 +127,8 @@ public class DmaapConsumerJsonParser { if (isNotificationFieldsHeaderNotEmpty(changeIdentifier, changeType, notificationFieldsVersion) && arrayOfNamedHashMap != null && isChangeIdentifierCorrect(changeIdentifier) && isChangeTypeCorrect(changeType)) { - return getAllFileDataFromJson(changeIdentifier, changeType, arrayOfNamedHashMap); + return getAllFileDataFromJson(productName, vendorName, lastEpochMicrosec, sourceName, + startEpochMicrosec, timeZoneOffset, changeIdentifier, changeType, arrayOfNamedHashMap); } return handleJsonError(changeIdentifier, changeType, notificationFieldsVersion, arrayOfNamedHashMap, @@ -129,13 +146,15 @@ public class DmaapConsumerJsonParser { return FILE_READY_CHANGE_IDENTIFIER.equals(changeIdentifier); } - private Flux<FileData> getAllFileDataFromJson(String changeIdentifier, String changeType, - JsonArray arrayOfAdditionalFields) { + private Flux<FileData> getAllFileDataFromJson(String productName, String vendorName, String lastEpochMicrosec, + String sourceName, String startEpochMicrosec, String timeZoneOffset, String changeIdentifier, + String changeType, JsonArray arrayOfAdditionalFields) { List<FileData> res = new ArrayList<>(); for (int i = 0; i < arrayOfAdditionalFields.size(); i++) { if (arrayOfAdditionalFields.get(i) != null) { JsonObject fileInfo = (JsonObject) arrayOfAdditionalFields.get(i); - FileData fileData = getFileDataFromJson(fileInfo, changeIdentifier, changeType); + FileData fileData = getFileDataFromJson(productName, vendorName, lastEpochMicrosec, sourceName, + startEpochMicrosec, timeZoneOffset, fileInfo, changeIdentifier, changeType); if (fileData != null) { res.add(fileData); @@ -147,7 +166,9 @@ public class DmaapConsumerJsonParser { return Flux.fromIterable(res); } - private FileData getFileDataFromJson(JsonObject fileInfo, String changeIdentifier, String changeType) { + private FileData getFileDataFromJson(String productName, String vendorName, String lastEpochMicrosec, + String sourceName, String startEpochMicrosec, String timeZoneOffset, JsonObject fileInfo, + String changeIdentifier, String changeType) { logger.trace("starting to getFileDataFromJson!"); FileData fileData = null; @@ -161,13 +182,57 @@ public class DmaapConsumerJsonParser { if (isFileFormatFieldsNotEmpty(fileFormatVersion, fileFormatType) && isNameAndLocationAndCompressionNotEmpty(name, location, compression)) { - fileData = ImmutableFileData.builder().name(name).changeIdentifier(changeIdentifier).changeType(changeType) - .location(location).compression(compression).fileFormatType(fileFormatType) - .fileFormatVersion(fileFormatVersion).build(); + // @formatter:off + fileData = ImmutableFileData.builder() + .productName(productName) + .vendorName(vendorName) + .lastEpochMicrosec(lastEpochMicrosec) + .sourceName(sourceName) + .startEpochMicrosec(startEpochMicrosec) + .timeZoneOffset(timeZoneOffset) + .name(name) + .changeIdentifier(changeIdentifier) + .changeType(changeType) + .location(location) + .compression(compression) + .fileFormatType(fileFormatType) + .fileFormatVersion(fileFormatVersion) + .build(); + // @formatter:on } return fileData; } + /** + * @param eventName + * @return String of vendorName eventName is defined as: + * {DomainAbbreviation}_{productName}-{vendorName}_{Description}, example: + * Noti_RnNode-Ericsson_FileReady + */ + private String getVendorNameFromEventName(String eventName) { + String[] eventArray = eventName.split("_|-"); + if (eventArray.length >= 4) { + return eventArray[2]; + } else { + logger.trace("Can not get vendorName from eventName, eventName is not in correct format: " + eventName); + } + return ""; + } + + /** + * @param eventName + * @return String of productName + */ + private String getProductNameFromEventName(String eventName) { + String[] eventArray = eventName.split("_|-"); + if (eventArray.length >= 4) { + return eventArray[1]; + } else { + logger.trace("Can not get productName from eventName, eventName is not in correct format: " + eventName); + } + return ""; + } + private String getValueFromJson(JsonObject jsonObject, String jsonKey) { return jsonObject.has(jsonKey) ? jsonObject.get(jsonKey).getAsString() : ""; } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java index 306c2ded..75549f9b 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/XnfCollectorTaskImpl.java @@ -119,9 +119,14 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask { private FileServerData getFileServerData(URI uri) { String[] userInfo = getUserNameAndPasswordIfGiven(uri.getUserInfo()); - return ImmutableFileServerData.builder().serverAddress(uri.getHost()) - .userId(userInfo != null ? userInfo[0] : "").password(userInfo != null ? userInfo[1] : "") - .port(uri.getPort()).build(); + // @formatter:off + return ImmutableFileServerData.builder() + .serverAddress(uri.getHost()) + .userId(userInfo != null ? userInfo[0] : "") + .password(userInfo != null ? userInfo[1] : "") + .port(uri.getPort()) + .build(); + // @formatter:on } private String[] getUserNameAndPasswordIfGiven(String userInfoString) { @@ -157,13 +162,35 @@ public class XnfCollectorTaskImpl implements XnfCollectorTask { } private ConsumerDmaapModel getConsumerDmaapModel(FileData fileData, String localFile) { + String productName = fileData.productName(); + String vendorName = fileData.vendorName(); + String lastEpochMicrosec = fileData.lastEpochMicrosec(); + String sourceName = fileData.sourceName(); + String startEpochMicrosec = fileData.startEpochMicrosec(); + String timeZoneOffset = fileData.timeZoneOffset(); String name = fileData.name(); + String location = fileData.location(); + String internalLocation = localFile; String compression = fileData.compression(); String fileFormatType = fileData.fileFormatType(); String fileFormatVersion = fileData.fileFormatVersion(); - return ImmutableConsumerDmaapModel.builder().name(name).location(localFile).compression(compression) - .fileFormatType(fileFormatType).fileFormatVersion(fileFormatVersion).build(); + // @formatter:off + return ImmutableConsumerDmaapModel.builder() + .productName(productName) + .vendorName(vendorName) + .lastEpochMicrosec(lastEpochMicrosec) + .sourceName(sourceName) + .startEpochMicrosec(startEpochMicrosec) + .timeZoneOffset(timeZoneOffset) + .name(name) + .location(location) + .internalLocation(internalLocation) + .compression(compression) + .fileFormatType(fileFormatType) + .fileFormatVersion(fileFormatVersion) + .build(); + // @formatter:on } private RetryTimer getRetryTimer() { 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 167ff03a..d5491f5e 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 @@ -39,6 +39,12 @@ import reactor.test.StepVerifier; * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ class DmaapConsumerJsonParserTest { + private static final String PRODUCT_NAME = "NrRadio"; + private static final String VENDOR_NAME = "Ericsson"; + private static final String LAST_EPOCH_MICROSEC = "1519837825682"; + private static final String SOURCE_NAME = "5GRAN_DU"; + private static final String START_EPOCH_MICROSEC = "1519837825682"; + private static final String TIME_ZONE_OFFSET = "UTC+05:00"; private static final String PM_FILE_NAME = "A20161224.1030-1045.bin.gz"; private static final String LOCATION = "ftpes://192.168.0.101:22/ftp/rop/" + PM_FILE_NAME; private static final String GZIP_COMPRESSION = "gzip"; @@ -52,17 +58,37 @@ class DmaapConsumerJsonParserTest { @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) + // @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() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -76,13 +102,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithoutName_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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -96,13 +129,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithoutLocation_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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -116,12 +156,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithoutCompression_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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -135,12 +183,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithoutFileFormatType_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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -154,19 +210,44 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingOneCorrectJsonWithoutFileFormatVersionAndOneCorrect_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() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -180,9 +261,13 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingJsonWithoutMandatoryHeaderInformation_validationThrowingAnException() { - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES_INVALID") - .changeType("FileReady_INVALID").notificationFieldsVersion("1.0_INVALID").build(); - + // @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(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -212,12 +297,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithIncorrectChangeType_validationThrowingAnException() { - 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(INCORRECT_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(INCORRECT_CHANGE_TYPE) + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) + .addAdditionalField(additionalField) + .build(); + // @formatter:on String messageString = message.toString(); String parsedString = message.getParsed(); DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser()); @@ -231,12 +324,20 @@ class DmaapConsumerJsonParserTest { @Test void whenPassingCorrectJsonWithIncorrectChangeIdentifier_validationThrowingAnException() { - 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(INCORRECT_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(INCORRECT_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()); 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 43502b49..8810c921 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 @@ -52,6 +52,12 @@ import reactor.test.StepVerifier; * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ class DmaapConsumerTaskImplTest { + private static final String PRODUCT_NAME = "NrRadio"; + private static final String VENDOR_NAME = "Ericsson"; + private static final String LAST_EPOCH_MICROSEC = "8745745764578"; + 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_IDENTIFIER = "PM_MEAS_FILES"; private static final String FILE_READY_CHANGE_TYPE = "FileReady"; private static final String FTPES_SCHEME = "ftpes://"; @@ -82,42 +88,99 @@ class DmaapConsumerTaskImplTest { @BeforeAll public static void setUp() { - dmaapConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder().consumerGroup("OpenDCAE-c12") - .consumerId("c12").dmaapContentType("application/json").dmaapHostName("54.45.33.2") - .dmaapPortNumber(1234).dmaapProtocol("https").dmaapUserName("Datafile").dmaapUserPassword("Datafile") - .dmaapTopicName("unauthenticated.NOTIFICATION").timeoutMS(-1).messageLimit(-1).build(); + //@formatter:off + dmaapConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder() + .consumerGroup("OpenDCAE-c12") + .consumerId("c12") + .dmaapContentType("application/json") + .dmaapHostName("54.45.33.2") + .dmaapPortNumber(1234).dmaapProtocol("https") + .dmaapUserName("Datafile") + .dmaapUserPassword("Datafile") + .dmaapTopicName("unauthenticated.NOTIFICATION") + .timeoutMS(-1) + .messageLimit(-1) + .build(); appConfig = mock(AppConfig.class); - AdditionalField ftpesAdditionalField = - new JsonMessage.AdditionalFieldBuilder().location(FTPES_LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - JsonMessage ftpesJsonMessage = new JsonMessage.JsonMessageBuilder().changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).notificationFieldsVersion("1.0") - .addAdditionalField(ftpesAdditionalField).build(); - ftpesMessage = ftpesJsonMessage.toString(); - ftpesFileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location(FTPES_LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); - - AdditionalField sftpAdditionalField = - new JsonMessage.AdditionalFieldBuilder().location(SFTP_LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - JsonMessage sftpJsonMessage = new JsonMessage.JsonMessageBuilder().changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).notificationFieldsVersion("1.0") - .addAdditionalField(sftpAdditionalField).build(); - sftpMessage = sftpJsonMessage.toString(); - sftpFileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location(SFTP_LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); + AdditionalField ftpesAdditionalField = new JsonMessage.AdditionalFieldBuilder() + .location(FTPES_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage ftpesJsonMessage = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) + .changeType(FILE_READY_CHANGE_TYPE) + .notificationFieldsVersion("1.0") + .addAdditionalField(ftpesAdditionalField) + .build(); - ImmutableConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder().name(PM_FILE_NAME) - .location(LOCAL_FILE_LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); + ftpesMessage = ftpesJsonMessage.toString(); + ftpesFileData = 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) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + AdditionalField sftpAdditionalField = new JsonMessage.AdditionalFieldBuilder() + .location(SFTP_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + JsonMessage sftpJsonMessage = new JsonMessage.JsonMessageBuilder() + .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) + .changeType(FILE_READY_CHANGE_TYPE) + .notificationFieldsVersion("1.0") + .addAdditionalField(sftpAdditionalField) + .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) + .name(PM_FILE_NAME) + .location(SFTP_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + + ImmutableConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .internalLocation(LOCAL_FILE_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); listOfConsumerDmaapModel.add(consumerDmaapModel); + //@formatter:on } @Test diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java index c124e982..7770eec4 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DmaapPublisherTaskImplTest.java @@ -43,6 +43,12 @@ import reactor.test.StepVerifier; * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ class DmaapPublisherTaskImplTest { + private static final String PRODUCT_NAME = "NrRadio"; + private static final String VENDOR_NAME = "Ericsson"; + private static final String LAST_EPOCH_MICROSEC = "8745745764578"; + 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_FILE_NAME = "A20161224.1030-1045.bin.gz"; private static ConsumerDmaapModel consumerDmaapModel; @@ -53,13 +59,32 @@ class DmaapPublisherTaskImplTest { @BeforeAll public static void setUp() { - dmaapPublisherConfiguration = - new ImmutableDmaapPublisherConfiguration.Builder().dmaapContentType("application/json") - .dmaapHostName("54.45.33.2").dmaapPortNumber(1234).dmaapProtocol("https").dmaapUserName("DFC") - .dmaapUserPassword("DFC").dmaapTopicName("unauthenticated.VES_NOTIFICATION_OUTPUT").build(); - consumerDmaapModel = ImmutableConsumerDmaapModel.builder().name(PM_FILE_NAME).location("target/" + PM_FILE_NAME) - .compression("gzip").fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build(); + //@formatter:off + dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder() + .dmaapContentType("application/json") + .dmaapHostName("54.45.33.2") + .dmaapPortNumber(1234) + .dmaapProtocol("https") + .dmaapUserName("DFC") + .dmaapUserPassword("DFC") + .dmaapTopicName("unauthenticated.VES_NOTIFICATION_OUTPUT") + .build(); + consumerDmaapModel = ImmutableConsumerDmaapModel.builder() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .name(PM_FILE_NAME) + .location("ftpes://192.168.0.101:22/ftp/rop/" + PM_FILE_NAME) + .internalLocation("target/" + PM_FILE_NAME) + .compression("gzip") + .fileFormatType("org.3GPP.32.435#measCollec") + .fileFormatVersion("V10") + .build(); appConfig = mock(AppConfig.class); + //@formatter:on } @Test 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 8251a65a..acd0c0bd 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 @@ -47,7 +47,12 @@ import reactor.test.StepVerifier; * */ public class XnfCollectorTaskImplTest { - + private static final String PRODUCT_NAME = "NrRadio"; + private static final String VENDOR_NAME = "Ericsson"; + private static final String LAST_EPOCH_MICROSEC = "8745745764578"; + 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 FILE_READY_CHANGE_TYPE = "FileReady"; private static final String FTPES_SCHEME = "ftpes://"; @@ -91,21 +96,52 @@ public class XnfCollectorTaskImplTest { @Test public void whenFtpesFile_returnCorrectResponse() { - XnfCollectorTaskImpl collectorUndetTest = new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); - - FileData fileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location(FTPES_LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); - - FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).userId(USER) - .password(PWD).port(PORT_22).build(); + XnfCollectorTaskImpl collectorUndetTest = + 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) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + FileServerData fileServerData = ImmutableFileServerData.builder() + .serverAddress(SERVER_ADDRESS) + .userId(USER) + .password(PWD) + .port(PORT_22) + .build(); + // @formatter:on when(ftpsClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)) .thenReturn(new FileCollectResult()); - ConsumerDmaapModel expectedConsumerDmaapModel = ImmutableConsumerDmaapModel.builder().name(PM_FILE_NAME) - .location(LOCAL_FILE_LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); + // @formatter:off + ConsumerDmaapModel expectedConsumerDmaapModel = ImmutableConsumerDmaapModel.builder() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .internalLocation(LOCAL_FILE_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on StepVerifier.create(collectorUndetTest.execute(fileData)).expectNext(expectedConsumerDmaapModel) .verifyComplete(); @@ -120,22 +156,51 @@ public class XnfCollectorTaskImplTest { @Test public void whenSftpFile_returnCorrectResponse() { - XnfCollectorTaskImpl collectorUndetTest = new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); - - FileData fileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location(SFTP_LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); - - FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).userId("") - .password("").port(PORT_22).build(); + XnfCollectorTaskImpl collectorUndetTest = + 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) + .name(PM_FILE_NAME) + .location(SFTP_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + + FileServerData fileServerData = ImmutableFileServerData.builder() + .serverAddress(SERVER_ADDRESS) + .userId("") + .password("") + .port(PORT_22) + .build(); + // @formatter:on when(sftpClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)) .thenReturn(new FileCollectResult()); - - ConsumerDmaapModel expectedConsumerDmaapModel = ImmutableConsumerDmaapModel.builder().name(PM_FILE_NAME) - .location(LOCAL_FILE_LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - + // @formatter:off + ConsumerDmaapModel expectedConsumerDmaapModel = ImmutableConsumerDmaapModel.builder() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .name(PM_FILE_NAME) + .location(SFTP_LOCATION) + .internalLocation(LOCAL_FILE_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on StepVerifier.create(collectorUndetTest.execute(fileData)).expectNext(expectedConsumerDmaapModel) .verifyComplete(); @@ -145,16 +210,33 @@ public class XnfCollectorTaskImplTest { @Test public void whenFtpesFileAlwaysFail_retryAndReturnEmpty() { - XnfCollectorTaskImpl collectorUndetTest = new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); + XnfCollectorTaskImpl collectorUndetTest = + new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); collectorUndetTest.setRetryTimer(retryTimerMock); - - FileData fileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location(FTPES_LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); - - FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).userId(USER) - .password(PWD).port(PORT_22).build(); + // @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) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + FileServerData fileServerData = ImmutableFileServerData.builder() + .serverAddress(SERVER_ADDRESS) + .userId(USER) + .password(PWD) + .port(PORT_22) + .build(); + // @formatter:on ErrorData errorData = new ErrorData(); errorData.addError("Unable to collect file.", new Exception()); when(ftpsClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)) @@ -169,26 +251,54 @@ public class XnfCollectorTaskImplTest { @Test public void whenFtpesFileFailOnce_retryAndReturnCorrectResponse() { - XnfCollectorTaskImpl collectorUndetTest = new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); + XnfCollectorTaskImpl collectorUndetTest = + new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); collectorUndetTest.setRetryTimer(retryTimerMock); - - FileData fileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location(FTPES_LOCATION) - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); - - FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).userId(USER) - .password(PWD).port(PORT_22).build(); + // @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) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + FileServerData fileServerData = ImmutableFileServerData.builder() + .serverAddress(SERVER_ADDRESS) + .userId(USER) + .password(PWD) + .port(PORT_22) + .build(); + // @formatter:on ErrorData errorData = new ErrorData(); errorData.addError("Unable to collect file.", new Exception()); when(ftpsClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)) - .thenReturn(new FileCollectResult(errorData)); + .thenReturn(new FileCollectResult(errorData)); doReturn(new FileCollectResult()).when(ftpsClientMock).retryCollectFile(); - - ConsumerDmaapModel expectedConsumerDmaapModel = ImmutableConsumerDmaapModel.builder().name(PM_FILE_NAME) - .location(LOCAL_FILE_LOCATION).compression(GZIP_COMPRESSION) - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE).fileFormatVersion(FILE_FORMAT_VERSION).build(); - + // @formatter:off + ConsumerDmaapModel expectedConsumerDmaapModel = ImmutableConsumerDmaapModel.builder() + .productName(PRODUCT_NAME) + .vendorName(VENDOR_NAME) + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) + .sourceName(SOURCE_NAME) + .startEpochMicrosec(START_EPOCH_MICROSEC) + .timeZoneOffset(TIME_ZONE_OFFSET) + .name(PM_FILE_NAME) + .location(FTPES_LOCATION) + .internalLocation(LOCAL_FILE_LOCATION) + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + // @formatter:on StepVerifier.create(collectorUndetTest.execute(fileData)).expectNext(expectedConsumerDmaapModel) .verifyComplete(); @@ -199,15 +309,32 @@ public class XnfCollectorTaskImplTest { @Test public void whenWrongScheme_returnEmpty() { - XnfCollectorTaskImpl collectorUndetTest = new XnfCollectorTaskImpl(appConfigMock, ftpsClientMock, sftpClientMock); - - FileData fileData = ImmutableFileData.builder().changeIdentifier(PM_MEAS_CHANGE_IDINTIFIER) - .changeType(FILE_READY_CHANGE_TYPE).name(PM_FILE_NAME).location("http://host.com/file.zip") - .compression(GZIP_COMPRESSION).fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) - .fileFormatVersion(FILE_FORMAT_VERSION).build(); - - FileServerData fileServerData = ImmutableFileServerData.builder().serverAddress(SERVER_ADDRESS).userId("") - .password("").port(PORT_22).build(); + XnfCollectorTaskImpl collectorUndetTest = + 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) + .name(PM_FILE_NAME) + .location("http://host.com/file.zip") + .compression(GZIP_COMPRESSION) + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) + .fileFormatVersion(FILE_FORMAT_VERSION) + .build(); + + FileServerData fileServerData = ImmutableFileServerData.builder() + .serverAddress(SERVER_ADDRESS) + .userId("") + .password("") + .port(PORT_22) + .build(); + // @formatter:on when(sftpClientMock.collectFile(fileServerData, REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION)) .thenReturn(new FileCollectResult()); 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 14251406..8a25d72f 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 @@ -56,14 +56,28 @@ public class JsonMessage { } additionalFieldsString.append("]"); } - - return "{" + "\"event\":{" + "\"commonEventHeader\":{" + "\"domain\":\"notification\"," - + "\"eventId\":\"<<SerialNumber>>-reg\"," + "\"eventName\":\"EriNoti_RnNode_FileReady\"," - + "\"eventType\":\"fileReady\"," + "\"internalHeaderFields\":{}," - + "\"lastEpochMicrosec\":1519837825682," + "\"nfNamingCode\":\"5GRAN\"," + "\"nfcNamingCode\":\"5DU\"," - + "\"priority\":\"Normal\"," + "\"reportingEntityName\":\"5GRAN_DU\"," + "\"sequence\":0," - + "\"sourceId\":\"<<SerialNumber>>\"," + "\"sourceName\":\"5GRAN_DU\"," - + "\"startEpochMicrosec\":\"1519837825682\"," + "\"version\":3" + "}," + "\"notificationFields\":{" + // @formatter:off + return "{" + "\"event\":{" + + "\"commonEventHeader\":{" + + "\"domain\":\"notification\"," + + "\"eventId\":\"<<SerialNumber>>-reg\"," + + "\"eventName\":\"Noti_NrRadio-Ericsson_FileReady\"," + + "\"eventType\":\"fileReady\"," + + "\"internalHeaderFields\":{}," + + "\"lastEpochMicrosec\":1519837825682," + + "\"nfNamingCode\":\"5GRAN\"," + + "\"nfcNamingCode\":\"5DU\"," + + "\"priority\":\"Normal\"," + + "\"reportingEntityName\":\"5GRAN_DU\"," + + "\"sequence\":0," + + "\"sourceId\":\"<<SerialNumber>>\"," + + "\"sourceName\":\"5GRAN_DU\"," + + "\"timeZoneOffset\":\"UTC+05:00\"," + + "\"startEpochMicrosec\":\"1519837825682\"," + + "\"version\":3" + + "}," + + "\"notificationFields\":{" + // @formatter:on + getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier, changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0) + getAsStringIfParameterIsSet("changeType", changeType, @@ -89,8 +103,7 @@ public class JsonMessage { @Override public String toString() { - return "{" + getAsStringIfParameterIsSet("name", name, true) - + "\"hashMap\":{" + return "{" + getAsStringIfParameterIsSet("name", name, true) + "\"hashMap\":{" + getAsStringIfParameterIsSet("location", location, compression != null || fileFormatType != null || fileFormatVersion != null) + getAsStringIfParameterIsSet("compression", compression, @@ -198,16 +211,29 @@ public class JsonMessage { * @param args Not used */ public static void main(String[] args) { - AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz") - .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip") - .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build(); - AdditionalField secondAdditionalField = - new JsonMessage.AdditionalFieldBuilder().name("A20161224.1030-1045.bin.gz") - .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz").compression("gzip") - .fileFormatType("org.3GPP.32.435#measCollec").fileFormatVersion("V10").build(); - JsonMessage message = new JsonMessage.JsonMessageBuilder().changeIdentifier("PM_MEAS_FILES") - .changeType("FileReady").notificationFieldsVersion("2.0").addAdditionalField(additionalField) - .addAdditionalField(secondAdditionalField).build(); + // @formatter:off + AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() + .name("A20161224.1030-1045.bin.gz") + .location("ftpes://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") + .compression("gzip") + .fileFormatType("org.3GPP.32.435#measCollec") + .fileFormatVersion("V10") + .build(); + AdditionalField secondAdditionalField = new JsonMessage.AdditionalFieldBuilder() + .name("A20161224.1030-1045.bin.gz") + .location("sftp://192.168.0.101:22/ftp/rop/A20161224.1030-1045.bin.gz") + .compression("gzip") + .fileFormatType("org.3GPP.32.435#measCollec") + .fileFormatVersion("V10") + .build(); + JsonMessage message = new JsonMessage.JsonMessageBuilder() + .changeIdentifier("PM_MEAS_FILES") + .changeType("FileReady") + .notificationFieldsVersion("2.0") + .addAdditionalField(additionalField) + .addAdditionalField(secondAdditionalField) + .build(); + // @formatter:on System.out.println(message.toString()); } } |