diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2019-06-14 11:42:38 +0000 |
---|---|---|
committer | PatrikBuhr <patrik.buhr@est.tech> | 2019-06-14 11:42:38 +0000 |
commit | 21f0997ab8b1d16b05a0dd5929ff0491ea47c466 (patch) | |
tree | 705d1e4c09899f1e8ed72f50be2bf0b0a2c2e7e5 /datafile-app-server | |
parent | dafd553cf1694585b35fd7132c6bafdef1e98ed6 (diff) |
Code formatting with maven
This commit only contains code formastting changes done by command:
mvn formatter:format spotless:apply process-sources
Change-Id: I0fb9d166ad5d9171cdeee9f26b6d353bca74069c
Issue-ID: DCAEGEN2-1538
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'datafile-app-server')
50 files changed, 1104 insertions, 1081 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java index cc5d12b9..55f4fe73 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/MainApp.java @@ -32,7 +32,7 @@ import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18 * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ -@SpringBootApplication(exclude = { JacksonAutoConfiguration.class }) +@SpringBootApplication(exclude = {JacksonAutoConfiguration.class}) @EnableScheduling public class MainApp { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java index b66be163..8e15deb7 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java @@ -22,6 +22,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.google.gson.TypeAdapterFactory; + import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; @@ -31,8 +32,10 @@ import java.time.Duration; import java.util.Map; import java.util.Properties; import java.util.ServiceLoader; + import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; + import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuration.EnvProperties; @@ -46,6 +49,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Component; + import reactor.core.Disposable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -77,7 +81,7 @@ public class AppConfig { @Autowired public synchronized void setCloudConfigurationProvider( - CloudConfigurationProvider reactiveCloudConfigurationProvider) { + CloudConfigurationProvider reactiveCloudConfigurationProvider) { this.cloudConfigurationProvider = reactiveCloudConfigurationProvider; } @@ -94,10 +98,10 @@ public class AppConfig { loadConfigurationFromFile(); refreshConfigTask = Flux.interval(Duration.ZERO, Duration.ofMinutes(5)) - .flatMap(count -> createRefreshConfigurationTask(count, context)) - .subscribe(e -> logger.info("Refreshed configuration data"), - throwable -> logger.error("Configuration refresh terminated due to exception", throwable), - () -> logger.error("Configuration refresh terminated")); + .flatMap(count -> createRefreshConfigurationTask(count, context)) + .subscribe(e -> logger.info("Refreshed configuration data"), + throwable -> logger.error("Configuration refresh terminated due to exception", throwable), + () -> logger.error("Configuration refresh terminated")); } public void stop() { @@ -116,7 +120,7 @@ public class AppConfig { } public synchronized PublisherConfiguration getPublisherConfiguration(String changeIdentifier) - throws DatafileTaskException { + throws DatafileTaskException { if (publishingConfiguration == null) { throw new DatafileTaskException("No PublishingConfiguration loaded, changeIdentifier: " + changeIdentifier); @@ -124,7 +128,7 @@ public class AppConfig { PublisherConfiguration cfg = publishingConfiguration.get(changeIdentifier); if (cfg == null) { throw new DatafileTaskException( - "Cannot find getPublishingConfiguration for changeIdentifier: " + changeIdentifier); + "Cannot find getPublishingConfiguration for changeIdentifier: " + changeIdentifier); } return cfg; } @@ -135,14 +139,14 @@ public class AppConfig { Flux<AppConfig> createRefreshConfigurationTask(Long counter, Map<String, String> context) { return Flux.just(counter) // - .doOnNext(cnt -> logger.debug("Refresh config {}", cnt)) // - .flatMap(cnt -> readEnvironmentVariables(systemEnvironment, context)) // - .flatMap(this::fetchConfiguration); + .doOnNext(cnt -> logger.debug("Refresh config {}", cnt)) // + .flatMap(cnt -> readEnvironmentVariables(systemEnvironment, context)) // + .flatMap(this::fetchConfiguration); } Mono<EnvProperties> readEnvironmentVariables(Properties systemEnvironment, Map<String, String> context) { return EnvironmentProcessor.readEnvironmentVariables(systemEnvironment, context) - .onErrorResume(AppConfig::onErrorResume); + .onErrorResume(AppConfig::onErrorResume); } private static <R> Mono<R> onErrorResume(Throwable trowable) { @@ -152,21 +156,21 @@ public class AppConfig { private Mono<AppConfig> fetchConfiguration(EnvProperties env) { Mono<JsonObject> serviceCfg = cloudConfigurationProvider.callForServiceConfigurationReactive(env) // - .onErrorResume(AppConfig::onErrorResume); + .onErrorResume(AppConfig::onErrorResume); // Note, have to use this callForServiceConfigurationReactive with EnvProperties, since the // other ones does not work EnvProperties dmaapEnv = ImmutableEnvProperties.builder() // - .consulHost(env.consulHost()) // - .consulPort(env.consulPort()) // - .cbsName(env.cbsName()) // - .appName(env.appName() + ":dmaap") // - .build(); // + .consulHost(env.consulHost()) // + .consulPort(env.consulPort()) // + .cbsName(env.cbsName()) // + .appName(env.appName() + ":dmaap") // + .build(); // Mono<JsonObject> dmaapCfg = cloudConfigurationProvider.callForServiceConfigurationReactive(dmaapEnv) - .onErrorResume(t -> Mono.just(new JsonObject())); + .onErrorResume(t -> Mono.just(new JsonObject())); return serviceCfg.zipWith(dmaapCfg, this::parseCloudConfig) // - .onErrorResume(AppConfig::onErrorResume); + .onErrorResume(AppConfig::onErrorResume); } /** @@ -181,7 +185,7 @@ public class AppConfig { try { CloudConfigParser parser = new CloudConfigParser(serviceConfigRootObject, dmaapConfigRootObject); setConfiguration(parser.getDmaapConsumerConfig(), parser.getDmaapPublisherConfig(), - parser.getFtpesConfig()); + parser.getFtpesConfig()); } catch (DatafileTaskException e) { logger.error("Could not parse configuration {}", e.toString(), e); } @@ -208,11 +212,11 @@ public class AppConfig { } private synchronized void setConfiguration(ConsumerConfiguration consumerConfiguration, - Map<String, PublisherConfiguration> publisherConfiguration, FtpesConfig ftpesConfig) { + Map<String, PublisherConfiguration> publisherConfiguration, FtpesConfig ftpesConfig) { if (consumerConfiguration == null || publisherConfiguration == null || ftpesConfig == null) { logger.error( - "Problem with configuration consumerConfiguration: {}, publisherConfiguration: {}, ftpesConfig: {}", - consumerConfiguration, publisherConfiguration, ftpesConfig); + "Problem with configuration consumerConfiguration: {}, publisherConfiguration: {}, ftpesConfig: {}", + consumerConfiguration, publisherConfiguration, ftpesConfig); } else { this.dmaapConsumerConfiguration = consumerConfiguration; this.publishingConfiguration = publisherConfiguration; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java index 3103af49..d25d7db1 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/CloudConfigParser.java @@ -21,13 +21,14 @@ package org.onap.dcaegen2.collectors.datafile.configuration; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; +import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; /** * Parses the cloud configuration. @@ -52,7 +53,7 @@ public class CloudConfigParser { public Map<String, PublisherConfiguration> getDmaapPublisherConfig() throws DatafileTaskException { Iterator<JsonElement> producerCfgs = - toArray(serviceConfigurationRoot.get("dmaap.dmaapProducerConfiguration")).iterator(); + toArray(serviceConfigurationRoot.get("dmaap.dmaapProducerConfiguration")).iterator(); Map<String, PublisherConfiguration> result = new HashMap<>(); @@ -62,19 +63,18 @@ public class CloudConfigParser { JsonObject feedConfig = getFeedConfig(feedName); PublisherConfiguration cfg = ImmutablePublisherConfiguration.builder() // - .publishUrl(getAsString(feedConfig, "publish_url")) // - .passWord(getAsString(feedConfig, "password")) // - .userName(getAsString(feedConfig, "username")) // - .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH)) // - .trustStorePasswordPath( - getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH)) // - .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH)) // - .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH)) // - .enableDmaapCertAuth( - get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) // - .changeIdentifier(getAsString(producerCfg, "changeIdentifier")) // - .logUrl(getAsString(feedConfig, "log_url")) // - .build(); + .publishUrl(getAsString(feedConfig, "publish_url")) // + .passWord(getAsString(feedConfig, "password")) // + .userName(getAsString(feedConfig, "username")) // + .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH)) // + .trustStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH)) // + .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH)) // + .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH)) // + .enableDmaapCertAuth( + get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) // + .changeIdentifier(getAsString(producerCfg, "changeIdentifier")) // + .logUrl(getAsString(feedConfig, "log_url")) // + .build(); result.put(cfg.changeIdentifier(), cfg); } @@ -92,22 +92,21 @@ public class CloudConfigParser { String topicUrl = getAsString(dmaapInfo, "topic_url"); return ImmutableConsumerConfiguration.builder().topicUrl(topicUrl) - .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH)) - .trustStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH)) - .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH)) - .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH)) - .enableDmaapCertAuth( - get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) // - .build(); + .trustStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PATH)) + .trustStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_TRUST_STORE_PASS_PATH)) + .keyStorePath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PATH)) + .keyStorePasswordPath(getAsString(serviceConfigurationRoot, DMAAP_SECURITY_KEY_STORE_PASS_PATH)) + .enableDmaapCertAuth(get(serviceConfigurationRoot, DMAAP_SECURITY_ENABLE_DMAAP_CERT_AUTH).getAsBoolean()) // + .build(); } public FtpesConfig getFtpesConfig() throws DatafileTaskException { return new ImmutableFtpesConfig.Builder() // - .keyCert(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyCert")) - .keyPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyPassword")) - .trustedCa(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCa")) - .trustedCaPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCaPassword")) // - .build(); + .keyCert(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyCert")) + .keyPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.keyPassword")) + .trustedCa(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCa")) + .trustedCaPassword(getAsString(serviceConfigurationRoot, "dmaap.ftpesConfig.trustedCaPassword")) // + .build(); } private static JsonElement get(JsonObject obj, String memberName) throws DatafileTaskException { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/ConsumerConfiguration.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/ConsumerConfiguration.java index bd8f0c3c..1fd24e98 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/ConsumerConfiguration.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/ConsumerConfiguration.java @@ -18,6 +18,7 @@ package org.onap.dcaegen2.collectors.datafile.configuration; import java.net.MalformedURLException; import java.net.URL; + import org.immutables.gson.Gson; import org.immutables.value.Value; import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; @@ -55,23 +56,23 @@ public abstract class ConsumerConfiguration { DmaapConsumerUrlPath path = parseDmaapUrlPath(urlPath); return new ImmutableDmaapConsumerConfiguration.Builder() // - .dmaapContentType("application/json") // - .dmaapPortNumber(url.getPort()) // - .dmaapHostName(url.getHost()) // - .dmaapTopicName(path.dmaapTopicName) // - .dmaapProtocol(url.getProtocol()) // - .dmaapUserName(userName) // - .dmaapUserPassword(passwd) // - .trustStorePath(this.trustStorePath()) // - .trustStorePasswordPath(this.trustStorePasswordPath()) // - .keyStorePath(this.keyStorePath()) // - .keyStorePasswordPath(this.keyStorePasswordPath()) // - .enableDmaapCertAuth(this.enableDmaapCertAuth()) // - .consumerId(path.consumerId) // - .consumerGroup(path.consumerGroup) // - .timeoutMs(-1) // - .messageLimit(-1) // - .build(); + .dmaapContentType("application/json") // + .dmaapPortNumber(url.getPort()) // + .dmaapHostName(url.getHost()) // + .dmaapTopicName(path.dmaapTopicName) // + .dmaapProtocol(url.getProtocol()) // + .dmaapUserName(userName) // + .dmaapUserPassword(passwd) // + .trustStorePath(this.trustStorePath()) // + .trustStorePasswordPath(this.trustStorePasswordPath()) // + .keyStorePath(this.keyStorePath()) // + .keyStorePasswordPath(this.keyStorePasswordPath()) // + .enableDmaapCertAuth(this.enableDmaapCertAuth()) // + .consumerId(path.consumerId) // + .consumerGroup(path.consumerGroup) // + .timeoutMs(-1) // + .messageLimit(-1) // + .build(); } catch (MalformedURLException e) { throw new DatafileTaskException("Could not parse the URL", e); } @@ -90,12 +91,14 @@ public abstract class ConsumerConfiguration { } private DmaapConsumerUrlPath parseDmaapUrlPath(String urlPath) throws DatafileTaskException { - String[] tokens = urlPath.split("/"); // UrlPath: /events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12 + String[] tokens = urlPath.split("/"); // UrlPath: + // /events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12 if (tokens.length != 5) { throw new DatafileTaskException("The path has incorrect syntax: " + urlPath); } - final String dmaapTopicName = tokens[1] + "/" + tokens[2]; // e.g. /events/unauthenticated.VES_NOTIFICATION_OUTPUT + final String dmaapTopicName = tokens[1] + "/" + tokens[2]; // e.g. + // /events/unauthenticated.VES_NOTIFICATION_OUTPUT final String consumerGroup = tokens[3]; // ex. OpenDcae-c12 final String consumerId = tokens[4]; // ex. C12 return new DmaapConsumerUrlPath(dmaapTopicName, consumerGroup, consumerId); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java index 62af92a8..f3c915b2 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/EnvironmentProcessor.java @@ -26,7 +26,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuratio import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; - import reactor.core.publisher.Mono; /** @@ -39,7 +38,8 @@ class EnvironmentProcessor { private static final int DEFAULT_CONSUL_PORT = 8500; private static final Logger logger = LoggerFactory.getLogger(EnvironmentProcessor.class); - private EnvironmentProcessor() {} + private EnvironmentProcessor() { + } static Mono<EnvProperties> readEnvironmentVariables(Properties systemEnvironment, Map<String, String> contextMap) { MDC.setContextMap(contextMap); @@ -47,11 +47,11 @@ class EnvironmentProcessor { EnvProperties envProperties; try { envProperties = ImmutableEnvProperties.builder() // - .consulHost(getConsulHost(systemEnvironment)) // - .consulPort(getConsultPort(systemEnvironment)) // - .cbsName(getConfigBindingService(systemEnvironment)) // - .appName(getService(systemEnvironment)) // - .build(); + .consulHost(getConsulHost(systemEnvironment)) // + .consulPort(getConsultPort(systemEnvironment)) // + .cbsName(getConfigBindingService(systemEnvironment)) // + .appName(getService(systemEnvironment)) // + .build(); } catch (EnvironmentLoaderException e) { return Mono.error(e); } @@ -61,27 +61,27 @@ class EnvironmentProcessor { private static String getConsulHost(Properties systemEnvironments) throws EnvironmentLoaderException { return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_HOST")) - .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined")); + .orElseThrow(() -> new EnvironmentLoaderException("$CONSUL_HOST environment has not been defined")); } private static Integer getConsultPort(Properties systemEnvironments) { return Optional.ofNullable(systemEnvironments.getProperty("CONSUL_PORT")) // - .map(Integer::valueOf) // - .orElseGet(EnvironmentProcessor::getDefaultPortOfConsul); + .map(Integer::valueOf) // + .orElseGet(EnvironmentProcessor::getDefaultPortOfConsul); } private static String getConfigBindingService(Properties systemEnvironments) throws EnvironmentLoaderException { return Optional.ofNullable(systemEnvironments.getProperty("CONFIG_BINDING_SERVICE")) // - .orElseThrow(() -> new EnvironmentLoaderException( - "$CONFIG_BINDING_SERVICE environment has not been defined")); + .orElseThrow( + () -> new EnvironmentLoaderException("$CONFIG_BINDING_SERVICE environment has not been defined")); } private static String getService(Properties systemEnvironments) throws EnvironmentLoaderException { return Optional - .ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME")) - .orElse(systemEnvironments.getProperty("SERVICE_NAME"))) - .orElseThrow(() -> new EnvironmentLoaderException( - "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment")); + .ofNullable(Optional.ofNullable(systemEnvironments.getProperty("HOSTNAME")) + .orElse(systemEnvironments.getProperty("SERVICE_NAME"))) + .orElseThrow(() -> new EnvironmentLoaderException( + "Neither $HOSTNAME/$SERVICE_NAME have not been defined as system environment")); } private static Integer getDefaultPortOfConsul() { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java index 844699eb..e12365e4 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/FtpesConfig.java @@ -26,7 +26,6 @@ import org.immutables.gson.Gson; import org.immutables.value.Value; import org.springframework.stereotype.Component; - @Component @Value.Immutable @Value.Style(builder = "new", redactedMask = "####") diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/PublisherConfiguration.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/PublisherConfiguration.java index 5576ed26..3c3a7625 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/PublisherConfiguration.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/PublisherConfiguration.java @@ -24,7 +24,6 @@ import org.immutables.value.Value; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration; - @Value.Immutable @Value.Style(redactedMask = "####") @Gson.TypeAdapters @@ -56,19 +55,19 @@ public interface PublisherConfiguration { String urlPath = url.getPath(); return new ImmutableDmaapPublisherConfiguration.Builder() // - .dmaapContentType("application/octet-stream") // - .dmaapPortNumber(url.getPort()) // - .dmaapHostName(url.getHost()) // - .dmaapTopicName(urlPath) // - .dmaapProtocol(url.getProtocol()) // - .dmaapUserName(this.userName()) // - .dmaapUserPassword(this.passWord()) // - .trustStorePath(this.trustStorePath()) // - .trustStorePasswordPath(this.trustStorePasswordPath()) // - .keyStorePath(this.keyStorePath()) // - .keyStorePasswordPath(this.keyStorePasswordPath()) // - .enableDmaapCertAuth(this.enableDmaapCertAuth()) // - .build(); + .dmaapContentType("application/octet-stream") // + .dmaapPortNumber(url.getPort()) // + .dmaapHostName(url.getHost()) // + .dmaapTopicName(urlPath) // + .dmaapProtocol(url.getProtocol()) // + .dmaapUserName(this.userName()) // + .dmaapUserPassword(this.passWord()) // + .trustStorePath(this.trustStorePath()) // + .trustStorePasswordPath(this.trustStorePasswordPath()) // + .keyStorePath(this.keyStorePath()) // + .keyStorePasswordPath(this.keyStorePasswordPath()) // + .enableDmaapCertAuth(this.enableDmaapCertAuth()) // + .build(); } } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java index e0362373..3a0c559e 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java @@ -17,6 +17,7 @@ package org.onap.dcaegen2.collectors.datafile.configuration; import io.swagger.annotations.ApiOperation; + import java.time.Duration; import java.time.Instant; import java.util.ArrayList; @@ -24,7 +25,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ScheduledFuture; + import javax.annotation.PostConstruct; + import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext; import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks; import org.slf4j.Logger; @@ -66,8 +69,7 @@ public class SchedulerConfig { * @param configuration The DFC configuration. */ @Autowired - public SchedulerConfig(TaskScheduler taskScheduler, ScheduledTasks scheduledTasks, - AppConfig configuration) { + public SchedulerConfig(TaskScheduler taskScheduler, ScheduledTasks scheduledTasks, AppConfig configuration) { this.taskScheduler = taskScheduler; this.scheduledTask = scheduledTasks; this.configuration = configuration; @@ -103,10 +105,9 @@ public class SchedulerConfig { if (scheduledFutureList.isEmpty()) { scheduledFutureList.add(taskScheduler.scheduleWithFixedDelay(scheduledTask::executeDatafileMainTask, - SCHEDULING_DELAY_FOR_DATAFILE_COLLECTOR_TASKS)); - scheduledFutureList - .add(taskScheduler.scheduleWithFixedDelay(() -> scheduledTask.purgeCachedInformation(Instant.now()), - SCHEDULING_DELAY_FOR_DATAFILE_PURGE_CACHE)); + SCHEDULING_DELAY_FOR_DATAFILE_COLLECTOR_TASKS)); + scheduledFutureList.add(taskScheduler.scheduleWithFixedDelay( + () -> scheduledTask.purgeCachedInformation(Instant.now()), SCHEDULING_DELAY_FOR_DATAFILE_PURGE_CACHE)); return true; } else { return false; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java index 5a78261a..1990efb8 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SwaggerConfig.java @@ -19,11 +19,13 @@ package org.onap.dcaegen2.collectors.datafile.configuration; import com.google.common.base.Predicates; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; + import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; @@ -32,7 +34,6 @@ import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; - @EnableSwagger2 @Configuration @Profile("prod") @@ -53,29 +54,29 @@ public class SwaggerConfig extends WebMvcConfigurationSupport { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) // - .apiInfo(apiInfo()) // - .select() // - .apis(RequestHandlerSelectors.any()) // - .paths(PathSelectors.any()) // - .paths(Predicates.not(PathSelectors.regex("/error"))) // - // this endpoint is not implemented, but was visible for Swagger - .build(); + .apiInfo(apiInfo()) // + .select() // + .apis(RequestHandlerSelectors.any()) // + .paths(PathSelectors.any()) // + .paths(Predicates.not(PathSelectors.regex("/error"))) // + // this endpoint is not implemented, but was visible for Swagger + .build(); } private static ApiInfo apiInfo() { return new ApiInfoBuilder() // - .title(API_TITLE) // - .description(DESCRIPTION) // - .version(VERSION) // - .build(); + .title(API_TITLE) // + .description(DESCRIPTION) // + .version(VERSION) // + .build(); } @Override protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler(SWAGGER_UI) // - .addResourceLocations(RESOURCES_PATH); + .addResourceLocations(RESOURCES_PATH); registry.addResourceHandler(WEBJARS) // - .addResourceLocations(WEBJARS_PATH); + .addResourceLocations(WEBJARS_PATH); } } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java index 791f0cf1..16cd05de 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/ScheduleController.java @@ -20,6 +20,7 @@ package org.onap.dcaegen2.collectors.datafile.controllers; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; + import org.onap.dcaegen2.collectors.datafile.configuration.SchedulerConfig; import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext; import org.slf4j.Logger; @@ -71,7 +72,7 @@ public class ScheduleController { public Mono<ResponseEntity<String>> startTasks() { return Mono.fromSupplier(schedulerConfig::tryToStartTask) // - .map(ScheduleController::createStartTaskResponse); + .map(ScheduleController::createStartTaskResponse); } /** @@ -84,7 +85,7 @@ public class ScheduleController { public Mono<ResponseEntity<String>> stopTask(@RequestHeader HttpHeaders headers) { MappedDiagnosticContext.initializeTraceContext(headers); logger.info(MappedDiagnosticContext.ENTRY, "Stop request"); - Mono<ResponseEntity<String>> response = schedulerConfig.getResponseFromCancellationOfTasks(); + Mono<ResponseEntity<String>> response = schedulerConfig.getResponseFromCancellationOfTasks(); logger.info(MappedDiagnosticContext.EXIT, "Stop request"); return response; } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/StatusController.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/StatusController.java index 40f9d99b..5b72df1a 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/StatusController.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/controllers/StatusController.java @@ -19,12 +19,12 @@ package org.onap.dcaegen2.collectors.datafile.controllers; import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.ENTRY; import static org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext.EXIT; -import org.onap.dcaegen2.collectors.datafile.model.Counters; - import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; + +import org.onap.dcaegen2.collectors.datafile.model.Counters; import org.onap.dcaegen2.collectors.datafile.model.logging.MappedDiagnosticContext; import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks; import org.slf4j.Logger; @@ -61,7 +61,8 @@ public class StatusController { */ @GetMapping("/heartbeat") @ApiOperation(value = "Returns liveness of DATAFILE service") - @ApiResponses(value = { // + @ApiResponses( + value = { // @ApiResponse(code = 200, message = "DATAFILE service is living"), @ApiResponse(code = 401, message = "You are not authorized to view the resource"), @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"), @@ -85,7 +86,8 @@ public class StatusController { */ @GetMapping("/status") @ApiOperation(value = "Returns status and statistics of DATAFILE service") - @ApiResponses(value = { // + @ApiResponses( + value = { // @ApiResponse(code = 200, message = "DATAFILE service is living"), @ApiResponse(code = 401, message = "You are not authorized to view the resource"), @ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"), @@ -100,6 +102,4 @@ public class StatusController { return response; } - - } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/NonRetryableDatafileTaskException.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/NonRetryableDatafileTaskException.java index a4bdd667..5c2a0d2f 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/NonRetryableDatafileTaskException.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/exceptions/NonRetryableDatafileTaskException.java @@ -18,7 +18,6 @@ package org.onap.dcaegen2.collectors.datafile.exceptions; - public class NonRetryableDatafileTaskException extends DatafileTaskException { private static final long serialVersionUID = 1L; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java index c35a5a1d..d74b10a2 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FileCollectClient.java @@ -17,6 +17,7 @@ package org.onap.dcaegen2.collectors.datafile.ftp; import java.nio.file.Path; + import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; /** @@ -24,7 +25,7 @@ import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; * * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a> */ -public interface FileCollectClient extends AutoCloseable { +public interface FileCollectClient extends AutoCloseable { public void collectFile(String remoteFile, Path localFile) throws DatafileTaskException; public void open() throws DatafileTaskException; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java index 18288603..2d126ff8 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClient.java @@ -72,7 +72,7 @@ public class FtpsClient implements FileCollectClient { * @param trustedCaPassword password for the PNF's trusted keystore. */ public FtpsClient(FileServerData fileServerData, String keyCertPath, String keyCertPassword, Path trustedCaPath, - String trustedCaPassword) { + String trustedCaPassword) { this.fileServerData = fileServerData; this.keyCertPath = keyCertPath; this.keyCertPassword = keyCertPassword; @@ -120,7 +120,8 @@ public class FtpsClient implements FileCollectClient { try (OutputStream output = createOutputStream(localFileName)) { logger.trace("begin to retrieve from xNF."); if (!realFtpsClient.retrieveFile(remoteFileName, output)) { - throw new NonRetryableDatafileTaskException("Could not retrieve file. No retry attempts will be done, file :" + remoteFileName); + throw new NonRetryableDatafileTaskException( + "Could not retrieve file. No retry attempts will be done, file :" + remoteFileName); } } catch (IOException e) { throw new DatafileTaskException("Could not fetch file: " + e, e); @@ -151,14 +152,14 @@ public class FtpsClient implements FileCollectClient { realFtpsClient.setBufferSize(1024 * 1024); } else { throw new DatafileTaskException("Unable to connect to xNF. " + fileServerData.serverAddress() - + " xNF reply code: " + realFtpsClient.getReplyCode()); + + " xNF reply code: " + realFtpsClient.getReplyCode()); } logger.trace("setUpConnection successfully!"); } private TrustManager createTrustManager(Path trustedCaPath, String trustedCaPassword) - throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException { + throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException { logger.trace("Creating trust manager from file: {}", trustedCaPath); try (InputStream fis = createInputStream(trustedCaPath)) { KeyStore keyStore = KeyStore.getInstance("JKS"); @@ -185,7 +186,7 @@ public class FtpsClient implements FileCollectClient { } protected TrustManager getTrustManager(Path trustedCaPath, String trustedCaPassword) - throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException { + throws KeyStoreException, NoSuchAlgorithmException, IOException, CertificateException { synchronized (FtpsClient.class) { if (theTrustManager == null) { theTrustManager = createTrustManager(trustedCaPath, trustedCaPassword); @@ -195,7 +196,7 @@ public class FtpsClient implements FileCollectClient { } protected KeyManager createKeyManager(String keyCertPath, String keyCertPassword) - throws IOException, GeneralSecurityException { + throws IOException, GeneralSecurityException { return KeyManagerUtils.createClientKeyManager(new File(keyCertPath), keyCertPassword); } } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/Scheme.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/Scheme.java index 585dd775..e5ca9351 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/Scheme.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/Scheme.java @@ -30,8 +30,7 @@ public enum Scheme { FTPS, SFTP; public static final String DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG = "DFC does not support protocol "; - public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE = - ". Supported protocols are FTPES, FTPS, and SFTP"; + public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE = ". Supported protocols are FTPES, FTPS, and SFTP"; /** * Get a <code>Scheme</code> from a string. @@ -47,8 +46,8 @@ public enum Scheme { } else if ("SFTP".equalsIgnoreCase(schemeString)) { result = Scheme.SFTP; } else { - throw new DatafileTaskException(DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString - + SUPPORTED_PROTOCOLS_ERROR_MESSAGE); + throw new DatafileTaskException( + DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString + SUPPORTED_PROTOCOLS_ERROR_MESSAGE); } return result; } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java index f5d10d34..e11cd76b 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClient.java @@ -22,8 +22,10 @@ import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpException; + import java.nio.file.Path; import java.util.Optional; + import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; import org.onap.dcaegen2.collectors.datafile.exceptions.NonRetryableDatafileTaskException; import org.slf4j.Logger; @@ -57,12 +59,12 @@ public class SftpClient implements FileCollectClient { logger.trace("File {} Download Successfull from xNF", localFile.getFileName()); } catch (SftpException e) { boolean retry = e.id != ChannelSftp.SSH_FX_NO_SUCH_FILE && e.id != ChannelSftp.SSH_FX_PERMISSION_DENIED - && e.id != ChannelSftp.SSH_FX_OP_UNSUPPORTED; + && e.id != ChannelSftp.SSH_FX_OP_UNSUPPORTED; if (retry) { throw new DatafileTaskException("Unable to get file from xNF. Data: " + fileServerData, e); } else { throw new NonRetryableDatafileTaskException( - "Unable to get file from xNF. No retry attempts will be done. Data: " + fileServerData, e); + "Unable to get file from xNF. No retry attempts will be done. Data: " + fileServerData, e); } } @@ -95,7 +97,7 @@ public class SftpClient implements FileCollectClient { throw new DatafileTaskException("Could not open Sftp client. " + e); } else { throw new NonRetryableDatafileTaskException( - "Could not open Sftp client, no retry attempts will be done " + e); + "Could not open Sftp client, no retry attempts will be done " + e); } } } @@ -107,8 +109,8 @@ public class SftpClient implements FileCollectClient { private Session setUpSession(FileServerData fileServerData) throws JSchException { JSch jsch = createJsch(); - Session newSession = jsch.getSession(fileServerData.userId(), fileServerData.serverAddress(), - getPort(fileServerData.port())); + Session newSession = + jsch.getSession(fileServerData.userId(), fileServerData.serverAddress(), getPort(fileServerData.port())); newSession.setConfig("StrictHostKeyChecking", "no"); newSession.setPassword(fileServerData.password()); newSession.connect(); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/http/HttpAsyncClientBuilderWrapper.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/http/HttpAsyncClientBuilderWrapper.java index f6f93d49..b0037271 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/http/HttpAsyncClientBuilderWrapper.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/http/HttpAsyncClientBuilderWrapper.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.collectors.datafile.http; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; + import org.apache.http.client.RedirectStrategy; import org.apache.http.client.config.RequestConfig; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/Counters.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/Counters.java index 5efbe37a..4c42284e 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/Counters.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/Counters.java @@ -23,7 +23,6 @@ package org.onap.dcaegen2.collectors.datafile.model; import java.time.Instant; import java.util.concurrent.atomic.AtomicInteger; - /** * * Various counters that can be shown via a REST API. 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 36aae949..8cafd0c4 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 @@ -108,9 +108,9 @@ public abstract class FileData { URI uri = URI.create(location()); Optional<String[]> userInfo = getUserNameAndPasswordIfGiven(uri.getUserInfo()); ImmutableFileServerData.Builder builder = ImmutableFileServerData.builder() // - .serverAddress(uri.getHost()) // - .userId(userInfo.isPresent() ? userInfo.get()[0] : "") // - .password(userInfo.isPresent() ? userInfo.get()[1] : ""); + .serverAddress(uri.getHost()) // + .userId(userInfo.isPresent() ? userInfo.get()[0] : "") // + .password(userInfo.isPresent() ? userInfo.get()[1] : ""); if (uri.getPort() > 0) { builder.port(uri.getPort()); } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FilePublishInformation.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FilePublishInformation.java index 5b8c015e..34f2ac0b 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FilePublishInformation.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FilePublishInformation.java @@ -34,7 +34,7 @@ import org.immutables.value.Value; @Value.Immutable @Gson.TypeAdapters @Value.Style(redactedMask = "####") -public interface FilePublishInformation { +public interface FilePublishInformation { @SerializedName("productName") String getProductName(); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileReadyMessage.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileReadyMessage.java index 6cc6da6e..647330fe 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileReadyMessage.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/FileReadyMessage.java @@ -21,6 +21,7 @@ package org.onap.dcaegen2.collectors.datafile.model; import java.util.List; + import org.immutables.gson.Gson; import org.immutables.value.Value; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/JsonSerializer.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/JsonSerializer.java index efd69a09..6f6ef004 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/JsonSerializer.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/JsonSerializer.java @@ -23,6 +23,7 @@ import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; import com.google.gson.Gson; import com.google.gson.GsonBuilder; + import java.util.Set; /** @@ -31,11 +32,12 @@ import java.util.Set; public abstract class JsonSerializer { private static Gson gson = new GsonBuilder() // - .serializeNulls() // - .addSerializationExclusionStrategy(new FilePublishInformationExclusionStrategy()) // - .create(); // + .serializeNulls() // + .addSerializationExclusionStrategy(new FilePublishInformationExclusionStrategy()) // + .create(); // - private JsonSerializer() {} + private JsonSerializer() { + } /** * Serializes a <code>filePublishInformation</code>. @@ -53,8 +55,8 @@ public abstract class JsonSerializer { * Elements in FilePublishInformation to include in the file publishing Json string. */ private final Set<String> inclusions = - Sets.newHashSet("productName", "vendorName", "lastEpochMicrosec", "sourceName", "startEpochMicrosec", - "timeZoneOffset", "location", "compression", "fileFormatType", "fileFormatVersion"); + Sets.newHashSet("productName", "vendorName", "lastEpochMicrosec", "sourceName", "startEpochMicrosec", + "timeZoneOffset", "location", "compression", "fileFormatType", "fileFormatVersion"); @Override public boolean shouldSkipField(FieldAttributes fieldAttributes) { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/logging/MappedDiagnosticContext.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/logging/MappedDiagnosticContext.java index 86ea5c3e..72d18437 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/logging/MappedDiagnosticContext.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/model/logging/MappedDiagnosticContext.java @@ -40,7 +40,8 @@ public final class MappedDiagnosticContext { private static final Logger logger = LoggerFactory.getLogger(MappedDiagnosticContext.class); - private MappedDiagnosticContext() {} + private MappedDiagnosticContext() { + } /** * Inserts the relevant trace information in the HTTP header. @@ -78,6 +79,7 @@ public final class MappedDiagnosticContext { /** * Initialize the MDC when a new context is started. + * * @return a copy of the new trace context */ public static Map<String, String> initializeTraceContext() { @@ -88,6 +90,7 @@ public final class MappedDiagnosticContext { /** * Updates the request ID in the current context. + * * @param newRequestId the new value of the request ID * @return a copy the updated context */ diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapWebClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapWebClient.java index 5f5ccddf..2ad96e8d 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapWebClient.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/DmaapWebClient.java @@ -28,7 +28,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.Builder; - import reactor.core.publisher.Mono; /** @@ -86,7 +85,7 @@ public class DmaapWebClient { MDC.put(SERVICE_NAME, String.valueOf(clientRequest.url())); logger.trace("Request: {} {}", clientRequest.method(), clientRequest.url()); clientRequest.headers() - .forEach((name, values) -> values.forEach(value -> logger.trace("{}={}", name, value))); + .forEach((name, values) -> values.forEach(value -> logger.trace("{}={}", name, value))); logger.trace("HTTP request headers: {}", clientRequest.headers()); MDC.remove(SERVICE_NAME); return Mono.just(clientRequest); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParser.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParser.java index 5e02ecdd..abed645a 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParser.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParser.java @@ -22,11 +22,13 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; + import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.StreamSupport; + import org.onap.dcaegen2.collectors.datafile.ftp.Scheme; import org.onap.dcaegen2.collectors.datafile.model.FileData; import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage; @@ -37,6 +39,7 @@ import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StringUtils; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -109,8 +112,7 @@ public class JsonMessageParser { private Flux<FileReadyMessage> getMessagesFromJsonArray(JsonElement jsonElement) { return createMessages(Flux.fromStream(StreamSupport.stream(jsonElement.getAsJsonArray().spliterator(), false) - .map(jsonElementFromArray -> getJsonObjectFromAnArray(jsonElementFromArray) - .orElseGet(JsonObject::new)))); + .map(jsonElementFromArray -> getJsonObjectFromAnArray(jsonElementFromArray).orElseGet(JsonObject::new)))); } /** @@ -121,7 +123,7 @@ public class JsonMessageParser { */ private Flux<FileReadyMessage> createMessageData(JsonElement jsonElement) { return jsonElement.isJsonObject() ? createMessages(Flux.just(jsonElement.getAsJsonObject())) - : getMessagesFromJsonArray(jsonElement); + : getMessagesFromJsonArray(jsonElement); } private static Mono<JsonElement> getJsonParserMessage(String message) { @@ -130,10 +132,9 @@ public class JsonMessageParser { private static Flux<FileReadyMessage> createMessages(Flux<JsonObject> jsonObject) { return jsonObject.flatMap(monoJsonP -> containsNotificationFields(monoJsonP) ? transformMessages(monoJsonP) - : logErrorAndReturnEmptyMessageFlux("Incorrect JsonObject - missing header. " + jsonObject)); + : logErrorAndReturnEmptyMessageFlux("Incorrect JsonObject - missing header. " + jsonObject)); } - private static Mono<FileReadyMessage> transformMessages(JsonObject message) { Optional<MessageMetaData> optionalMessageMetaData = getMessageMetaData(message); if (optionalMessageMetaData.isPresent()) { @@ -144,8 +145,8 @@ public class JsonMessageParser { List<FileData> allFileDataFromJson = getAllFileDataFromJson(arrayOfNamedHashMap, messageMetaData); if (!allFileDataFromJson.isEmpty()) { return Mono.just(ImmutableFileReadyMessage.builder() // - .files(allFileDataFromJson) // - .build()); + .files(allFileDataFromJson) // + .build()); } else { return Mono.empty(); } @@ -158,7 +159,6 @@ public class JsonMessageParser { return Mono.empty(); } - private static Optional<MessageMetaData> getMessageMetaData(JsonObject message) { List<String> missingValues = new ArrayList<>(); JsonObject commonEventHeader = message.getAsJsonObject(EVENT).getAsJsonObject(COMMON_EVENT_HEADER); @@ -173,15 +173,15 @@ public class JsonMessageParser { getValueFromJson(notificationFields, NOTIFICATION_FIELDS_VERSION, missingValues); MessageMetaData messageMetaData = ImmutableMessageMetaData.builder() // - .productName(getDataFromEventName(EventNameDataType.PRODUCT_NAME, eventName, missingValues)) // - .vendorName(getDataFromEventName(EventNameDataType.VENDOR_NAME, eventName, missingValues)) // - .lastEpochMicrosec(getValueFromJson(commonEventHeader, LAST_EPOCH_MICROSEC, missingValues)) // - .sourceName(getValueFromJson(commonEventHeader, SOURCE_NAME, missingValues)) // - .startEpochMicrosec(getValueFromJson(commonEventHeader, START_EPOCH_MICROSEC, missingValues)) // - .timeZoneOffset(getValueFromJson(commonEventHeader, TIME_ZONE_OFFSET, missingValues)) // - .changeIdentifier(changeIdentifier) // - .changeType(changeType) // - .build(); + .productName(getDataFromEventName(EventNameDataType.PRODUCT_NAME, eventName, missingValues)) // + .vendorName(getDataFromEventName(EventNameDataType.VENDOR_NAME, eventName, missingValues)) // + .lastEpochMicrosec(getValueFromJson(commonEventHeader, LAST_EPOCH_MICROSEC, missingValues)) // + .sourceName(getValueFromJson(commonEventHeader, SOURCE_NAME, missingValues)) // + .startEpochMicrosec(getValueFromJson(commonEventHeader, START_EPOCH_MICROSEC, missingValues)) // + .timeZoneOffset(getValueFromJson(commonEventHeader, TIME_ZONE_OFFSET, missingValues)) // + .changeIdentifier(changeIdentifier) // + .changeType(changeType) // + .build(); if (missingValues.isEmpty() && isChangeTypeCorrect(changeType)) { return Optional.of(messageMetaData); } else { @@ -203,7 +203,7 @@ public class JsonMessageParser { } private static List<FileData> getAllFileDataFromJson(JsonArray arrayOfAdditionalFields, - MessageMetaData messageMetaData) { + MessageMetaData messageMetaData) { List<FileData> res = new ArrayList<>(); for (int i = 0; i < arrayOfAdditionalFields.size(); i++) { JsonObject fileInfo = (JsonObject) arrayOfAdditionalFields.get(i); @@ -225,7 +225,7 @@ public class JsonMessageParser { String location = getValueFromJson(data, LOCATION, missingValues); if (StringUtils.isEmpty(location)) { logger.error(ERROR_MSG_VES_EVENT_PARSING + "File information wrong. Missing location. Data: {} {}", - messageMetaData, fileInfo); + messageMetaData, fileInfo); return Optional.empty(); } Scheme scheme; @@ -233,23 +233,23 @@ public class JsonMessageParser { scheme = Scheme.getSchemeFromString(URI.create(location).getScheme()); } catch (Exception e) { logger.error(ERROR_MSG_VES_EVENT_PARSING + "{}. Location: {} Data: {}", e.getMessage(), location, - messageMetaData, e); + messageMetaData, e); return Optional.empty(); } FileData fileData = ImmutableFileData.builder() // - .name(getValueFromJson(fileInfo, NAME, missingValues)) // - .fileFormatType(getValueFromJson(data, FILE_FORMAT_TYPE, missingValues)) // - .fileFormatVersion(getValueFromJson(data, FILE_FORMAT_VERSION, missingValues)) // - .location(location) // - .scheme(scheme) // - .compression(getValueFromJson(data, COMPRESSION, missingValues)) // - .messageMetaData(messageMetaData) // - .build(); + .name(getValueFromJson(fileInfo, NAME, missingValues)) // + .fileFormatType(getValueFromJson(data, FILE_FORMAT_TYPE, missingValues)) // + .fileFormatVersion(getValueFromJson(data, FILE_FORMAT_VERSION, missingValues)) // + .location(location) // + .scheme(scheme) // + .compression(getValueFromJson(data, COMPRESSION, missingValues)) // + .messageMetaData(messageMetaData) // + .build(); if (missingValues.isEmpty()) { return Optional.of(fileData); } logger.error(ERROR_MSG_VES_EVENT_PARSING + "File information wrong. Missing data: {} Data: {}", missingValues, - fileInfo); + fileInfo); return Optional.empty(); } @@ -263,16 +263,15 @@ public class JsonMessageParser { * @return String of data from event name */ private static String getDataFromEventName(EventNameDataType dataType, String eventName, - List<String> missingValues) { + List<String> missingValues) { String[] eventArray = eventName.split("_|-"); if (eventArray.length >= 4) { return eventArray[dataType.index]; } else { missingValues.add(dataType.toString()); logger.error( - ERROR_MSG_VES_EVENT_PARSING - + "Can not get {} from eventName, eventName is not in correct format: {}", - dataType, eventName); + ERROR_MSG_VES_EVENT_PARSING + "Can not get {} from eventName, eventName is not in correct format: {}", + dataType, eventName); } return ""; } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java index 475e0224..91b74042 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java @@ -18,7 +18,6 @@ package org.onap.dcaegen2.collectors.datafile.service; import java.nio.file.Path; import java.time.Instant; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java index 198c1bf1..a46e17ba 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClient.java @@ -83,7 +83,7 @@ public class DmaapProducerHttpClient { * @throws DatafileTaskException if anything goes wrong. */ public HttpResponse getDmaapProducerResponseWithRedirect(HttpUriRequest request, Map<String, String> contextMap) - throws DatafileTaskException { + throws DatafileTaskException { MDC.setContextMap(contextMap); try (CloseableHttpAsyncClient webClient = createWebClient(true, DEFAULT_REQUEST_TIMEOUT, contextMap)) { webClient.start(); @@ -110,7 +110,7 @@ public class DmaapProducerHttpClient { * @throws DatafileTaskException if anything goes wrong. */ public HttpResponse getDmaapProducerResponseWithCustomTimeout(HttpUriRequest request, Duration requestTimeout, - Map<String, String> contextMap) throws DatafileTaskException { + Map<String, String> contextMap) throws DatafileTaskException { MDC.setContextMap(contextMap); try (CloseableHttpAsyncClient webClient = createWebClient(false, requestTimeout, contextMap)) { webClient.start(); @@ -140,13 +140,13 @@ public class DmaapProducerHttpClient { } private CloseableHttpAsyncClient createWebClient(boolean expectRedirect, Duration requestTimeout, - Map<String, String> contextMap) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { + Map<String, String> contextMap) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { SSLContext sslContext = - new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build(); + new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build(); HttpAsyncClientBuilderWrapper clientBuilder = getHttpClientBuilder(); clientBuilder.setSslContext(sslContext) // - .setSslHostnameVerifier(new NoopHostnameVerifier()); + .setSslHostnameVerifier(new NoopHostnameVerifier()); if (expectRedirect) { clientBuilder.setRedirectStrategy(new PublishRedirectStrategy(contextMap)); @@ -155,10 +155,10 @@ public class DmaapProducerHttpClient { if (requestTimeout.toMillis() > 0) { int millis = (int) requestTimeout.toMillis(); RequestConfig requestConfig = RequestConfig.custom() // - .setSocketTimeout(millis) // - .setConnectTimeout(millis) // - .setConnectionRequestTimeout(millis) // - .build(); + .setSocketTimeout(millis) // + .setConnectTimeout(millis) // + .setConnectionRequestTimeout(millis) // + .build(); clientBuilder.setDefaultRequestConfig(requestConfig); } else { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumer.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumer.java index f1d33454..081c7f39 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumer.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumer.java @@ -51,7 +51,7 @@ public class DMaaPMessageConsumer { } protected DMaaPMessageConsumer(DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient, - JsonMessageParser messageParser) { + JsonMessageParser messageParser) { this.dmaaPConsumerReactiveHttpClient = dmaaPConsumerReactiveHttpClient; this.jsonMessageParser = messageParser; } @@ -72,7 +72,7 @@ public class DMaaPMessageConsumer { } private static DMaaPConsumerReactiveHttpClient createHttpClient(AppConfig datafileAppConfig) - throws DatafileTaskException { + throws DatafileTaskException { DmaapConsumerConfiguration config = datafileAppConfig.getDmaapConsumerConfiguration().toDmaap(); WebClient client = new DmaapWebClient().fromConfiguration(config).build(); return new DMaaPConsumerReactiveHttpClient(config, client); diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java index 02e153cf..bfd3f3e3 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java @@ -22,12 +22,14 @@ package org.onap.dcaegen2.collectors.datafile.tasks; import com.google.gson.JsonElement; import com.google.gson.JsonParser; + import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.nio.file.Path; import java.time.Duration; + import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPut; import org.apache.http.entity.ContentType; @@ -79,13 +81,13 @@ public class DataRouterPublisher { * @return the (same) filePublishInformation */ public Mono<FilePublishInformation> publishFile(FilePublishInformation publishInfo, long numRetries, - Duration firstBackoff) { + Duration firstBackoff) { MDC.setContextMap(publishInfo.getContext()); return Mono.just(publishInfo) // - .cache() // - .flatMap(this::publishFile) // - .flatMap(httpStatus -> handleHttpResponse(httpStatus, publishInfo)) // - .retryBackoff(numRetries, firstBackoff); + .cache() // + .flatMap(this::publishFile) // + .flatMap(httpStatus -> handleHttpResponse(httpStatus, publishInfo)) // + .retryBackoff(numRetries, firstBackoff); } private Mono<HttpStatus> publishFile(FilePublishInformation publishInfo) { @@ -99,7 +101,7 @@ public class DataRouterPublisher { dmaapProducerHttpClient.addUserCredentialsToHead(put); HttpResponse response = - dmaapProducerHttpClient.getDmaapProducerResponseWithRedirect(put, publishInfo.getContext()); + dmaapProducerHttpClient.getDmaapProducerResponseWithRedirect(put, publishInfo.getContext()); logger.trace("{}", response); counters.incTotalPublishedFiles(); return Mono.just(HttpStatus.valueOf(response.getStatusLine().getStatusCode())); @@ -116,10 +118,10 @@ public class DataRouterPublisher { JsonElement metaData = new JsonParser().parse(JsonSerializer.createJsonBodyForDataRouter(publishInfo)); put.addHeader(X_DMAAP_DR_META, metaData.toString()); URI uri = new DefaultUriBuilderFactory( - datafileAppConfig.getPublisherConfiguration(publishInfo.getChangeIdentifier()).publishUrl()) // - .builder() // - .pathSegment(publishInfo.getName()) // - .build(); + datafileAppConfig.getPublisherConfiguration(publishInfo.getChangeIdentifier()).publishUrl()) // + .builder() // + .pathSegment(publishInfo.getName()) // + .build(); put.setURI(uri); MappedDiagnosticContext.appendTraceInfo(put); @@ -132,7 +134,7 @@ public class DataRouterPublisher { } private static Mono<FilePublishInformation> handleHttpResponse(HttpStatus response, - FilePublishInformation publishInfo) { + FilePublishInformation publishInfo) { MDC.setContextMap(publishInfo.getContext()); if (HttpUtils.isSuccessfulResponseCode(response.value())) { logger.trace("Publishing file {} to DR successful!", publishInfo.getName()); @@ -140,7 +142,7 @@ public class DataRouterPublisher { } else { logger.warn("Publishing file {} to DR unsuccessful. Response code: {}", publishInfo.getName(), response); return Mono.error(new Exception( - "Publishing file " + publishInfo.getName() + " to DR unsuccessful. Response code: " + response)); + "Publishing file " + publishInfo.getName() + " to DR unsuccessful. Response code: " + response)); } } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java index 311f752d..20bf599b 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java @@ -21,6 +21,7 @@ import java.nio.file.Paths; import java.time.Duration; import java.util.Map; import java.util.Optional; + import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig; import org.onap.dcaegen2.collectors.datafile.configuration.FtpesConfig; import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; @@ -70,15 +71,15 @@ public class FileCollector { * @return the data needed to publish the file. */ public Mono<FilePublishInformation> collectFile(FileData fileData, long numRetries, Duration firstBackoff, - Map<String, String> contextMap) { + Map<String, String> contextMap) { MDC.setContextMap(contextMap); logger.trace("Entering collectFile with {}", fileData); return Mono.just(fileData) // - .cache() // - .flatMap(fd -> tryCollectFile(fileData, contextMap)) // - .retryBackoff(numRetries, firstBackoff) // - .flatMap(FileCollector::checkCollectedFile); + .cache() // + .flatMap(fd -> tryCollectFile(fileData, contextMap)) // + .retryBackoff(numRetries, firstBackoff) // + .flatMap(FileCollector::checkCollectedFile); } private static Mono<FilePublishInformation> checkCollectedFile(Optional<FilePublishInformation> info) { @@ -105,7 +106,7 @@ public class FileCollector { return Mono.just(Optional.of(getFilePublishInformation(fileData, localFile, context))); } catch (DatafileTaskException e) { logger.warn("Failed to download file: {} {}, reason: {}", fileData.sourceName(), fileData.name(), - e.toString()); + e.toString()); counters.incNoOfFailedFtpAttempts(); if (e instanceof NonRetryableDatafileTaskException) { return Mono.just(Optional.empty()); // Give up @@ -114,7 +115,7 @@ public class FileCollector { } } catch (Exception throwable) { logger.warn("Failed to close ftp client: {} {}, reason: {}", fileData.sourceName(), fileData.name(), - throwable.toString(), throwable); + throwable.toString(), throwable); return Mono.just(Optional.of(getFilePublishInformation(fileData, localFile, context))); } } @@ -131,25 +132,25 @@ public class FileCollector { } private static FilePublishInformation getFilePublishInformation(FileData fileData, Path localFile, - Map<String, String> context) { + Map<String, String> context) { String location = fileData.location(); MessageMetaData metaData = fileData.messageMetaData(); return ImmutableFilePublishInformation.builder() // - .productName(metaData.productName()) // - .vendorName(metaData.vendorName()) // - .lastEpochMicrosec(metaData.lastEpochMicrosec()) // - .sourceName(metaData.sourceName()) // - .startEpochMicrosec(metaData.startEpochMicrosec()) // - .timeZoneOffset(metaData.timeZoneOffset()) // - .name(fileData.name()) // - .location(location) // - .internalLocation(localFile) // - .compression(fileData.compression()) // - .fileFormatType(fileData.fileFormatType()) // - .fileFormatVersion(fileData.fileFormatVersion()) // - .changeIdentifier(fileData.messageMetaData().changeIdentifier()) // - .context(context) // - .build(); + .productName(metaData.productName()) // + .vendorName(metaData.vendorName()) // + .lastEpochMicrosec(metaData.lastEpochMicrosec()) // + .sourceName(metaData.sourceName()) // + .startEpochMicrosec(metaData.startEpochMicrosec()) // + .timeZoneOffset(metaData.timeZoneOffset()) // + .name(fileData.name()) // + .location(location) // + .internalLocation(localFile) // + .compression(fileData.compression()) // + .fileFormatType(fileData.fileFormatType()) // + .fileFormatVersion(fileData.fileFormatVersion()) // + .changeIdentifier(fileData.messageMetaData().changeIdentifier()) // + .context(context) // + .build(); } protected SftpClient createSftpClient(FileData fileData) { @@ -159,6 +160,6 @@ public class FileCollector { protected FtpsClient createFtpsClient(FileData fileData) { FtpesConfig config = datafileAppConfig.getFtpesConfiguration(); return new FtpsClient(fileData.fileServerData(), config.keyCert(), config.keyPassword(), - Paths.get(config.trustedCa()), config.trustedCaPassword()); + Paths.get(config.trustedCa()), config.trustedCaPassword()); } } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedChecker.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedChecker.java index 4d8d679d..037803bd 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedChecker.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedChecker.java @@ -73,7 +73,7 @@ public class PublishedChecker { * @throws DatafileTaskException if the check fails */ public boolean isFilePublished(String fileName, String changeIdentifier, Map<String, String> contextMap) - throws DatafileTaskException { + throws DatafileTaskException { MDC.setContextMap(contextMap); PublisherConfiguration publisherConfig = resolveConfiguration(changeIdentifier); @@ -86,8 +86,8 @@ public class PublishedChecker { getRequest.setURI(getPublishedQueryUri(fileName, publisherConfig)); producerClient.addUserCredentialsToHead(getRequest); - HttpResponse response = producerClient.getDmaapProducerResponseWithCustomTimeout(getRequest, - WEB_CLIENT_TIMEOUT, contextMap); + HttpResponse response = + producerClient.getDmaapProducerResponseWithCustomTimeout(getRequest, WEB_CLIENT_TIMEOUT, contextMap); logger.trace("{}", response); int status = response.getStatusLine().getStatusCode(); @@ -104,9 +104,9 @@ public class PublishedChecker { private static URI getPublishedQueryUri(String fileName, PublisherConfiguration config) throws URISyntaxException { return new URIBuilder(config.logUrl()) // - .addParameter("type", "pub") // - .addParameter("filename", fileName) // - .build(); + .addParameter("type", "pub") // + .addParameter("filename", fileName) // + .build(); } protected PublisherConfiguration resolveConfiguration(String changeIdentifier) throws DatafileTaskException { @@ -114,7 +114,7 @@ public class PublishedChecker { } protected DmaapProducerHttpClient resolveClient(PublisherConfiguration publisherConfig) - throws DatafileTaskException { + throws DatafileTaskException { try { return new DmaapProducerHttpClient(publisherConfig.toDmaap()); } catch (MalformedURLException e) { diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java index 300ca601..bc73ddb2 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasks.java @@ -22,6 +22,7 @@ import java.time.Duration; import java.time.Instant; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; + import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig; import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException; import org.onap.dcaegen2.collectors.datafile.model.Counters; @@ -35,12 +36,12 @@ import org.slf4j.LoggerFactory; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Schedulers; - /** * This implements the main flow of the data file collector. Fetch file ready events from the * message router, fetch new files from the PNF publish these in the data router. @@ -84,10 +85,10 @@ public class ScheduledTasks { try { if (getCurrentNumberOfTasks() > MAX_TASKS_FOR_POLLING || this.threadPoolQueueSize.get() > 0) { logger.info( - "Skipping consuming new files; current number of tasks: {}, number of subscriptions: {}, " - + "published files: {}, number of queued VES events: {}", - getCurrentNumberOfTasks(), this.currentNumberOfSubscriptions.get(), publishedFilesCache.size(), - threadPoolQueueSize.get()); + "Skipping consuming new files; current number of tasks: {}, number of subscriptions: {}, " + + "published files: {}, number of queued VES events: {}", + getCurrentNumberOfTasks(), this.currentNumberOfSubscriptions.get(), publishedFilesCache.size(), + threadPoolQueueSize.get()); return; } if (this.applicationConfiguration.getDmaapConsumerConfiguration() == null) { @@ -99,15 +100,15 @@ public class ScheduledTasks { Map<String, String> context = MappedDiagnosticContext.initializeTraceContext(); logger.trace("Execution of tasks was registered"); createMainTask(context) // - .subscribe(ScheduledTasks::onSuccess, // - throwable -> { - onError(throwable, context); - currentNumberOfSubscriptions.decrementAndGet(); - }, // - () -> { - onComplete(context); - currentNumberOfSubscriptions.decrementAndGet(); - }); + .subscribe(ScheduledTasks::onSuccess, // + throwable -> { + onError(throwable, context); + currentNumberOfSubscriptions.decrementAndGet(); + }, // + () -> { + onComplete(context); + currentNumberOfSubscriptions.decrementAndGet(); + }); } catch (Exception e) { logger.error("Unexpected exception: {}", e.toString(), e); } @@ -115,21 +116,21 @@ public class ScheduledTasks { Flux<FilePublishInformation> createMainTask(Map<String, String> context) { return fetchMoreFileReadyMessages() // - .doOnNext(fileReadyMessage -> threadPoolQueueSize.incrementAndGet()) // - .doOnNext(fileReadyMessage -> counters.incNoOfReceivedEvents()) // - .parallel(NUMBER_OF_WORKER_THREADS) // Each FileReadyMessage in a separate thread - .runOn(scheduler) // - .doOnNext(fileReadyMessage -> threadPoolQueueSize.decrementAndGet()) // - .flatMap(fileReadyMessage -> Flux.fromIterable(fileReadyMessage.files())) // - .flatMap(fileData -> createMdcContext(fileData, context)) // - .filter(this::isFeedConfigured) // - .filter(this::shouldBePublished) // - .doOnNext(fileData -> currentNumberOfTasks.incrementAndGet()) // - .flatMap(this::fetchFile, false, 1, 1) // - .flatMap(this::publishToDataRouter, false, 1, 1) // - .doOnNext(publishInfo -> deleteFile(publishInfo.getInternalLocation(), publishInfo.getContext())) // - .doOnNext(publishInfo -> currentNumberOfTasks.decrementAndGet()) // - .sequential(); + .doOnNext(fileReadyMessage -> threadPoolQueueSize.incrementAndGet()) // + .doOnNext(fileReadyMessage -> counters.incNoOfReceivedEvents()) // + .parallel(NUMBER_OF_WORKER_THREADS) // Each FileReadyMessage in a separate thread + .runOn(scheduler) // + .doOnNext(fileReadyMessage -> threadPoolQueueSize.decrementAndGet()) // + .flatMap(fileReadyMessage -> Flux.fromIterable(fileReadyMessage.files())) // + .flatMap(fileData -> createMdcContext(fileData, context)) // + .filter(this::isFeedConfigured) // + .filter(this::shouldBePublished) // + .doOnNext(fileData -> currentNumberOfTasks.incrementAndGet()) // + .flatMap(this::fetchFile, false, 1, 1) // + .flatMap(this::publishToDataRouter, false, 1, 1) // + .doOnNext(publishInfo -> deleteFile(publishInfo.getInternalLocation(), publishInfo.getContext())) // + .doOnNext(publishInfo -> currentNumberOfTasks.decrementAndGet()) // + .sequential(); } private class FileDataWithContext { @@ -157,7 +158,6 @@ public class ScheduledTasks { return this.counters; } - protected DMaaPMessageConsumer createConsumerTask() throws DatafileTaskException { return new DMaaPMessageConsumer(this.applicationConfiguration); } @@ -213,7 +213,7 @@ public class ScheduledTasks { return true; } else { logger.info("No feed is configured for: {}, file ignored: {}", - fileData.fileData.messageMetaData().changeIdentifier(), fileData.fileData.name()); + fileData.fileData.messageMetaData().changeIdentifier(), fileData.fileData.name()); return false; } } @@ -223,7 +223,7 @@ public class ScheduledTasks { if (publishedFilesCache.put(localFilePath) == null) { try { boolean result = !createPublishedChecker().isFilePublished(fileData.fileData.name(), - fileData.fileData.messageMetaData().changeIdentifier(), fileData.context); + fileData.fileData.messageMetaData().changeIdentifier(), fileData.context); return result; } catch (DatafileTaskException e) { logger.error("Cannot check if a file {} is published", fileData.fileData.name(), e); @@ -237,9 +237,9 @@ public class ScheduledTasks { private Mono<FilePublishInformation> fetchFile(FileDataWithContext fileData) { MDC.setContextMap(fileData.context); return createFileCollector() // - .collectFile(fileData.fileData, FILE_TRANSFER_MAX_RETRIES, FILE_TRANSFER_INITIAL_RETRY_TIMEOUT, - fileData.context) // - .onErrorResume(exception -> handleFetchFileFailure(fileData)); + .collectFile(fileData.fileData, FILE_TRANSFER_MAX_RETRIES, FILE_TRANSFER_INITIAL_RETRY_TIMEOUT, + fileData.context) // + .onErrorResume(exception -> handleFetchFileFailure(fileData)); } private Mono<FilePublishInformation> handleFetchFileFailure(FileDataWithContext fileData) { @@ -257,8 +257,8 @@ public class ScheduledTasks { MDC.setContextMap(publishInfo.getContext()); return createDataRouterPublisher() - .publishFile(publishInfo, DATA_ROUTER_MAX_RETRIES, DATA_ROUTER_INITIAL_RETRY_TIMEOUT) - .onErrorResume(exception -> handlePublishFailure(publishInfo)); + .publishFile(publishInfo, DATA_ROUTER_MAX_RETRIES, DATA_ROUTER_INITIAL_RETRY_TIMEOUT) + .onErrorResume(exception -> handlePublishFailure(publishInfo)); } private Mono<FilePublishInformation> handlePublishFailure(FilePublishInformation publishInfo) { @@ -277,15 +277,15 @@ public class ScheduledTasks { */ Flux<FileReadyMessage> fetchMoreFileReadyMessages() { logger.info( - "Consuming new file ready messages, current number of tasks: {}, published files: {}, " - + "number of subscriptions: {}", - getCurrentNumberOfTasks(), publishedFilesCache.size(), this.currentNumberOfSubscriptions.get()); + "Consuming new file ready messages, current number of tasks: {}, published files: {}, " + + "number of subscriptions: {}", + getCurrentNumberOfTasks(), publishedFilesCache.size(), this.currentNumberOfSubscriptions.get()); Map<String, String> context = MDC.getCopyOfContextMap(); try { return createConsumerTask() // - .getMessageRouterResponse() // - .onErrorResume(exception -> handleConsumeMessageFailure(exception, context)); + .getMessageRouterResponse() // + .onErrorResume(exception -> handleConsumeMessageFailure(exception, context)); } catch (Exception e) { logger.error("Could not create message consumer task", e); return Flux.empty(); @@ -295,7 +295,7 @@ public class ScheduledTasks { private Flux<FileReadyMessage> handleConsumeMessageFailure(Throwable exception, Map<String, String> context) { MDC.setContextMap(context); logger.error("Polling for file ready message failed, exception: {}, config: {}", exception.toString(), - this.applicationConfiguration.getDmaapConsumerConfiguration()); + this.applicationConfiguration.getDmaapConsumerConfiguration()); return Flux.empty(); } diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java index 9dcf133a..cc473a78 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategy.java @@ -18,6 +18,7 @@ package org.onap.dcaegen2.collectors.datafile.web; import java.net.URI; import java.util.Map; + import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.ProtocolException; @@ -51,11 +52,11 @@ public class PublishRedirectStrategy extends DefaultRedirectStrategy { * Redirectable methods. */ private static final String[] REDIRECT_METHODS = new String[] { // - HttpPut.METHOD_NAME, // - HttpGet.METHOD_NAME, // - HttpPost.METHOD_NAME, // - HttpHead.METHOD_NAME, // - HttpDelete.METHOD_NAME // + HttpPut.METHOD_NAME, // + HttpGet.METHOD_NAME, // + HttpPost.METHOD_NAME, // + HttpHead.METHOD_NAME, // + HttpDelete.METHOD_NAME // }; /** @@ -79,7 +80,7 @@ public class PublishRedirectStrategy extends DefaultRedirectStrategy { @Override public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) - throws ProtocolException { + throws ProtocolException { MDC.setContextMap(contextMap); final URI uri = getLocationURI(request, response, context); logger.trace("getRedirect...: {}", request); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java index 31c542d3..b3710fe3 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfigTest.java @@ -29,6 +29,7 @@ import static org.mockito.Mockito.when; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; + import com.google.common.base.Charsets; import com.google.common.io.Resources; import com.google.gson.JsonElement; @@ -36,6 +37,7 @@ import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -44,6 +46,7 @@ import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Properties; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -55,6 +58,7 @@ import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.http.configuratio import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.providers.CloudConfigurationProvider; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -69,30 +73,19 @@ class AppConfigTest { private static final String CHANGE_IDENTIFIER = "PM_MEAS_FILES"; - private static final ImmutableDmaapConsumerConfiguration CORRECT_DMAAP_CONSUMER_CONFIG = // - new ImmutableDmaapConsumerConfiguration.Builder() // - .timeoutMs(-1) // - .dmaapHostName("message-router.onap.svc.cluster.local") // - .dmaapUserName("admin") // - .dmaapUserPassword("admin") // - .dmaapTopicName("events/unauthenticated.VES_NOTIFICATION_OUTPUT") // - .dmaapPortNumber(2222) // - .dmaapContentType("application/json") // - .messageLimit(-1) // - .dmaapProtocol("http") // - .consumerId("C12") // - .consumerGroup("OpenDcae-c12") // - .trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .build(); - - private static final ConsumerConfiguration CORRECT_CONSUMER_CONFIG = ImmutableConsumerConfiguration.builder() // - .topicUrl( - "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12") + new ImmutableDmaapConsumerConfiguration.Builder() // + .timeoutMs(-1) // + .dmaapHostName("message-router.onap.svc.cluster.local") // + .dmaapUserName("admin") // + .dmaapUserPassword("admin") // + .dmaapTopicName("events/unauthenticated.VES_NOTIFICATION_OUTPUT") // + .dmaapPortNumber(2222) // + .dmaapContentType("application/json") // + .messageLimit(-1) // + .dmaapProtocol("http") // + .consumerId("C12") // + .consumerGroup("OpenDcae-c12") // .trustStorePath("trustStorePath") // .trustStorePasswordPath("trustStorePasswordPath") // .keyStorePath("keyStorePath") // @@ -100,57 +93,66 @@ class AppConfigTest { .enableDmaapCertAuth(true) // .build(); + private static final ConsumerConfiguration CORRECT_CONSUMER_CONFIG = ImmutableConsumerConfiguration.builder() // + .topicUrl( + "http://admin:admin@message-router.onap.svc.cluster.local:2222/events/unauthenticated.VES_NOTIFICATION_OUTPUT/OpenDcae-c12/C12") + .trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .build(); + private static final PublisherConfiguration CORRECT_PUBLISHER_CONFIG = // - ImmutablePublisherConfiguration.builder() // - .publishUrl("https://message-router.onap.svc.cluster.local:3907/publish/1") // - .logUrl("https://dmaap.example.com/feedlog/972").trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .changeIdentifier("PM_MEAS_FILES") // - .userName("user") // - .passWord("password") // - .build(); + ImmutablePublisherConfiguration.builder() // + .publishUrl("https://message-router.onap.svc.cluster.local:3907/publish/1") // + .logUrl("https://dmaap.example.com/feedlog/972").trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .changeIdentifier("PM_MEAS_FILES") // + .userName("user") // + .passWord("password") // + .build(); private static final ImmutableFtpesConfig CORRECT_FTPES_CONFIGURATION = // - new ImmutableFtpesConfig.Builder() // - .keyCert("/config/dfc.jks") // - .keyPassword("secret") // - .trustedCa("config/ftp.jks") // - .trustedCaPassword("secret") // - .build(); + new ImmutableFtpesConfig.Builder() // + .keyCert("/config/dfc.jks") // + .keyPassword("secret") // + .trustedCa("config/ftp.jks") // + .trustedCaPassword("secret") // + .build(); private static final ImmutableDmaapPublisherConfiguration CORRECT_DMAAP_PUBLISHER_CONFIG = // - new ImmutableDmaapPublisherConfiguration.Builder() // - .dmaapTopicName("/publish/1") // - .dmaapUserPassword("password") // - .dmaapPortNumber(3907) // - .dmaapProtocol("https") // - .dmaapContentType("application/octet-stream") // - .dmaapHostName("message-router.onap.svc.cluster.local") // - .dmaapUserName("user") // - .trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .build(); + new ImmutableDmaapPublisherConfiguration.Builder() // + .dmaapTopicName("/publish/1") // + .dmaapUserPassword("password") // + .dmaapPortNumber(3907) // + .dmaapProtocol("https") // + .dmaapContentType("application/octet-stream") // + .dmaapHostName("message-router.onap.svc.cluster.local") // + .dmaapUserName("user") // + .trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .build(); private static EnvProperties properties() { return ImmutableEnvProperties.builder() // - .consulHost("host") // - .consulPort(123) // - .cbsName("cbsName") // - .appName("appName") // - .build(); + .consulHost("host") // + .consulPort(123) // + .cbsName("cbsName") // + .appName("appName") // + .build(); } private AppConfig appConfigUnderTest; private CloudConfigurationProvider cloudConfigurationProvider = mock(CloudConfigurationProvider.class); private final Map<String, String> context = MappedDiagnosticContext.initializeTraceContext(); - @BeforeEach public void setUp() { appConfigUnderTest = spy(AppConfig.class); @@ -196,9 +198,9 @@ class AppConfigTest { Assertions.assertNotNull(appConfigUnderTest.getPublisherConfiguration("YY_FILES")); assertThat(appConfigUnderTest.getPublisherConfiguration("XX_FILES").publishUrl()) - .isEqualTo("feed01::publish_url"); + .isEqualTo("feed01::publish_url"); assertThat(appConfigUnderTest.getPublisherConfiguration("YY_FILES").publishUrl()) - .isEqualTo("feed01::publish_url"); + .isEqualTo("feed01::publish_url"); } @Test @@ -213,12 +215,12 @@ class AppConfigTest { // Then assertTrue("Error message missing in log.", - logAppender.list.toString().contains("[WARN] Local configuration file not loaded: /temp.json")); + logAppender.list.toString().contains("[WARN] Local configuration file not loaded: /temp.json")); logAppender.stop(); Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration()); assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER)) - .hasMessageContaining("No PublishingConfiguration loaded, changeIdentifier: PM_MEAS_FILES"); + .hasMessageContaining("No PublishingConfiguration loaded, changeIdentifier: PM_MEAS_FILES"); Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration()); } @@ -233,7 +235,7 @@ class AppConfigTest { verify(appConfigUnderTest, times(1)).loadConfigurationFromFile(); Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration()); assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER)) - .hasMessageContaining(CHANGE_IDENTIFIER); + .hasMessageContaining(CHANGE_IDENTIFIER); Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration()); } @@ -251,7 +253,7 @@ class AppConfigTest { verify(appConfigUnderTest, times(1)).loadConfigurationFromFile(); Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration()); assertThatThrownBy(() -> appConfigUnderTest.getPublisherConfiguration(CHANGE_IDENTIFIER)) - .hasMessageContaining(CHANGE_IDENTIFIER); + .hasMessageContaining(CHANGE_IDENTIFIER); Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration()); } @@ -262,10 +264,10 @@ class AppConfigTest { Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context); StepVerifier // - .create(task) // - .expectSubscription() // - .expectNextCount(0) // - .verifyComplete(); + .create(task) // + .expectSubscription() // + .expectNextCount(0) // + .verifyComplete(); assertTrue(logAppender.list.toString().contains("$CONSUL_HOST environment has not been defined")); } @@ -281,13 +283,13 @@ class AppConfigTest { Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context); StepVerifier // - .create(task) // - .expectSubscription() // - .expectNextCount(0) // - .verifyComplete(); + .create(task) // + .expectSubscription() // + .expectNextCount(0) // + .verifyComplete(); - assertTrue(logAppender.list.toString() - .contains("Could not refresh application configuration java.io.IOException")); + assertTrue( + logAppender.list.toString().contains("Could not refresh application configuration java.io.IOException")); } @Test @@ -301,10 +303,10 @@ class AppConfigTest { Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context); StepVerifier // - .create(task) // - .expectSubscription() // - .expectNext(appConfigUnderTest) // - .verifyComplete(); + .create(task) // + .expectSubscription() // + .expectNext(appConfigUnderTest) // + .verifyComplete(); Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration()); } @@ -321,10 +323,10 @@ class AppConfigTest { Flux<AppConfig> task = appConfigUnderTest.createRefreshConfigurationTask(1L, context); StepVerifier // - .create(task) // - .expectSubscription() // - .expectNext(appConfigUnderTest) // - .verifyComplete(); + .create(task) // + .expectSubscription() // + .expectNext(appConfigUnderTest) // + .verifyComplete(); Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration()); } @@ -348,8 +350,8 @@ class AppConfigTest { private static InputStream getIncorrectJson() { String string = "{" + // - " \"configs\": {" + // - " \"dmaap\": {"; // + " \"configs\": {" + // + " \"dmaap\": {"; // return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8))); } } diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java index eba88c33..7b03e00e 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfigTest.java @@ -44,7 +44,6 @@ import org.onap.dcaegen2.collectors.datafile.tasks.ScheduledTasks; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.TaskScheduler; - import reactor.test.StepVerifier; public class SchedulerConfigTest { @@ -53,7 +52,7 @@ public class SchedulerConfigTest { private final TaskScheduler taskSchedulerMock = mock(TaskScheduler.class); private final ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class); private final SchedulerConfig schedulerUnderTest = - spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock)); + spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock)); @BeforeEach public void setUp() { @@ -72,8 +71,8 @@ public class SchedulerConfigTest { String msg = "Datafile Service has already been stopped!"; StepVerifier.create(schedulerUnderTest.getResponseFromCancellationOfTasks()) - .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) // - .verifyComplete(); + .expectNext(new ResponseEntity<String>(msg, HttpStatus.CREATED)) // + .verifyComplete(); verify(scheduledFutureMock).cancel(false); verifyNoMoreInteractions(scheduledFutureMock); @@ -88,7 +87,7 @@ public class SchedulerConfigTest { SchedulerConfig.setScheduledFutureList(scheduledFutureList); SchedulerConfig schedulerUnderTestSpy = - spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock)); + spy(new SchedulerConfig(taskSchedulerMock, scheduledTasksMock, appConfigurationMock)); boolean actualResult = schedulerUnderTestSpy.tryToStartTask(); @@ -96,10 +95,10 @@ public class SchedulerConfigTest { ArgumentCaptor<Runnable> scheduleMainDatafileEventTaskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(taskSchedulerMock).scheduleWithFixedDelay(scheduleMainDatafileEventTaskCaptor.capture(), - eq(Duration.ofSeconds(15))); + eq(Duration.ofSeconds(15))); ArgumentCaptor<Runnable> purgeCachedInformationCaptor = ArgumentCaptor.forClass(Runnable.class); verify(taskSchedulerMock).scheduleWithFixedDelay(purgeCachedInformationCaptor.capture(), - eq(Duration.ofHours(1))); + eq(Duration.ofHours(1))); verifyNoMoreInteractions(taskSchedulerMock); scheduleMainDatafileEventTaskCaptor.getValue().run(); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java index 51097f52..a80999ed 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/controller/StatusControllerTest.java @@ -26,10 +26,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; + import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.collectors.datafile.controllers.StatusController; @@ -63,7 +63,6 @@ public class StatusControllerTest { assertFalse(StringUtils.isBlank(MDC.get(MdcVariables.INVOCATION_ID))); } - @Test public void status() { ScheduledTasks scheduledTasksMock = mock(ScheduledTasks.class); @@ -83,7 +82,6 @@ public class StatusControllerTest { assertFalse(StringUtils.isBlank(MDC.get(MdcVariables.INVOCATION_ID))); } - private void validateLogging(ListAppender<ILoggingEvent> logAppender) { assertEquals(logAppender.list.get(0).getMarker().getName(), "ENTRY"); assertNotNull(logAppender.list.get(0).getMDCPropertyMap().get("InvocationID")); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java index f4e814f4..a747701a 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/FtpsClientTest.java @@ -32,8 +32,10 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Path; import java.nio.file.Paths; + import javax.net.ssl.KeyManager; import javax.net.ssl.TrustManager; + import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTPSClient; import org.junit.jupiter.api.BeforeEach; @@ -205,8 +207,7 @@ public class FtpsClientTest { doReturn(false).when(ftpsClientMock).retrieveFile(REMOTE_FILE_PATH, outputStreamMock); assertThatThrownBy(() -> clientUnderTestSpy.collectFile(REMOTE_FILE_PATH, LOCAL_FILE_PATH)) - .hasMessageContaining(REMOTE_FILE_PATH) - .hasMessageContaining("No retry"); + .hasMessageContaining(REMOTE_FILE_PATH).hasMessageContaining("No retry"); verifyFtpsClientMock_openOk(); verify(ftpsClientMock, times(1)).retrieveFile(ArgumentMatchers.eq(REMOTE_FILE_PATH), any()); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java index 693806c2..74d9ecd1 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/ftp/SftpClientTest.java @@ -31,9 +31,11 @@ import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpException; + import java.io.IOException; import java.nio.file.Paths; import java.util.Optional; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -58,13 +60,13 @@ public class SftpClientTest { @Test public void openWithPort_success() - throws DatafileTaskException, IOException, JSchException, SftpException, Exception { + throws DatafileTaskException, IOException, JSchException, SftpException, Exception { FileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(HOST) // - .userId(USERNAME) // - .password(PASSWORD) // - .port(SFTP_PORT) // - .build(); + .serverAddress(HOST) // + .userId(USERNAME) // + .password(PASSWORD) // + .port(SFTP_PORT) // + .build(); SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData)); @@ -87,13 +89,13 @@ public class SftpClientTest { @Test public void openWithoutPort_success() - throws DatafileTaskException, IOException, JSchException, SftpException, Exception { + throws DatafileTaskException, IOException, JSchException, SftpException, Exception { FileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(HOST) // - .userId(USERNAME) // - .password(PASSWORD) // - .port(Optional.empty()) // - .build(); + .serverAddress(HOST) // + .userId(USERNAME) // + .password(PASSWORD) // + .port(Optional.empty()) // + .build(); SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData)); @@ -108,13 +110,13 @@ public class SftpClientTest { @Test public void open_throwsException() - throws DatafileTaskException, IOException, JSchException, SftpException, Exception { + throws DatafileTaskException, IOException, JSchException, SftpException, Exception { FileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(HOST) // - .userId(USERNAME) // - .password(PASSWORD) // - .port(SFTP_PORT) // - .build(); + .serverAddress(HOST) // + .userId(USERNAME) // + .password(PASSWORD) // + .port(SFTP_PORT) // + .build(); SftpClient sftpClientSpy = spy(new SftpClient(expectedFileServerData)); @@ -128,11 +130,11 @@ public class SftpClientTest { @Test public void collectFile_succes() throws DatafileTaskException, SftpException { FileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(HOST) // - .userId(USERNAME) // - .password(PASSWORD) // - .port(SFTP_PORT) // - .build(); + .serverAddress(HOST) // + .userId(USERNAME) // + .password(PASSWORD) // + .port(SFTP_PORT) // + .build(); SftpClient sftpClient = new SftpClient(expectedFileServerData); sftpClient.sftpChannel = channelMock; @@ -145,24 +147,24 @@ public class SftpClientTest { @Test public void collectFile_throwsExceptionWithoutRetry() - throws IOException, JSchException, SftpException, DatafileTaskException { + throws IOException, JSchException, SftpException, DatafileTaskException { FileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(HOST) // - .userId(USERNAME) // - .password(PASSWORD) // - .port(SFTP_PORT) // - .build(); + .serverAddress(HOST) // + .userId(USERNAME) // + .password(PASSWORD) // + .port(SFTP_PORT) // + .build(); try (SftpClient sftpClient = new SftpClient(expectedFileServerData)) { sftpClient.sftpChannel = channelMock; doThrow(new SftpException(ChannelSftp.SSH_FX_NO_SUCH_FILE, "Failed")).when(channelMock).get(anyString(), - anyString()); + anyString()); assertThatThrownBy(() -> sftpClient.collectFile("remoteFile", Paths.get("localFile"))) - .isInstanceOf(DatafileTaskException.class) - .hasMessageStartingWith("Unable to get file from xNF. No retry attempts will be done") - .hasMessageContaining("Data: FileServerData{serverAddress=" + HOST + ", " + "userId=" + USERNAME - + ", password=####, port=" + SFTP_PORT); + .isInstanceOf(DatafileTaskException.class) + .hasMessageStartingWith("Unable to get file from xNF. No retry attempts will be done") + .hasMessageContaining("Data: FileServerData{serverAddress=" + HOST + ", " + "userId=" + USERNAME + + ", password=####, port=" + SFTP_PORT); } } diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java index 79666f72..35894f9c 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/model/FileDataTest.java @@ -36,56 +36,55 @@ public class FileDataTest { private static final String SERVER_ADDRESS = "192.168.0.101"; private static final int PORT_22 = 22; private static final String LOCATION_WITH_USER = - FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; + FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; private static final String LOCATION_WITHOUT_USER = - FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; - + FTPES_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; private MessageMetaData messageMetaData() { return ImmutableMessageMetaData.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(); + .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(); } private FileData properFileDataWithUser() { return ImmutableFileData.builder() // - .name("name") // - .location(LOCATION_WITH_USER) // - .compression("comp") // - .fileFormatType("type") // - .fileFormatVersion("version") // - .scheme(Scheme.FTPS) // - .messageMetaData(messageMetaData()) // - .build(); + .name("name") // + .location(LOCATION_WITH_USER) // + .compression("comp") // + .fileFormatType("type") // + .fileFormatVersion("version") // + .scheme(Scheme.FTPS) // + .messageMetaData(messageMetaData()) // + .build(); } private FileData properFileDataWithoutUser() { return ImmutableFileData.builder() // - .name("name") // - .location(LOCATION_WITHOUT_USER) // - .compression("comp") // - .fileFormatType("type") // - .fileFormatVersion("version") // - .scheme(Scheme.FTPS) // - .messageMetaData(messageMetaData()) // - .build(); + .name("name") // + .location(LOCATION_WITHOUT_USER) // + .compression("comp") // + .fileFormatType("type") // + .fileFormatVersion("version") // + .scheme(Scheme.FTPS) // + .messageMetaData(messageMetaData()) // + .build(); } @Test public void fileServerData_properLocationWithUser() { ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(SERVER_ADDRESS) // - .port(PORT_22) // - .userId(USER) // - .password(PWD) // - .build(); + .serverAddress(SERVER_ADDRESS) // + .port(PORT_22) // + .userId(USER) // + .password(PWD) // + .build(); FileServerData actualFileServerData = properFileDataWithUser().fileServerData(); assertEquals(expectedFileServerData, actualFileServerData); @@ -94,11 +93,11 @@ public class FileDataTest { @Test public void fileServerData_properLocationWithoutUser() { ImmutableFileServerData expectedFileServerData = ImmutableFileServerData.builder() // - .serverAddress(SERVER_ADDRESS) // - .port(PORT_22) // - .userId("") // - .password("") // - .build(); + .serverAddress(SERVER_ADDRESS) // + .port(PORT_22) // + .userId("") // + .password("") // + .build(); FileServerData actualFileServerData = properFileDataWithoutUser().fileServerData(); assertEquals(expectedFileServerData, actualFileServerData); @@ -114,12 +113,11 @@ public class FileDataTest { @Test public void fileServerData_properLocationWithoutPort() { ImmutableFileServerData fileServerData = ImmutableFileServerData.builder() // - .serverAddress(SERVER_ADDRESS) // - .userId("") // - .password("") // - .build(); + .serverAddress(SERVER_ADDRESS) // + .userId("") // + .password("") // + .build(); assertFalse(fileServerData.port().isPresent()); } } - diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java index b7eddaa7..2e3245a4 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/JsonMessageParserTest.java @@ -23,12 +23,15 @@ import static org.mockito.Mockito.spy; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; + import com.google.gson.JsonElement; import com.google.gson.JsonParser; + import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; import java.util.Optional; + import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.dcaegen2.collectors.datafile.ftp.Scheme; @@ -41,6 +44,7 @@ import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData; import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage; import org.onap.dcaegen2.collectors.datafile.utils.JsonMessage.AdditionalField; import org.onap.dcaegen2.collectors.datafile.utils.LoggingUtils; + import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -73,468 +77,468 @@ class JsonMessageParserTest { @Test void whenPassingCorrectJson_oneFileReadyMessage() throws URISyntaxException { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); MessageMetaData messageMetaData = ImmutableMessageMetaData.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) // - .build(); + .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) // + .build(); FileData expectedFileData = ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .scheme(Scheme.FTPS) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .messageMetaData(messageMetaData) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .scheme(Scheme.FTPS) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .messageMetaData(messageMetaData) // + .build(); List<FileData> files = new ArrayList<>(); files.add(expectedFileData); FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() // - .files(files) // - .build(); + .files(files) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNext(expectedMessage).verifyComplete(); + .expectSubscription().expectNext(expectedMessage).verifyComplete(); } @Test void whenPassingCorrectJsonWithTwoEvents_twoMessages() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); MessageMetaData messageMetaData = ImmutableMessageMetaData.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) // - .build(); + .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) // + .build(); FileData expectedFileData = ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .scheme(Scheme.FTPS) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .messageMetaData(messageMetaData) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .scheme(Scheme.FTPS) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .messageMetaData(messageMetaData) // + .build(); List<FileData> files = new ArrayList<>(); files.add(expectedFileData); FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() // - .files(files) // - .build(); + .files(files) // + .build(); String parsedString = message.getParsed(); String messageString = "[" + parsedString + "," + parsedString + "]"; JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNext(expectedMessage).expectNext(expectedMessage).verifyComplete(); + .expectSubscription().expectNext(expectedMessage).expectNext(expectedMessage).verifyComplete(); } @Test void whenPassingCorrectJsonWithoutLocation_noMessage() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).verifyComplete(); + .expectSubscription().expectNextCount(0).verifyComplete(); assertTrue(logAppender.list.toString() - .contains("[ERROR] VES event parsing. File information wrong. " + "Missing location.")); + .contains("[ERROR] VES event parsing. File information wrong. " + "Missing location.")); assertTrue(logAppender.list.get(0).toString().contains("sourceName=5GRAN_DU")); } @Test void whenPassingCorrectJsonWrongScheme_noMessage() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location("http://location.xml") // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location("http://location.xml") // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).verifyComplete(); + .expectSubscription().expectNextCount(0).verifyComplete(); assertTrue("Error missing in log", - logAppender.list.toString() - .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + Scheme.DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + "http" - + Scheme.SUPPORTED_PROTOCOLS_ERROR_MESSAGE + ". Location: http://location.xml")); + logAppender.list.toString() + .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + + Scheme.DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + "http" + Scheme.SUPPORTED_PROTOCOLS_ERROR_MESSAGE + + ". Location: http://location.xml")); assertTrue("Missing sourceName in log", logAppender.list.toString().contains("sourceName=5GRAN_DU")); } @Test void whenPassingCorrectJsonWithTwoEventsFirstNoHeader_oneFileDatan() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); MessageMetaData messageMetaData = ImmutableMessageMetaData.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) // - .build(); + .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) // + .build(); FileData expectedFileData = ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .scheme(Scheme.FTPS) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .messageMetaData(messageMetaData) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .scheme(Scheme.FTPS) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .messageMetaData(messageMetaData) // + .build(); List<FileData> files = new ArrayList<>(); files.add(expectedFileData); FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() // - .files(files) // - .build(); + .files(files) // + .build(); String parsedString = message.getParsed(); String messageString = "[{\"event\":{}}," + parsedString + "]"; JsonMessageParser jsonMessageParserUnderTest = new JsonMessageParser(); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNext(expectedMessage).verifyComplete(); + .expectSubscription().expectNext(expectedMessage).verifyComplete(); } @Test void whenPassingCorrectJsonWithFaultyEventName_noFileData() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .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(); + .eventName("Faulty event name") // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectComplete().verify(); + .expectSubscription().expectComplete().verify(); - assertTrue("Error missing in log", logAppender.list.toString().contains(ERROR_LOG_TAG - + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + assertTrue("Error missing in log", + logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + "Can not get PRODUCT_NAME from eventName, eventName is not in correct format: Faulty event name")); } @Test void whenPassingCorrectJsonWithoutName_noFileData() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).verifyComplete(); + .expectSubscription().expectNextCount(0).verifyComplete(); assertTrue("Error missing in log", - logAppender.list.toString() - .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + "File information wrong. Missing data: [name] Data: " - + message.getAdditionalFields().get(0).toString())); + logAppender.list.toString() + .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + + "File information wrong. Missing data: [name] Data: " + + message.getAdditionalFields().get(0).toString())); } @Test void whenPassingCorrectJsonWithoutAdditionalFields_noFileData() { JsonMessage message = new JsonMessage.JsonMessageBuilder() // - .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // - .changeIdentifier(CHANGE_IDENTIFIER) // - .changeType(CHANGE_TYPE) // - .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // - .build(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).verifyComplete(); + .expectSubscription().expectNextCount(0).verifyComplete(); assertTrue("Error missing in log", - logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + "Missing arrayOfNamedHashMap in message. " + message.getParsed())); + logAppender.list.toString().contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + + "Missing arrayOfNamedHashMap in message. " + message.getParsed())); } @Test void whenPassingCorrectJsonWithoutCompression_noFileData() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).verifyComplete(); + .expectSubscription().expectNextCount(0).verifyComplete(); assertTrue("Error missing in log", - logAppender.list.toString() - .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + "File information wrong. Missing data: [compression] Data: " - + message.getAdditionalFields().get(0).toString())); + logAppender.list.toString() + .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + + "File information wrong. Missing data: [compression] Data: " + + message.getAdditionalFields().get(0).toString())); } @Test void whenPassingCorrectJsonWithoutFileFormatType_noFileData() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .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(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).verifyComplete(); + .expectSubscription().expectNextCount(0).verifyComplete(); assertTrue("Error missing in log", - logAppender.list.toString() - .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + "File information wrong. Missing data: [fileFormatType] Data: " - + message.getAdditionalFields().get(0).toString())); + logAppender.list.toString() + .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + + "File information wrong. Missing data: [fileFormatType] Data: " + + message.getAdditionalFields().get(0).toString())); } @Test void whenPassingOneCorrectJsonWithoutFileFormatVersionAndOneCorrect_oneFileData() { AdditionalField additionalFaultyField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .build(); + .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(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .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(additionalFaultyField) // - .addAdditionalField(additionalField) // - .build(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalFaultyField) // + .addAdditionalField(additionalField) // + .build(); MessageMetaData messageMetaData = ImmutableMessageMetaData.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) // - .build(); + .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) // + .build(); FileData expectedFileData = ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .scheme(Scheme.FTPS) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .messageMetaData(messageMetaData) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .scheme(Scheme.FTPS) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .messageMetaData(messageMetaData) // + .build(); List<FileData> files = new ArrayList<>(); files.add(expectedFileData); FileReadyMessage expectedMessage = ImmutableFileReadyMessage.builder() // - .files(files) // - .build(); + .files(files) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNext(expectedMessage).verifyComplete(); + .expectSubscription().expectNext(expectedMessage).verifyComplete(); } @Test void whenPassingJsonWithoutMandatoryHeaderInformation_noFileData() { JsonMessage message = new JsonMessage.JsonMessageBuilder() // - .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // - .build(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .build(); String incorrectMessageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(incorrectMessageString))) - .expectSubscription().expectComplete().verify(); + .expectSubscription().expectComplete().verify(); assertTrue("Error missing in log", - logAppender.list.toString() - .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + "Missing data: [changeIdentifier, changeType, notificationFieldsVersion]. " - + "Change type is wrong: Expected: FileReady Message: " + message.getParsed())); + logAppender.list.toString() + .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + + "Missing data: [changeIdentifier, changeType, notificationFieldsVersion]. " + + "Change type is wrong: Expected: FileReady Message: " + message.getParsed())); } @Test @@ -543,47 +547,46 @@ class JsonMessageParserTest { JsonElement jsonElement = new JsonParser().parse("{}"); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just("[{}]"))).expectSubscription() - .expectComplete().verify(); + .expectComplete().verify(); assertTrue("Error missing in log", - logAppender.list.toString().contains(ERROR_LOG_TAG + "Incorrect JsonObject - missing header. ")); + logAppender.list.toString().contains(ERROR_LOG_TAG + "Incorrect JsonObject - missing header. ")); } @Test void whenPassingCorrectJsonWithIncorrectChangeType_noFileData() { AdditionalField additionalField = new JsonMessage.AdditionalFieldBuilder() // - .name(PM_FILE_NAME) // - .location(LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .name(PM_FILE_NAME) // + .location(LOCATION) // + .compression(GZIP_COMPRESSION) // + .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) // - .addAdditionalField(additionalField) // - .build(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType(INCORRECT_CHANGE_TYPE) // + .notificationFieldsVersion(NOTIFICATION_FIELDS_VERSION) // + .addAdditionalField(additionalField) // + .build(); String messageString = message.toString(); String parsedString = message.getParsed(); JsonMessageParser jsonMessageParserUnderTest = spy(new JsonMessageParser()); JsonElement jsonElement = new JsonParser().parse(parsedString); Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject())).when(jsonMessageParserUnderTest) - .getJsonObjectFromAnArray(jsonElement); + .getJsonObjectFromAnArray(jsonElement); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(JsonMessageParser.class); StepVerifier.create(jsonMessageParserUnderTest.getMessagesFromJson(Mono.just(messageString))) - .expectSubscription().expectNextCount(0).expectComplete().verify(); + .expectSubscription().expectNextCount(0).expectComplete().verify(); assertTrue("Error missing in log", - logAppender.list.toString() - .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING - + " Change type is wrong: " + INCORRECT_CHANGE_TYPE + " Expected: FileReady Message: " - + message.getParsed())); + logAppender.list.toString() + .contains(ERROR_LOG_TAG + JsonMessageParser.ERROR_MSG_VES_EVENT_PARSING + " Change type is wrong: " + + INCORRECT_CHANGE_TYPE + " Expected: FileReady Message: " + message.getParsed())); } } diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java index 64cfb38f..9960dfdd 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCacheTest.java @@ -19,6 +19,7 @@ package org.onap.dcaegen2.collectors.datafile.service; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Instant; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java index a71521cd..d4541efb 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/service/producer/DmaapProducerHttpClientTest.java @@ -71,7 +71,6 @@ class DmaapProducerHttpClientTest { private static final Map<String, String> CONTEXT_MAP = new HashMap<>(); - private DmaapProducerHttpClient producerClientUnderTestSpy; private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class); @@ -167,7 +166,7 @@ class DmaapProducerHttpClientTest { when(futureMock.get()).thenThrow(new InterruptedException("Interrupted")); producerClientUnderTestSpy.getDmaapProducerResponseWithCustomTimeout(request, TWO_SECOND_TIMEOUT, - CONTEXT_MAP); + CONTEXT_MAP); fail("Should have got an exception."); } catch (DatafileTaskException e) { diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java index 574ad18e..1bea290f 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTest.java @@ -96,94 +96,94 @@ public class DMaaPMessageConsumerTest { @BeforeAll public static void setUp() { AdditionalField ftpesAdditionalField = new JsonMessage.AdditionalFieldBuilder() // - .location(FTPES_LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .location(FTPES_LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .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") // - .addAdditionalField(ftpesAdditionalField) // - .build(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) // + .changeType(FILE_READY_CHANGE_TYPE) // + .notificationFieldsVersion("1.0") // + .addAdditionalField(ftpesAdditionalField) // + .build(); ftpesMessageString = ftpesJsonMessage.toString(); MessageMetaData messageMetaData = ImmutableMessageMetaData.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(); + .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(); ftpesFileData = ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(FTPES_LOCATION) // - .scheme(Scheme.FTPS) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .messageMetaData(messageMetaData) // - .build(); + .name(PM_FILE_NAME) // + .location(FTPES_LOCATION) // + .scheme(Scheme.FTPS) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .messageMetaData(messageMetaData) // + .build(); List<FileData> files = new ArrayList<>(); files.add(ftpesFileData); expectedFtpesMessage = ImmutableFileReadyMessage.builder() // - .files(files) // - .build(); + .files(files) // + .build(); AdditionalField sftpAdditionalField = new JsonMessage.AdditionalFieldBuilder() // - .location(SFTP_LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .build(); + .location(SFTP_LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // + .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") // - .addAdditionalField(sftpAdditionalField) // - .build(); + .eventName(NR_RADIO_ERICSSON_EVENT_NAME) // + .changeIdentifier(PM_MEAS_CHANGE_IDENTIFIER) // + .changeType(FILE_READY_CHANGE_TYPE) // + .notificationFieldsVersion("1.0") // + .addAdditionalField(sftpAdditionalField) // + .build(); sftpMessageString = sftpJsonMessage.toString(); sftpFileData = ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(SFTP_LOCATION) // - .scheme(Scheme.FTPS) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .messageMetaData(messageMetaData) // - .build(); + .name(PM_FILE_NAME) // + .location(SFTP_LOCATION) // + .scheme(Scheme.FTPS) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .messageMetaData(messageMetaData) // + .build(); ImmutableFilePublishInformation filePublishInformation = ImmutableFilePublishInformation.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) // - .changeIdentifier(CHANGE_IDENTIFIER) // - .context(new HashMap<String,String>()) // - .build(); + .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) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .context(new HashMap<String, String>()) // + .build(); listOfFilePublishInformation.add(filePublishInformation); files = new ArrayList<>(); files.add(sftpFileData); expectedSftpMessage = ImmutableFileReadyMessage.builder() // - .files(files) // - .build(); + .files(files) // + .build(); } @Test @@ -191,9 +191,9 @@ public class DMaaPMessageConsumerTest { prepareMocksForDmaapConsumer("", null); StepVerifier.create(messageConsumer.getMessageRouterResponse()) // - .expectSubscription() // - .expectError(DatafileTaskException.class) // - .verify(); + .expectSubscription() // + .expectError(DatafileTaskException.class) // + .verify(); verify(httpClientMock, times(1)).getDMaaPConsumerResponse(); } @@ -203,8 +203,8 @@ public class DMaaPMessageConsumerTest { prepareMocksForDmaapConsumer(ftpesMessageString, expectedFtpesMessage); StepVerifier.create(messageConsumer.getMessageRouterResponse()) // - .expectNext(expectedFtpesMessage) // - .verifyComplete(); + .expectNext(expectedFtpesMessage) // + .verifyComplete(); verify(httpClientMock, times(1)).getDMaaPConsumerResponse(); verifyNoMoreInteractions(httpClientMock); @@ -215,8 +215,8 @@ public class DMaaPMessageConsumerTest { prepareMocksForDmaapConsumer(sftpMessageString, expectedSftpMessage); StepVerifier.create(messageConsumer.getMessageRouterResponse()) // - .expectNext(expectedSftpMessage) // - .verifyComplete(); + .expectNext(expectedSftpMessage) // + .verifyComplete(); verify(httpClientMock, times(1)).getDMaaPConsumerResponse(); verifyNoMoreInteractions(httpClientMock); @@ -230,10 +230,10 @@ public class DMaaPMessageConsumerTest { if (!message.isEmpty()) { when(jsonMessageParserMock.getMessagesFromJson(messageAsMono)) - .thenReturn(Flux.just(fileReadyMessageAfterConsume)); + .thenReturn(Flux.just(fileReadyMessageAfterConsume)); } else { when(jsonMessageParserMock.getMessagesFromJson(messageAsMono)) - .thenReturn(Flux.error(new DatafileTaskException("problemas"))); + .thenReturn(Flux.error(new DatafileTaskException("problemas"))); } messageConsumer = spy(new DMaaPMessageConsumer(httpClientMock, jsonMessageParserMock)); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java index 6a9dccda..a585bf9c 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisherTest.java @@ -27,10 +27,10 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -import java.io.File; - import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; + +import java.io.File; import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; @@ -39,6 +39,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -97,28 +98,28 @@ class DataRouterPublisherTest { // "https://54.45.333.2:1234/publish/1"; private static final String PUBLISH_URL = - HTTPS_SCHEME + "://" + HOST + ":" + PORT + "/" + PUBLISH_TOPIC + "/" + FEED_ID; + HTTPS_SCHEME + "://" + HOST + ":" + PORT + "/" + PUBLISH_TOPIC + "/" + FEED_ID; @BeforeAll public static void setUp() { when(publisherConfigurationMock.publishUrl()).thenReturn(PUBLISH_URL); filePublishInformation = ImmutableFilePublishInformation.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_ADDRESS) // - .internalLocation(Paths.get("target/" + PM_FILE_NAME)) // - .compression("gzip") // - .fileFormatType(FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .context(context) // - .changeIdentifier(CHANGE_IDENTIFIER) // - .build(); // + .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_ADDRESS) // + .internalLocation(Paths.get("target/" + PM_FILE_NAME)) // + .compression("gzip") // + .fileFormatType(FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .context(context) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .build(); // appConfig = mock(AppConfig.class); publisherTaskUnderTestSpy = spy(new DataRouterPublisher(appConfig, new Counters())); } @@ -127,9 +128,9 @@ class DataRouterPublisherTest { public void whenPassedObjectFits_ReturnsCorrectStatus() throws Exception { prepareMocksForTests(null, Integer.valueOf(HttpStatus.OK.value())); StepVerifier // - .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0))) - .expectNext(filePublishInformation) // - .verifyComplete(); + .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0))) + .expectNext(filePublishInformation) // + .verifyComplete(); ArgumentCaptor<HttpUriRequest> requestCaptor = ArgumentCaptor.forClass(HttpUriRequest.class); verify(httpClientMock).addUserCredentialsToHead(any(HttpUriRequest.class)); @@ -176,22 +177,22 @@ class DataRouterPublisherTest { ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(DataRouterPublisher.class); StepVerifier.create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 2, Duration.ofSeconds(0))) - .expectNext(filePublishInformation) // - .verifyComplete(); + .expectNext(filePublishInformation) // + .verifyComplete(); - assertTrue("Warning missing in log", logAppender.list.toString() - .contains("[WARN] Publishing file " + PM_FILE_NAME + " to DR unsuccessful.")); + assertTrue("Warning missing in log", + logAppender.list.toString().contains("[WARN] Publishing file " + PM_FILE_NAME + " to DR unsuccessful.")); } @Test public void whenPassedObjectFits_firstFailsThenSucceeds() throws Exception { prepareMocksForTests(null, Integer.valueOf(HttpStatus.BAD_GATEWAY.value()), - Integer.valueOf(HttpStatus.OK.value())); + Integer.valueOf(HttpStatus.OK.value())); StepVerifier // - .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0))) - .expectNext(filePublishInformation) // - .verifyComplete(); + .create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0))) + .expectNext(filePublishInformation) // + .verifyComplete(); verify(httpClientMock, times(2)).addUserCredentialsToHead(any(HttpUriRequest.class)); verify(httpClientMock, times(2)).getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any()); @@ -201,15 +202,15 @@ class DataRouterPublisherTest { @Test public void whenPassedObjectFits_firstFailsThenFails() throws Exception { prepareMocksForTests(null, Integer.valueOf(HttpStatus.BAD_GATEWAY.value()), - Integer.valueOf((HttpStatus.BAD_GATEWAY.value()))); + Integer.valueOf((HttpStatus.BAD_GATEWAY.value()))); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(DataRouterPublisher.class); StepVerifier.create(publisherTaskUnderTestSpy.publishFile(filePublishInformation, 1, Duration.ofSeconds(0))) - .expectErrorMessage("Retries exhausted: 1/1") // - .verify(); + .expectErrorMessage("Retries exhausted: 1/1") // + .verify(); assertTrue("Warning missing in log", logAppender.list.toString().contains("[WARN] Publishing file " - + PM_FILE_NAME + " to DR unsuccessful. Response code: " + HttpStatus.BAD_GATEWAY)); + + PM_FILE_NAME + " to DR unsuccessful. Response code: " + HttpStatus.BAD_GATEWAY)); verify(httpClientMock, times(2)).addUserCredentialsToHead(any(HttpUriRequest.class)); verify(httpClientMock, times(2)).getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any()); @@ -218,7 +219,7 @@ class DataRouterPublisherTest { @SafeVarargs final void prepareMocksForTests(Exception exception, Integer firstResponse, Integer... nextHttpResponses) - throws Exception { + throws Exception { httpClientMock = mock(DmaapProducerHttpClient.class); when(appConfig.getPublisherConfiguration(CHANGE_IDENTIFIER)).thenReturn(publisherConfigurationMock); doReturn(publisherConfigurationMock).when(publisherTaskUnderTestSpy).resolveConfiguration(CHANGE_IDENTIFIER); @@ -227,10 +228,10 @@ class DataRouterPublisherTest { HttpResponse httpResponseMock = mock(HttpResponse.class); if (exception == null) { when(httpClientMock.getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any())) - .thenReturn(httpResponseMock); + .thenReturn(httpResponseMock); } else { when(httpClientMock.getDmaapProducerResponseWithRedirect(any(HttpUriRequest.class), any())) - .thenThrow(exception).thenReturn(httpResponseMock); + .thenThrow(exception).thenReturn(httpResponseMock); } StatusLine statusLineMock = mock(StatusLine.class); when(httpResponseMock.getStatusLine()).thenReturn(statusLineMock); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java index 99e92bd2..1a3b2055 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollectorTest.java @@ -48,7 +48,6 @@ import org.onap.dcaegen2.collectors.datafile.model.ImmutableFileData; import org.onap.dcaegen2.collectors.datafile.model.ImmutableFilePublishInformation; import org.onap.dcaegen2.collectors.datafile.model.ImmutableMessageMetaData; import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData; - import reactor.test.StepVerifier; public class FileCollectorTest { @@ -70,10 +69,10 @@ public class FileCollectorTest { private static final String USER = "usr"; private static final String PWD = "pwd"; private static final String FTPES_LOCATION = - FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; + FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; private static final String FTPES_LOCATION_NO_PORT = - FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + REMOTE_FILE_LOCATION; + FTPES_SCHEME + USER + ":" + PWD + "@" + SERVER_ADDRESS + REMOTE_FILE_LOCATION; private static final String SFTP_LOCATION = SFTP_SCHEME + SERVER_ADDRESS + ":" + PORT_22 + REMOTE_FILE_LOCATION; private static final String SFTP_LOCATION_NO_PORT = SFTP_SCHEME + SERVER_ADDRESS + REMOTE_FILE_LOCATION; @@ -99,46 +98,46 @@ public class FileCollectorTest { private MessageMetaData createMessageMetaData() { return ImmutableMessageMetaData.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(); + .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(); } private FileData createFileData(String location, Scheme scheme) { return ImmutableFileData.builder() // - .name(PM_FILE_NAME) // - .location(location) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .scheme(scheme) // - .messageMetaData(createMessageMetaData()) // - .build(); + .name(PM_FILE_NAME) // + .location(location) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .scheme(scheme) // + .messageMetaData(createMessageMetaData()) // + .build(); } private FilePublishInformation createExpectedFilePublishInformation(String location) { return ImmutableFilePublishInformation.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(location) // - .internalLocation(LOCAL_FILE_LOCATION) // - .compression(GZIP_COMPRESSION) // - .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // - .fileFormatVersion(FILE_FORMAT_VERSION) // - .context(new HashMap<String, String>()) // - .changeIdentifier(CHANGE_IDENTIFIER) // - .build(); + .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(location) // + .internalLocation(LOCAL_FILE_LOCATION) // + .compression(GZIP_COMPRESSION) // + .fileFormatType(MEAS_COLLECT_FILE_FORMAT_TYPE) // + .fileFormatVersion(FILE_FORMAT_VERSION) // + .context(new HashMap<String, String>()) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .build(); } /** @@ -161,11 +160,11 @@ public class FileCollectorTest { FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS); FilePublishInformation expectedfilePublishInformation = - createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT); + createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT); StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap)) - .expectNext(expectedfilePublishInformation) // - .verifyComplete(); + .expectNext(expectedfilePublishInformation) // + .verifyComplete(); verify(ftpsClientMock, times(1)).open(); verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); @@ -179,22 +178,21 @@ public class FileCollectorTest { FileCollector collectorUndetTest = spy(new FileCollector(appConfigMock, counters)); doReturn(sftpClientMock).when(collectorUndetTest).createSftpClient(any()); - FileData fileData = createFileData(SFTP_LOCATION_NO_PORT, Scheme.SFTP); FilePublishInformation expectedfilePublishInformation = - createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT); + createExpectedFilePublishInformation(SFTP_LOCATION_NO_PORT); StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap)) - .expectNext(expectedfilePublishInformation) // - .verifyComplete(); + .expectNext(expectedfilePublishInformation) // + .verifyComplete(); // The same again, but with port fileData = createFileData(SFTP_LOCATION, Scheme.SFTP); expectedfilePublishInformation = createExpectedFilePublishInformation(SFTP_LOCATION); StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap)) - .expectNext(expectedfilePublishInformation) // - .verifyComplete(); + .expectNext(expectedfilePublishInformation) // + .verifyComplete(); verify(sftpClientMock, times(2)).open(); verify(sftpClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); @@ -209,11 +207,11 @@ public class FileCollectorTest { FileData fileData = createFileData(FTPES_LOCATION, Scheme.FTPS); doThrow(new DatafileTaskException("Unable to collect file.")).when(ftpsClientMock) - .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); + .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap)) - .expectErrorMessage("Retries exhausted: 3/3") // - .verify(); + .expectErrorMessage("Retries exhausted: 3/3") // + .verify(); verify(ftpsClientMock, times(4)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); } @@ -225,11 +223,11 @@ public class FileCollectorTest { FileData fileData = createFileData(FTPES_LOCATION, Scheme.FTPS); doThrow(new NonRetryableDatafileTaskException("Unable to collect file.")).when(ftpsClientMock) - .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); + .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap)) - .expectErrorMessage("Non retryable file transfer failure") // - .verify(); + .expectErrorMessage("Non retryable file transfer failure") // + .verify(); verify(ftpsClientMock, times(1)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); } @@ -239,16 +237,16 @@ public class FileCollectorTest { FileCollector collectorUndetTest = spy(new FileCollector(appConfigMock, counters)); doReturn(ftpsClientMock).when(collectorUndetTest).createFtpsClient(any()); doThrow(new DatafileTaskException("Unable to collect file.")).doNothing().when(ftpsClientMock) - .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); + .collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); FilePublishInformation expectedfilePublishInformation = - createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT); + createExpectedFilePublishInformation(FTPES_LOCATION_NO_PORT); FileData fileData = createFileData(FTPES_LOCATION_NO_PORT, Scheme.FTPS); StepVerifier.create(collectorUndetTest.collectFile(fileData, 3, Duration.ofSeconds(0), contextMap)) - .expectNext(expectedfilePublishInformation) // - .verifyComplete(); + .expectNext(expectedfilePublishInformation) // + .verifyComplete(); verify(ftpsClientMock, times(2)).collectFile(REMOTE_FILE_LOCATION, LOCAL_FILE_LOCATION); } diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java index 52640140..3a387e28 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/PublishedCheckerTest.java @@ -36,6 +36,7 @@ import java.io.InputStream; import java.net.URI; import java.util.HashMap; import java.util.Map; + import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -67,7 +68,6 @@ public class PublishedCheckerTest { private PublishedChecker publishedCheckerUnderTestSpy; - @BeforeAll private static void setUp() throws DatafileTaskException { when(publisherConfigurationMock.publishUrl()).thenReturn(PUBLISH_URL); @@ -81,7 +81,7 @@ public class PublishedCheckerTest { prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, null); boolean isPublished = - publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); + publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); assertFalse(isPublished); @@ -103,7 +103,7 @@ public class PublishedCheckerTest { prepareMocksForTests(HttpUtils.SC_BAD_REQUEST, EMPTY_CONTENT, null); boolean isPublished = - publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); + publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); assertFalse(isPublished); } @@ -113,7 +113,7 @@ public class PublishedCheckerTest { prepareMocksForTests(HttpUtils.SC_OK, "[" + LOCAL_FILE_NAME + "]", null); boolean isPublished = - publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); + publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); assertTrue(isPublished); } @@ -123,7 +123,7 @@ public class PublishedCheckerTest { prepareMocksForTests(HttpUtils.SC_OK, EMPTY_CONTENT, new DatafileTaskException("")); boolean isPublished = - publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); + publishedCheckerUnderTestSpy.isFilePublished(LOCAL_FILE_NAME, CHANGE_IDENTIFIER, CONTEXT_MAP); assertFalse(isPublished); } @@ -138,10 +138,10 @@ public class PublishedCheckerTest { HttpResponse httpResponseMock = mock(HttpResponse.class); if (exception == null) { when(httpClientMock.getDmaapProducerResponseWithCustomTimeout(any(HttpUriRequest.class), any(), any())) - .thenReturn(httpResponseMock); + .thenReturn(httpResponseMock); } else { when(httpClientMock.getDmaapProducerResponseWithCustomTimeout(any(HttpUriRequest.class), any(), any())) - .thenThrow(exception); + .thenThrow(exception); } HttpEntity httpEntityMock = mock(HttpEntity.class); StatusLine statusLineMock = mock(StatusLine.class); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java index 3df2edae..edbf5880 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/tasks/ScheduledTasksTest.java @@ -37,6 +37,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; + import java.nio.file.Paths; import java.time.Duration; import java.time.Instant; @@ -44,6 +45,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,6 +67,7 @@ import org.onap.dcaegen2.collectors.datafile.model.MessageMetaData; import org.onap.dcaegen2.collectors.datafile.utils.LoggingUtils; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables; import org.slf4j.MDC; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -103,24 +106,24 @@ public class ScheduledTasksTest { private void setUpConfiguration() throws DatafileTaskException { final PublisherConfiguration dmaapPublisherConfiguration = ImmutablePublisherConfiguration.builder() // - .publishUrl(publishUrl) // - .logUrl("") // - .userName("userName") // - .passWord("passWord") // - .trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .changeIdentifier(CHANGE_IDENTIFIER) // - .build(); // + .publishUrl(publishUrl) // + .logUrl("") // + .userName("userName") // + .passWord("passWord") // + .trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .changeIdentifier(CHANGE_IDENTIFIER) // + .build(); // final ConsumerConfiguration dmaapConsumerConfiguration = ImmutableConsumerConfiguration.builder() // - .topicUrl("topicUrl").trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .build(); + .topicUrl("topicUrl").trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .build(); doReturn(dmaapPublisherConfiguration).when(appConfig).getPublisherConfiguration(CHANGE_IDENTIFIER); doReturn(dmaapConsumerConfiguration).when(appConfig).getDmaapConsumerConfiguration(); @@ -129,27 +132,27 @@ public class ScheduledTasksTest { private MessageMetaData messageMetaData() { return ImmutableMessageMetaData.builder() // - .productName("productName") // - .vendorName("") // - .lastEpochMicrosec("") // - .sourceName("") // - .startEpochMicrosec("") // - .timeZoneOffset("") // - .changeIdentifier(CHANGE_IDENTIFIER) // - .changeType("") // - .build(); + .productName("productName") // + .vendorName("") // + .lastEpochMicrosec("") // + .sourceName("") // + .startEpochMicrosec("") // + .timeZoneOffset("") // + .changeIdentifier(CHANGE_IDENTIFIER) // + .changeType("") // + .build(); } private FileData fileData(int instanceNumber) { return ImmutableFileData.builder() // - .name(PM_FILE_NAME + instanceNumber) // - .fileFormatType("") // - .fileFormatVersion("") // - .location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) // - .scheme(Scheme.FTPS) // - .compression("") // - .messageMetaData(messageMetaData()) // - .build(); + .name(PM_FILE_NAME + instanceNumber) // + .fileFormatType("") // + .fileFormatVersion("") // + .location("ftpes://192.168.0.101/ftp/rop/" + PM_FILE_NAME + instanceNumber) // + .scheme(Scheme.FTPS) // + .compression("") // + .messageMetaData(messageMetaData()) // + .build(); } private List<FileData> files(int size, boolean uniqueNames) { @@ -177,21 +180,21 @@ public class ScheduledTasksTest { private FilePublishInformation filePublishInformation() { return ImmutableFilePublishInformation // - .builder() // - .productName("") // - .vendorName("") // - .lastEpochMicrosec("") // - .sourceName("") // - .startEpochMicrosec("") // - .timeZoneOffset("") // - .name("") // - .location("") // - .internalLocation(Paths.get("internalLocation")) // - .compression("") // - .fileFormatType("") // - .fileFormatVersion("") // - .changeIdentifier(CHANGE_IDENTIFIER) // - .context(new HashMap<String, String>()).build(); + .builder() // + .productName("") // + .vendorName("") // + .lastEpochMicrosec("") // + .sourceName("") // + .startEpochMicrosec("") // + .timeZoneOffset("") // + .name("") // + .location("") // + .internalLocation(Paths.get("internalLocation")) // + .compression("") // + .fileFormatType("") // + .fileFormatVersion("") // + .changeIdentifier(CHANGE_IDENTIFIER) // + .context(new HashMap<String, String>()).build(); } @Test @@ -256,24 +259,24 @@ public class ScheduledTasksTest { @Test public void executeDatafileMainTask_unconfiguredChangeIdentifier() throws DatafileTaskException { final PublisherConfiguration dmaapPublisherConfiguration = ImmutablePublisherConfiguration.builder() // - .publishUrl(publishUrl) // - .logUrl("") // - .userName("userName") // - .passWord("passWord") // - .trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .changeIdentifier("Different changeIdentifier") // - .build(); // + .publishUrl(publishUrl) // + .logUrl("") // + .userName("userName") // + .passWord("passWord") // + .trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .changeIdentifier("Different changeIdentifier") // + .build(); // final ConsumerConfiguration dmaapConsumerConfiguration = ImmutableConsumerConfiguration.builder() // - .topicUrl("topicUrl").trustStorePath("trustStorePath") // - .trustStorePasswordPath("trustStorePasswordPath") // - .keyStorePath("keyStorePath") // - .keyStorePasswordPath("keyStorePasswordPath") // - .enableDmaapCertAuth(true) // - .build(); + .topicUrl("topicUrl").trustStorePath("trustStorePath") // + .trustStorePasswordPath("trustStorePasswordPath") // + .keyStorePath("keyStorePath") // + .keyStorePasswordPath("keyStorePasswordPath") // + .enableDmaapCertAuth(true) // + .build(); doReturn(dmaapPublisherConfiguration).when(appConfig).getPublisherConfiguration(CHANGE_IDENTIFIER); doReturn(dmaapConsumerConfiguration).when(appConfig).getDmaapConsumerConfiguration(); @@ -290,7 +293,7 @@ public class ScheduledTasksTest { await().untilAsserted(() -> assertEquals(0, testedObject.getCurrentNumberOfSubscriptions())); assertTrue("Error missing in log", logAppender.list.toString().contains( - "[INFO] No feed is configured for: " + CHANGE_IDENTIFIER + ", file ignored: " + PM_FILE_NAME + "1")); + "[INFO] No feed is configured for: " + CHANGE_IDENTIFIER + ", file ignored: " + PM_FILE_NAME + "1")); } @Test @@ -300,14 +303,14 @@ public class ScheduledTasksTest { ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(ScheduledTasks.class); StepVerifier // - .create(testedObject.createMainTask(contextMap)) // - .expectSubscription() // - .expectNextCount(0) // - .expectComplete() // - .verify(); // - - assertTrue("Error missing in log", logAppender.list.toString().contains( - "[ERROR] Polling for file ready message failed, " + "exception: java.lang.Exception: Failed")); + .create(testedObject.createMainTask(contextMap)) // + .expectSubscription() // + .expectNextCount(0) // + .expectComplete() // + .verify(); // + + assertTrue("Error missing in log", logAppender.list.toString() + .contains("[ERROR] Polling for file ready message failed, " + "exception: java.lang.Exception: Failed")); } @Test @@ -328,11 +331,11 @@ public class ScheduledTasksTest { doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull()); StepVerifier // - .create(testedObject.createMainTask(contextMap)) // - .expectSubscription() // - .expectNextCount(noOfFiles) // - .expectComplete() // - .verify(); // + .create(testedObject.createMainTask(contextMap)) // + .expectSubscription() // + .expectNextCount(noOfFiles) // + .expectComplete() // + .verify(); // assertEquals(0, testedObject.getCurrentNumberOfTasks()); assertEquals(0, testedObject.getThreadPoolQueueSize()); @@ -358,18 +361,18 @@ public class ScheduledTasksTest { // First file collect will fail, 3 will succeed doReturn(error, collectedFile, collectedFile, collectedFile) // - .when(fileCollectorMock) // - .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull()); + .when(fileCollectorMock) // + .collectFile(any(FileData.class), anyLong(), any(Duration.class), notNull()); doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull()); doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull()); StepVerifier // - .create(testedObject.createMainTask(contextMap)) // - .expectSubscription() // - .expectNextCount(3) // - .expectComplete() // - .verify(); // + .create(testedObject.createMainTask(contextMap)) // + .expectSubscription() // + .expectNextCount(3) // + .expectComplete() // + .verify(); // assertEquals(0, testedObject.getCurrentNumberOfTasks()); verify(consumerMock, times(1)).getMessageRouterResponse(); @@ -395,16 +398,16 @@ public class ScheduledTasksTest { Mono<Object> error = Mono.error(new Exception("problem")); // One publish will fail, the rest will succeed doReturn(collectedFile, error, collectedFile, collectedFile) // - .when(dataRouterMock) // - .publishFile(notNull(), anyLong(), notNull()); + .when(dataRouterMock) // + .publishFile(notNull(), anyLong(), notNull()); ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(ScheduledTasks.class); StepVerifier // - .create(testedObject.createMainTask(contextMap)) // - .expectSubscription() // - .expectNextCount(3) // 3 completed files - .expectComplete() // - .verify(); // + .create(testedObject.createMainTask(contextMap)) // + .expectSubscription() // + .expectNextCount(3) // 3 completed files + .expectComplete() // + .verify(); // assertTrue("Error missing in log", logAppender.list.toString().contains("[ERROR] File publishing failed: ")); @@ -435,10 +438,10 @@ public class ScheduledTasksTest { doReturn(collectedFile).when(dataRouterMock).publishFile(notNull(), anyLong(), notNull()); StepVerifier // - .create(testedObject.createMainTask(contextMap)).expectSubscription() // - .expectNextCount(1) // 99 is skipped - .expectComplete() // - .verify(); // + .create(testedObject.createMainTask(contextMap)).expectSubscription() // + .expectNextCount(1) // 99 is skipped + .expectComplete() // + .verify(); // assertEquals(0, testedObject.getCurrentNumberOfTasks()); verify(consumerMock, times(1)).getMessageRouterResponse(); 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 2402e8bf..7c2706d0 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 @@ -65,39 +65,39 @@ public class JsonMessage { additionalFieldsString.append("]"); } return "{" // - + "\"event\":" // - + "{" // - + "\"commonEventHeader\":" // - + "{" // - + "\"domain\":\"notification\"," // - + "\"eventId\":\"<<SerialNumber>>-reg\"," // - + "\"eventName\":\"" + eventName + "\"," // - + "\"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\":" // - + "{" // - + getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier, - changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0) - + getAsStringIfParameterIsSet("changeType", changeType, - notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0) - + getAsStringIfParameterIsSet("notificationFieldsVersion", notificationFieldsVersion, - arrayOfAdditionalFields.size() > 0) - + additionalFieldsString.toString() // - + "}" // - + "}" // - + "}"; + + "\"event\":" // + + "{" // + + "\"commonEventHeader\":" // + + "{" // + + "\"domain\":\"notification\"," // + + "\"eventId\":\"<<SerialNumber>>-reg\"," // + + "\"eventName\":\"" + eventName + "\"," // + + "\"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\":" // + + "{" // + + getAsStringIfParameterIsSet("changeIdentifier", changeIdentifier, + changeType != null || notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0) + + getAsStringIfParameterIsSet("changeType", changeType, + notificationFieldsVersion != null || arrayOfAdditionalFields.size() > 0) + + getAsStringIfParameterIsSet("notificationFieldsVersion", notificationFieldsVersion, + arrayOfAdditionalFields.size() > 0) + + additionalFieldsString.toString() // + + "}" // + + "}" // + + "}"; } private JsonMessage(final JsonMessageBuilder builder) { @@ -118,17 +118,17 @@ public class JsonMessage { @Override public String toString() { return "{" // - + getAsStringIfParameterIsSet("name", name, true) // - + "\"hashMap\":" // - + "{" - + getAsStringIfParameterIsSet("location", location, - compression != null || fileFormatType != null || fileFormatVersion != null) - + getAsStringIfParameterIsSet("compression", compression, - fileFormatType != null || fileFormatVersion != null) - + getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null) - + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) // - + "}" // - + "}"; + + getAsStringIfParameterIsSet("name", name, true) // + + "\"hashMap\":" // + + "{" + + getAsStringIfParameterIsSet("location", location, + compression != null || fileFormatType != null || fileFormatVersion != null) + + getAsStringIfParameterIsSet("compression", compression, + fileFormatType != null || fileFormatVersion != null) + + getAsStringIfParameterIsSet("fileFormatType", fileFormatType, fileFormatVersion != null) + + getAsStringIfParameterIsSet("fileFormatVersion", fileFormatVersion, false) // + + "}" // + + "}"; } private AdditionalField(AdditionalFieldBuilder builder) { @@ -216,7 +216,7 @@ public class JsonMessage { } private static String getAsStringIfParameterIsSet(String parameterName, String parameterValue, - boolean withSeparator) { + boolean withSeparator) { String result = ""; if (parameterValue != null) { result = "\"" + parameterName + "\":\"" + parameterValue + "\""; @@ -236,27 +236,27 @@ public class JsonMessage { */ 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(); + .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(); + .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() // - .eventName("Noti_NrRadio-Ericsson_FileReady") // - .changeIdentifier("PM_MEAS_FILES") // - .changeType("FileReady") // - .notificationFieldsVersion("2.0") // - .addAdditionalField(additionalField) // - .addAdditionalField(secondAdditionalField) // - .build(); + .eventName("Noti_NrRadio-Ericsson_FileReady") // + .changeIdentifier("PM_MEAS_FILES") // + .changeType("FileReady") // + .notificationFieldsVersion("2.0") // + .addAdditionalField(additionalField) // + .addAdditionalField(secondAdditionalField) // + .build(); System.out.println(message.toString()); } } diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java index 45edac79..604bba3e 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/utils/LoggingUtils.java @@ -23,13 +23,14 @@ package org.onap.dcaegen2.collectors.datafile.utils; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; + import org.slf4j.LoggerFactory; public class LoggingUtils { /** * Returns a ListAppender that contains all logging events. Call this method at the very beginning of the test - * */ + */ public static ListAppender<ILoggingEvent> getLogListAppender(Class<?> logClass) { Logger logger = (Logger) LoggerFactory.getLogger(logClass); ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java index 6d3a98b7..d496aebc 100644 --- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java +++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/web/PublishRedirectStrategyTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.Map; + import org.apache.http.Header; import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; |