X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=datafilecollector%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fdcaegen2%2Fcollectors%2Fdatafile%2FMockDatafile.java;h=30a7975150fe2a37af79f9cf1c6844d7aa328150;hb=7e6809152a93be1621eca57bf8776dbbb11807a5;hp=16a36c0652783dd2235f9d9e06388e769117c165;hpb=6dfbff6834c3a9da2d8f06b15eb94048cbad2d88;p=nonrtric%2Fplt%2Franpm.git diff --git a/datafilecollector/src/test/java/org/onap/dcaegen2/collectors/datafile/MockDatafile.java b/datafilecollector/src/test/java/org/onap/dcaegen2/collectors/datafile/MockDatafile.java index 16a36c0..30a7975 100644 --- a/datafilecollector/src/test/java/org/onap/dcaegen2/collectors/datafile/MockDatafile.java +++ b/datafilecollector/src/test/java/org/onap/dcaegen2/collectors/datafile/MockDatafile.java @@ -26,14 +26,15 @@ import static org.awaitility.Awaitility.await; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -54,16 +55,18 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.context.annotation.Bean; import org.springframework.test.context.TestPropertySource; +import org.springframework.util.FileSystemUtils; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT) -@TestPropertySource(properties = { // +@TestPropertySource( + properties = { // "app.ssl.key-store-password-file=./config/ftps_keystore.pass", // "app.ssl.key-store=./config/ftps_keystore.p12", // "app.ssl.trust-store-password-file=./config/truststore.pass", // @@ -75,7 +78,7 @@ import reactor.core.publisher.Mono; "app.s3.accessKeyId=minio", // "app.s3.secretAccessKey=miniostorage", // "app.s3.bucket=ropfiles", // - "app.s3.locksBucket=locks" }) + "app.s3.locksBucket=locks"}) @SuppressWarnings("squid:S3577") // Not containing any tests since it is a mock. class MockDatafile { @@ -86,8 +89,10 @@ class MockDatafile { private static final String PM_FILE_NAME = "PM_FILE_NAME"; // This can be any downloadable file on the net - private static final String FTPES_LOCATION = "ftpes:// onap:pano@ftp-ftpes-6:2021/A20000626.2315+0200-2330+0200_GNODEB-15-4.xml.gz"; - private static final String LOCATION = "https://launchpad.net/ubuntu/+source/perf-tools-unstable/1.0+git7ffb3fd-1ubuntu1/+build/13630748/+files/perf-tools-unstable_1.0+git7ffb3fd-1ubuntu1_all.deb"; + private static final String FTPES_LOCATION = + "ftpes:// onap:pano@ftp-ftpes-6:2021/A20000626.2315+0200-2330+0200_GNODEB-15-4.xml.gz"; + private static final String LOCATION = + "https://launchpad.net/ubuntu/+source/perf-tools-unstable/1.0+git7ffb3fd-1ubuntu1/+build/13630748/+files/perf-tools-unstable_1.0+git7ffb3fd-1ubuntu1_all.deb"; private static final String GZIP_COMPRESSION = "gzip"; private static final String FILE_FORMAT_TYPE = "org.3GPP.32.435#measCollec"; private static final String FILE_FORMAT_VERSION = "V10"; @@ -96,8 +101,8 @@ class MockDatafile { private static final Logger logger = LoggerFactory.getLogger(MockDatafile.class); private static Gson gson = new GsonBuilder() // - .disableHtmlEscaping() // - .create(); // + .disableHtmlEscaping() // + .create(); // @LocalServerPort private int port; @@ -123,13 +128,13 @@ class MockDatafile { // Create a listener to the output topic. The KafkaTopicListener happens to be // suitable for that, - KafkaTopicListener topicListener = new KafkaTopicListener(applicationConfig.getKafkaBootStrapServers(), - "MockDatafile", outputTopic); + KafkaTopicListener topicListener = + new KafkaTopicListener(applicationConfig.getKafkaBootStrapServers(), "MockDatafile", outputTopic); topicListener.getFlux() // - .doOnNext(this::set) // - .doFinally(sig -> logger.info("Finally " + sig)) // - .subscribe(); + .doOnNext(this::set) // + .doFinally(sig -> logger.info("Finally " + sig)) // + .subscribe(); } private void set(DataFromTopic receivedKafkaOutput) { @@ -166,10 +171,10 @@ class MockDatafile { FilePublishInformation i = fc.createFilePublishInformation(fileData); try { - File from = new File("config/application.yaml"); - File to = new File(this.appConfig.collectedFilesPath + "/" + fileData.name()); - FileUtils.forceMkdirParent(to); - com.google.common.io.Files.copy(from, to); + Path from = Path.of("config/application.yaml"); + Path to = Path.of(this.appConfig.collectedFilesPath, fileData.name()); + Files.createDirectories(to.getParent()); + Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { logger.error("Could not copy file {}", e.getMessage()); } @@ -219,9 +224,8 @@ class MockDatafile { } private void deleteAllFiles() { - try { - FileUtils.deleteDirectory(new File(this.appConfig.collectedFilesPath)); + FileSystemUtils.deleteRecursively(Path.of(this.appConfig.collectedFilesPath)); } catch (IOException e) { } } @@ -259,10 +263,10 @@ class MockDatafile { Instant startTime = Instant.now(); Flux.range(1, NO_OF_OBJECTS) // - .map(i -> gson.toJson(fileReadyMessage("testS3Concurrency_" + i))) // - .flatMap(fileReadyMessage -> scheduledTask.sendDataToStream(appConfig.fileReadyEventTopic, "key", - fileReadyMessage)) // - .blockLast(); // + .map(i -> gson.toJson(fileReadyMessage("testS3Concurrency_" + i))) // + .flatMap(fileReadyMessage -> scheduledTask.sendDataToStream(appConfig.fileReadyEventTopic, "key", + fileReadyMessage)) // + .blockLast(); // while (kafkaReceiver.count < NO_OF_OBJECTS) { logger.info("sleeping {}", kafkaReceiver.count); @@ -292,45 +296,45 @@ class MockDatafile { FileReadyMessage.Event event(String fileName) { MessageMetaData messageMetaData = MessageMetaData.builder() // - .lastEpochMicrosec(LAST_EPOCH_MICROSEC) // - .sourceName(SOURCE_NAME) // - .startEpochMicrosec(START_EPOCH_MICROSEC) // - .timeZoneOffset(TIME_ZONE_OFFSET) // - .changeIdentifier(CHANGE_IDENTIFIER) // - .eventName("Noti_RnNode-Ericsson_FileReady").build(); + .lastEpochMicrosec(LAST_EPOCH_MICROSEC) // + .sourceName(SOURCE_NAME) // + .startEpochMicrosec(START_EPOCH_MICROSEC) // + .timeZoneOffset(TIME_ZONE_OFFSET) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .eventName("Noti_RnNode-Ericsson_FileReady").build(); FileReadyMessage.FileInfo fileInfo = FileReadyMessage.FileInfo // - .builder() // - .fileFormatType(FILE_FORMAT_TYPE) // - .location(LOCATION) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .compression(GZIP_COMPRESSION) // - .build(); + .builder() // + .fileFormatType(FILE_FORMAT_TYPE) // + .location(LOCATION) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .compression(GZIP_COMPRESSION) // + .build(); FileReadyMessage.ArrayOfNamedHashMap arrayOfNamedHashMap = FileReadyMessage.ArrayOfNamedHashMap // - .builder() // - .name(fileName) // - .hashMap(fileInfo) // - .build(); + .builder() // + .name(fileName) // + .hashMap(fileInfo) // + .build(); List arrayOfNamedHashMapList = new ArrayList<>(); arrayOfNamedHashMapList.add(arrayOfNamedHashMap); FileReadyMessage.NotificationFields notificationFields = FileReadyMessage.NotificationFields // - .builder().notificationFieldsVersion("notificationFieldsVersion") // - .changeType(CHANGE_TYPE).changeIdentifier(CHANGE_IDENTIFIER) // - .arrayOfNamedHashMap(arrayOfNamedHashMapList) // - .build(); + .builder().notificationFieldsVersion("notificationFieldsVersion") // + .changeType(CHANGE_TYPE).changeIdentifier(CHANGE_IDENTIFIER) // + .arrayOfNamedHashMap(arrayOfNamedHashMapList) // + .build(); return FileReadyMessage.Event.builder() // - .commonEventHeader(messageMetaData) // - .notificationFields(notificationFields).build(); + .commonEventHeader(messageMetaData) // + .notificationFields(notificationFields).build(); } private FileReadyMessage fileReadyMessage(String fileName) { FileReadyMessage message = FileReadyMessage.builder() // - .event(event(fileName)) // - .build(); + .event(event(fileName)) // + .build(); return message; }