summaryrefslogtreecommitdiffstats
path: root/datafile-app-server
diff options
context:
space:
mode:
Diffstat (limited to 'datafile-app-server')
-rw-r--r--datafile-app-server/pom.xml5
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/AppConfig.java271
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java39
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java144
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/SchedulerConfig.java2
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTask.java6
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DataRouterPublisher.java3
-rw-r--r--datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/FileCollector.java3
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java105
-rw-r--r--datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java8
10 files changed, 153 insertions, 433 deletions
diff --git a/datafile-app-server/pom.xml b/datafile-app-server/pom.xml
index 4e8f5c58..90b6fea6 100644
--- a/datafile-app-server/pom.xml
+++ b/datafile-app-server/pom.xml
@@ -215,5 +215,10 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-configuration-processor</artifactId>
+ <optional>true</optional>
+ </dependency>
</dependencies>
</project>
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 5bbacb14..40de33dd 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
@@ -20,14 +20,21 @@ package org.onap.dcaegen2.collectors.datafile.configuration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
-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 org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
+import java.io.*;
+import java.util.ServiceLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;
-
-import java.util.Optional;
-import java.util.function.Predicate;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.TypeAdapterFactory;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
@@ -35,199 +42,95 @@ import java.util.function.Predicate;
*/
@Component
-@Configuration
-public class AppConfig extends DatafileAppConfig {
-
- private static Predicate<String> isEmpty = String::isEmpty;
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapHostName:}")
- public String consumerDmaapHostName;
-
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapPortNumber:}")
- public Integer consumerDmaapPortNumber;
-
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapTopicName:}")
- public String consumerDmaapTopicName;
-
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapProtocol:}")
- public String consumerDmaapProtocol;
-
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapUserName:}")
- public String consumerDmaapUserName;
-
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapUserPassword:}")
- public String consumerDmaapUserPassword;
-
- @Value("${dmaap.dmaapConsumerConfiguration.dmaapContentType:}")
- public String consumerDmaapContentType;
-
- @Value("${dmaap.dmaapConsumerConfiguration.consumerId:}")
- public String consumerId;
-
- @Value("${dmaap.dmaapConsumerConfiguration.consumerGroup:}")
- public String consumerGroup;
-
- @Value("${dmaap.dmaapConsumerConfiguration.timeoutMs:}")
- public Integer consumerTimeoutMs;
-
- @Value("${dmaap.dmaapConsumerConfiguration.message-limit:}")
- public Integer consumerMessageLimit;
-
- @Value("${dmaap.dmaapProducerConfiguration.dmaapHostName:}")
- public String producerDmaapHostName;
-
- @Value("${dmaap.dmaapProducerConfiguration.dmaapPortNumber:}")
- public Integer producerDmaapPortNumber;
-
- @Value("${dmaap.dmaapProducerConfiguration.dmaapTopicName:}")
- public String producerDmaapTopicName;
+@EnableConfigurationProperties
+@ConfigurationProperties("app")
+public class AppConfig {
- @Value("${dmaap.dmaapProducerConfiguration.dmaapProtocol:}")
- public String producerDmaapProtocol;
+ private static final String CONFIG = "configs";
+ private static final String DMAAP = "dmaap";
+ private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
+ private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
+ private static final String FTP = "ftp";
+ private static final String FTPES_CONFIGURATION = "ftpesConfiguration";
+ private static final String SECURITY = "security";
+ private static final Logger logger = LoggerFactory.getLogger(AppConfig.class);
- @Value("${dmaap.dmaapProducerConfiguration.dmaapUserName:}")
- public String producerDmaapUserName;
+ DmaapConsumerConfiguration dmaapConsumerConfiguration;
- @Value("${dmaap.dmaapProducerConfiguration.dmaapUserPassword:}")
- public String producerDmaapUserPassword;
+ DmaapPublisherConfiguration dmaapPublisherConfiguration;
- @Value("${dmaap.dmaapProducerConfiguration.dmaapContentType:}")
- public String producerDmaapContentType;
+ FtpesConfig ftpesConfig;
- @Value("${ftp.ftpesConfiguration.keyCert:}")
- public String keyCert;
+ @NotEmpty
+ private String filepath;
- @Value("${ftp.ftpesConfiguration.keyPassword:}")
- public String keyPassword;
-
- @Value("${ftp.ftpesConfiguration.trustedCA:}")
- public String trustedCA;
+ public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
+ return dmaapConsumerConfiguration;
+ }
- @Value("${ftp.ftpesConfiguration.trustedCAPassword:}")
- public String trustedCAPassword;
+ public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
+ return dmaapPublisherConfiguration;
+ }
- @Value("${security.trustStorePath:}")
- public String trustStorePath;
+ public FtpesConfig getFtpesConfiguration() {
+ return ftpesConfig;
+ }
- @Value("${security.trustStorePasswordPath:}")
- public String trustStorePasswordPath;
+ public void initFileStreamReader() {
+
+ GsonBuilder gsonBuilder = new GsonBuilder();
+ ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
+ JsonParser parser = new JsonParser();
+ JsonObject jsonObject;
+ try (InputStream inputStream = getInputStream(filepath)) {
+ JsonElement rootElement = getJsonElement(parser, inputStream);
+ if (rootElement.isJsonObject()) {
+ jsonObject = rootElement.getAsJsonObject();
+ ftpesConfig = deserializeType(gsonBuilder,
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(FTP).getAsJsonObject(FTPES_CONFIGURATION),
+ FtpesConfig.class);
+ dmaapConsumerConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
+ DmaapConsumerConfiguration.class);
+
+ dmaapPublisherConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
+ jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
+ rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
+ DmaapPublisherConfiguration.class);
+ }
+ } catch (IOException e) {
+ logger.error("Problem with file loading, file: {}", filepath, e);
+ } catch (JsonSyntaxException e) {
+ logger.error("Problem with Json deserialization", e);
+ }
+ }
- @Value("${security.keyStorePath:}")
- public String keyStorePath;
+ JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
+ return parser.parse(new InputStreamReader(inputStream));
+ }
- @Value("${security.keyStorePasswordPath:}")
- public String keyStorePasswordPath;
+ private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
+ @NotNull Class<T> type) {
+ return gsonBuilder.create().fromJson(jsonObject, type);
+ }
- @Value("${security.enableDmaapCertAuth:}")
- public Boolean enableDmaapCertAuth;
+ InputStream getInputStream(@NotNull String filepath) throws IOException {
+ return new BufferedInputStream(new FileInputStream(filepath));
+ }
- @Override
- public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
- return new ImmutableDmaapConsumerConfiguration.Builder()
- .dmaapUserPassword(
- Optional.ofNullable(consumerDmaapUserPassword).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.dmaapUserPassword()))
- .dmaapUserName(
- Optional.ofNullable(consumerDmaapUserName).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.dmaapUserName()))
- .dmaapHostName(
- Optional.ofNullable(consumerDmaapHostName).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.dmaapHostName()))
- .dmaapPortNumber(
- Optional.ofNullable(consumerDmaapPortNumber).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapConsumerConfiguration.dmaapPortNumber()))
- .dmaapProtocol(
- Optional.ofNullable(consumerDmaapProtocol).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.dmaapProtocol()))
- .dmaapContentType(
- Optional.ofNullable(consumerDmaapContentType).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.dmaapContentType()))
- .dmaapTopicName(
- Optional.ofNullable(consumerDmaapTopicName).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.dmaapTopicName()))
- .messageLimit(
- Optional.ofNullable(consumerMessageLimit).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapConsumerConfiguration.messageLimit()))
- .timeoutMs(Optional.ofNullable(consumerTimeoutMs).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapConsumerConfiguration.timeoutMs()))
- .consumerGroup(Optional.ofNullable(consumerGroup).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.consumerGroup()))
- .consumerId(Optional.ofNullable(consumerId).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.consumerId()))
- .trustStorePath(
- Optional.ofNullable(trustStorePath).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.trustStorePath()))
- .trustStorePasswordPath(
- Optional.ofNullable(trustStorePasswordPath).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.trustStorePasswordPath()))
- .keyStorePath(
- Optional.ofNullable(keyStorePath).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.keyStorePath()))
- .keyStorePasswordPath(
- Optional.ofNullable(keyStorePasswordPath).filter(isEmpty.negate())
- .orElse(dmaapConsumerConfiguration.keyStorePasswordPath()))
- .enableDmaapCertAuth(
- Optional.ofNullable(enableDmaapCertAuth).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapConsumerConfiguration.enableDmaapCertAuth()))
- .build();
+ String getFilepath() {
+ return this.filepath;
}
- @Override
- public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
- return new ImmutableDmaapPublisherConfiguration.Builder()
- .dmaapContentType(
- Optional.ofNullable(producerDmaapContentType).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.dmaapContentType()))
- .dmaapHostName(
- Optional.ofNullable(producerDmaapHostName).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.dmaapHostName()))
- .dmaapPortNumber(
- Optional.ofNullable(producerDmaapPortNumber).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapPublisherConfiguration.dmaapPortNumber()))
- .dmaapProtocol(
- Optional.ofNullable(producerDmaapProtocol).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.dmaapProtocol()))
- .dmaapTopicName(
- Optional.ofNullable(producerDmaapTopicName).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.dmaapTopicName()))
- .dmaapUserName(
- Optional.ofNullable(producerDmaapUserName).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.dmaapUserName()))
- .dmaapUserPassword(
- Optional.ofNullable(producerDmaapUserPassword).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.dmaapUserPassword()))
- .trustStorePath(
- Optional.ofNullable(trustStorePath).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.trustStorePath()))
- .trustStorePasswordPath(
- Optional.ofNullable(trustStorePasswordPath).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.trustStorePasswordPath()))
- .keyStorePath(
- Optional.ofNullable(keyStorePath).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.keyStorePath()))
- .keyStorePasswordPath(
- Optional.ofNullable(keyStorePasswordPath).filter(isEmpty.negate())
- .orElse(dmaapPublisherConfiguration.keyStorePasswordPath()))
- .enableDmaapCertAuth(
- Optional.ofNullable(enableDmaapCertAuth).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapPublisherConfiguration.enableDmaapCertAuth()))
- .build();
+ public void setFilepath(String filepath) {
+ this.filepath = filepath;
}
- @Override
- public FtpesConfig getFtpesConfiguration() {
- return new ImmutableFtpesConfig.Builder()
- .keyCert(
- Optional.ofNullable(keyCert).filter(isEmpty.negate())
- .orElse(ftpesConfig.keyCert()))
- .keyPassword(
- Optional.ofNullable(keyPassword).filter(isEmpty.negate())
- .orElse(ftpesConfig.keyPassword()))
- .trustedCA(
- Optional.ofNullable(trustedCA).filter(isEmpty.negate())
- .orElse(ftpesConfig.trustedCA()))
- .trustedCAPassword(
- Optional.ofNullable(trustedCAPassword).filter(isEmpty.negate())
- .orElse(ftpesConfig.trustedCAPassword()))
- .build();
+ private JsonObject concatenateJsonObjects(JsonObject target, JsonObject source) {
+ source.entrySet()
+ .forEach(entry -> target.add(entry.getKey(), entry.getValue()));
+ return target;
}
+
}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java
deleted file mode 100644
index 7fe2561c..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/Config.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END========================================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.configuration;
-
-
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
-public interface Config {
-
- DmaapConsumerConfiguration getDmaapConsumerConfiguration();
-
- DmaapPublisherConfiguration getDmaapPublisherConfiguration();
-
- FtpesConfig getFtpesConfiguration();
-
- void initFileStreamReader();
-
-}
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java
deleted file mode 100644
index 59bb259d..00000000
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfig.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * ============LICENSE_START======================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property, 2018-2019 Nordix Foundation. All rights reserved.
- * ===============================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- * ============LICENSE_END========================================================================
- */
-
-package org.onap.dcaegen2.collectors.datafile.configuration;
-
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-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;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ServiceLoader;
-
-import javax.validation.constraints.NotEmpty;
-import javax.validation.constraints.NotNull;
-
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
- * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
- */
-@Configuration
-@EnableConfigurationProperties
-@ConfigurationProperties("app")
-public abstract class DatafileAppConfig implements Config {
-
- private static final String CONFIG = "configs";
- private static final String DMAAP = "dmaap";
- private static final String DMAAP_PRODUCER = "dmaapProducerConfiguration";
- private static final String DMAAP_CONSUMER = "dmaapConsumerConfiguration";
- private static final String FTP = "ftp";
- private static final String FTPES_CONFIGURATION = "ftpesConfiguration";
- private static final String SECURITY = "security";
- private static final Logger logger = LoggerFactory.getLogger(DatafileAppConfig.class);
-
- DmaapConsumerConfiguration dmaapConsumerConfiguration;
-
- DmaapPublisherConfiguration dmaapPublisherConfiguration;
-
- FtpesConfig ftpesConfig;
-
- @NotEmpty
- private String filepath;
-
-
- @Override
- public DmaapConsumerConfiguration getDmaapConsumerConfiguration() {
- return dmaapConsumerConfiguration;
- }
-
- @Override
- public DmaapPublisherConfiguration getDmaapPublisherConfiguration() {
- return dmaapPublisherConfiguration;
- }
-
- @Override
- public FtpesConfig getFtpesConfiguration() {
- return ftpesConfig;
- }
-
- @Override
- public void initFileStreamReader() {
-
- GsonBuilder gsonBuilder = new GsonBuilder();
- ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory);
- JsonParser parser = new JsonParser();
- JsonObject jsonObject;
- try (InputStream inputStream = getInputStream(filepath)) {
- JsonElement rootElement = getJsonElement(parser, inputStream);
- if (rootElement.isJsonObject()) {
- jsonObject = rootElement.getAsJsonObject();
- ftpesConfig = deserializeType(gsonBuilder,
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(FTP).getAsJsonObject(FTPES_CONFIGURATION),
- FtpesConfig.class);
- dmaapConsumerConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- DmaapConsumerConfiguration.class);
-
- dmaapPublisherConfiguration = deserializeType(gsonBuilder, concatenateJsonObjects(
- jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER),
- rootElement.getAsJsonObject().getAsJsonObject(CONFIG).getAsJsonObject(SECURITY)),
- DmaapPublisherConfiguration.class);
- }
- } catch (IOException e) {
- logger.error("Problem with file loading, file: {}", filepath, e);
- } catch (JsonSyntaxException e) {
- logger.error("Problem with Json deserialization", e);
- }
- }
-
- JsonElement getJsonElement(JsonParser parser, InputStream inputStream) {
- return parser.parse(new InputStreamReader(inputStream));
- }
-
- private <T> T deserializeType(@NotNull GsonBuilder gsonBuilder, @NotNull JsonObject jsonObject,
- @NotNull Class<T> type) {
- return gsonBuilder.create().fromJson(jsonObject, type);
- }
-
- InputStream getInputStream(@NotNull String filepath) throws IOException {
- return new BufferedInputStream(new FileInputStream(filepath));
- }
-
- String getFilepath() {
- return this.filepath;
- }
-
- public void setFilepath(String filepath) {
- this.filepath = filepath;
- }
-
- private JsonObject concatenateJsonObjects(JsonObject target, JsonObject source) {
- source.entrySet()
- .forEach(entry -> target.add(entry.getKey(), entry.getValue()));
- return target;
- }
-}
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 478ae309..12f303ef 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
@@ -37,7 +37,7 @@ import reactor.core.publisher.Mono;
*/
@Configuration
@EnableScheduling
-public class SchedulerConfig extends DatafileAppConfig {
+public class SchedulerConfig {
private static final int SCHEDULING_DELAY_FOR_DATAFILE_COLLECTOR_TASKS = 15;
private static final int SCHEDULING_REQUEST_FOR_CONFIGURATION_DELAY = 5;
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTask.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTask.java
index c41dce5b..f6daf733 100644
--- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTask.java
+++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/tasks/DMaaPMessageConsumerTask.java
@@ -22,7 +22,6 @@ package org.onap.dcaegen2.collectors.datafile.tasks;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.configuration.Config;
import org.onap.dcaegen2.collectors.datafile.model.FileReadyMessage;
import org.onap.dcaegen2.collectors.datafile.service.DmaapReactiveWebClient;
import org.onap.dcaegen2.collectors.datafile.service.JsonMessageParser;
@@ -31,9 +30,8 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consume
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.reactive.function.client.WebClient;
-
-import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import reactor.core.publisher.Flux;
/**
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
@@ -41,7 +39,7 @@ import reactor.core.publisher.Mono;
public class DMaaPMessageConsumerTask {
private static final Logger logger = LoggerFactory.getLogger(DMaaPMessageConsumerTask.class);
- private Config datafileAppConfig;
+ private AppConfig datafileAppConfig;
private JsonMessageParser jsonMessageParser;
private DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient;
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 b65ddd63..338c8323 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
@@ -19,7 +19,6 @@ package org.onap.dcaegen2.collectors.datafile.tasks;
import java.time.Duration;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.configuration.Config;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.onap.dcaegen2.collectors.datafile.service.HttpUtils;
import org.onap.dcaegen2.collectors.datafile.service.producer.DmaapProducerReactiveHttpClient;
@@ -37,7 +36,7 @@ import reactor.core.publisher.Flux;
public class DataRouterPublisher {
private static final Logger logger = LoggerFactory.getLogger(DataRouterPublisher.class);
- private final Config datafileAppConfig;
+ private final AppConfig datafileAppConfig;
public DataRouterPublisher(AppConfig datafileAppConfig) {
this.datafileAppConfig = datafileAppConfig;
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 db18ac2a..0b647bf5 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
@@ -20,7 +20,6 @@ import java.nio.file.Path;
import java.time.Duration;
import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
-import org.onap.dcaegen2.collectors.datafile.configuration.Config;
import org.onap.dcaegen2.collectors.datafile.configuration.FtpesConfig;
import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
import org.onap.dcaegen2.collectors.datafile.ftp.FileCollectClient;
@@ -41,7 +40,7 @@ import reactor.core.publisher.Mono;
public class FileCollector {
private static final Logger logger = LoggerFactory.getLogger(FileCollector.class);
- private Config datafileAppConfig;
+ private AppConfig datafileAppConfig;
private final FtpsClient ftpsClient;
private final SftpClient sftpClient;
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java
index 2cd854af..443ddae7 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/configuration/DatafileAppConfigTest.java
@@ -46,33 +46,32 @@ import org.onap.dcaegen2.collectors.datafile.integration.junit5.mockito.MockitoE
* @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
*/
@ExtendWith({MockitoExtension.class})
-class DatafileAppConfigTest {
-
+class AppConfigTest {
+
private static final String DATAFILE_ENDPOINTS = "datafile_endpoints.json";
private static final boolean CORRECT_JSON = true;
private static final boolean INCORRECT_JSON = false;
- private static DatafileAppConfig datafileAppConfig;
- private static AppConfig appConfig;
+ private static AppConfig appConfigUnderTest;
+
private static String filePath = Objects
- .requireNonNull(DatafileAppConfigTest.class.getClassLoader().getResource(DATAFILE_ENDPOINTS)).getFile();
+ .requireNonNull(AppConfigTest.class.getClassLoader().getResource(DATAFILE_ENDPOINTS)).getFile();
@BeforeEach
public void setUp() {
- datafileAppConfig = spy(DatafileAppConfig.class);
- appConfig = spy(new AppConfig());
+ appConfigUnderTest = spy(AppConfig.class);
}
@Test
public void whenApplicationWasStarted_FilePathIsSet() {
// When
- datafileAppConfig.setFilepath(filePath);
+ appConfigUnderTest.setFilepath(filePath);
// Then
- verify(datafileAppConfig, times(1)).setFilepath(anyString());
- verify(datafileAppConfig, times(0)).initFileStreamReader();
- Assertions.assertEquals(filePath, datafileAppConfig.getFilepath());
+ verify(appConfigUnderTest, times(1)).setFilepath(anyString());
+ verify(appConfigUnderTest, times(0)).initFileStreamReader();
+ Assertions.assertEquals(filePath, appConfigUnderTest.getFilepath());
}
@Test
@@ -82,23 +81,23 @@ class DatafileAppConfigTest {
new ByteArrayInputStream((getJsonConfig(CORRECT_JSON).getBytes(StandardCharsets.UTF_8)));
// When
- datafileAppConfig.setFilepath(filePath);
- doReturn(inputStream).when(datafileAppConfig).getInputStream(any());
- datafileAppConfig.initFileStreamReader();
- appConfig.dmaapConsumerConfiguration = datafileAppConfig.getDmaapConsumerConfiguration();
- appConfig.dmaapPublisherConfiguration = datafileAppConfig.getDmaapPublisherConfiguration();
- appConfig.ftpesConfig = datafileAppConfig.getFtpesConfiguration();
+ appConfigUnderTest.setFilepath(filePath);
+ doReturn(inputStream).when(appConfigUnderTest).getInputStream(any());
+ appConfigUnderTest.initFileStreamReader();
+ appConfigUnderTest.dmaapConsumerConfiguration = appConfigUnderTest.getDmaapConsumerConfiguration();
+ appConfigUnderTest.dmaapPublisherConfiguration = appConfigUnderTest.getDmaapPublisherConfiguration();
+ appConfigUnderTest.ftpesConfig = appConfigUnderTest.getFtpesConfiguration();
// Then
- verify(datafileAppConfig, times(1)).setFilepath(anyString());
- verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(datafileAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNotNull(datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions.assertEquals(appConfig.getDmaapPublisherConfiguration(),
- datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions.assertEquals(appConfig.getDmaapConsumerConfiguration(),
- datafileAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertEquals(appConfig.getFtpesConfiguration(), datafileAppConfig.getFtpesConfiguration());
+ verify(appConfigUnderTest, times(1)).setFilepath(anyString());
+ verify(appConfigUnderTest, times(1)).initFileStreamReader();
+ Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration());
+ Assertions.assertNotNull(appConfigUnderTest.getDmaapPublisherConfiguration());
+ Assertions.assertEquals(appConfigUnderTest.getDmaapPublisherConfiguration(),
+ appConfigUnderTest.getDmaapPublisherConfiguration());
+ Assertions.assertEquals(appConfigUnderTest.getDmaapConsumerConfiguration(),
+ appConfigUnderTest.getDmaapConsumerConfiguration());
+ Assertions.assertEquals(appConfigUnderTest.getFtpesConfiguration(), appConfigUnderTest.getFtpesConfiguration());
}
@@ -106,17 +105,17 @@ class DatafileAppConfigTest {
public void whenFileIsNotExist_ThrowIoException() {
// Given
filePath = "/temp.json";
- datafileAppConfig.setFilepath(filePath);
+ appConfigUnderTest.setFilepath(filePath);
// When
- datafileAppConfig.initFileStreamReader();
+ appConfigUnderTest.initFileStreamReader();
// Then
- verify(datafileAppConfig, times(1)).setFilepath(anyString());
- verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(datafileAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions.assertNull(datafileAppConfig.getFtpesConfiguration());
+ verify(appConfigUnderTest, times(1)).setFilepath(anyString());
+ verify(appConfigUnderTest, times(1)).initFileStreamReader();
+ Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
+ Assertions.assertNull(appConfigUnderTest.getDmaapPublisherConfiguration());
+ Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
@@ -127,16 +126,16 @@ class DatafileAppConfigTest {
new ByteArrayInputStream((getJsonConfig(INCORRECT_JSON).getBytes(StandardCharsets.UTF_8)));
// When
- datafileAppConfig.setFilepath(filePath);
- doReturn(inputStream).when(datafileAppConfig).getInputStream(any());
- datafileAppConfig.initFileStreamReader();
+ appConfigUnderTest.setFilepath(filePath);
+ doReturn(inputStream).when(appConfigUnderTest).getInputStream(any());
+ appConfigUnderTest.initFileStreamReader();
// Then
- verify(datafileAppConfig, times(1)).setFilepath(anyString());
- verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(datafileAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions.assertNotNull(datafileAppConfig.getFtpesConfiguration());
+ verify(appConfigUnderTest, times(1)).setFilepath(anyString());
+ verify(appConfigUnderTest, times(1)).initFileStreamReader();
+ Assertions.assertNotNull(appConfigUnderTest.getDmaapConsumerConfiguration());
+ Assertions.assertNull(appConfigUnderTest.getDmaapPublisherConfiguration());
+ Assertions.assertNotNull(appConfigUnderTest.getFtpesConfiguration());
}
@@ -147,22 +146,22 @@ class DatafileAppConfigTest {
InputStream inputStream =
new ByteArrayInputStream((getJsonConfig(CORRECT_JSON).getBytes(StandardCharsets.UTF_8)));
// When
- datafileAppConfig.setFilepath(filePath);
- doReturn(inputStream).when(datafileAppConfig).getInputStream(any());
+ appConfigUnderTest.setFilepath(filePath);
+ doReturn(inputStream).when(appConfigUnderTest).getInputStream(any());
JsonElement jsonElement = mock(JsonElement.class);
when(jsonElement.isJsonObject()).thenReturn(false);
- doReturn(jsonElement).when(datafileAppConfig).getJsonElement(any(JsonParser.class), any(InputStream.class));
- datafileAppConfig.initFileStreamReader();
- appConfig.dmaapConsumerConfiguration = datafileAppConfig.getDmaapConsumerConfiguration();
- appConfig.dmaapPublisherConfiguration = datafileAppConfig.getDmaapPublisherConfiguration();
- appConfig.ftpesConfig = datafileAppConfig.getFtpesConfiguration();
+ doReturn(jsonElement).when(appConfigUnderTest).getJsonElement(any(JsonParser.class), any(InputStream.class));
+ appConfigUnderTest.initFileStreamReader();
+ appConfigUnderTest.dmaapConsumerConfiguration = appConfigUnderTest.getDmaapConsumerConfiguration();
+ appConfigUnderTest.dmaapPublisherConfiguration = appConfigUnderTest.getDmaapPublisherConfiguration();
+ appConfigUnderTest.ftpesConfig = appConfigUnderTest.getFtpesConfiguration();
// Then
- verify(datafileAppConfig, times(1)).setFilepath(anyString());
- verify(datafileAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(datafileAppConfig.getDmaapConsumerConfiguration());
- Assertions.assertNull(datafileAppConfig.getDmaapPublisherConfiguration());
- Assertions.assertNull(datafileAppConfig.getFtpesConfiguration());
+ verify(appConfigUnderTest, times(1)).setFilepath(anyString());
+ verify(appConfigUnderTest, times(1)).initFileStreamReader();
+ Assertions.assertNull(appConfigUnderTest.getDmaapConsumerConfiguration());
+ Assertions.assertNull(appConfigUnderTest.getDmaapPublisherConfiguration());
+ Assertions.assertNull(appConfigUnderTest.getFtpesConfiguration());
}
private String getJsonConfig(boolean correct) {
diff --git a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java
index 05a4f515..0d5ea003 100644
--- a/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java
+++ b/datafile-app-server/src/test/java/org/onap/dcaegen2/collectors/datafile/integration/ServiceMockProvider.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2018-2019 NOKIA Intellectual Property, 2018 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@ package org.onap.dcaegen2.collectors.datafile.integration;
import static org.mockito.Mockito.mock;
-import org.onap.dcaegen2.collectors.datafile.configuration.DatafileAppConfig;
+import org.onap.dcaegen2.collectors.datafile.configuration.AppConfig;
import org.onap.dcaegen2.collectors.datafile.model.ConsumerDmaapModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,8 +34,8 @@ import org.springframework.context.annotation.Configuration;
class ServiceMockProvider {
@Bean
- public DatafileAppConfig getDatafileAppConfig() {
- return mock(DatafileAppConfig.class);
+ public AppConfig getDatafileAppConfig() {
+ return mock(AppConfig.class);
}
@Bean