diff options
Diffstat (limited to 'prh-app-server')
7 files changed, 220 insertions, 28 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java index 85ca5226..76633d26 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AppConfig.java @@ -19,21 +19,157 @@ */ package org.onap.dcaegen2.services.prh.configuration; +import java.util.Optional; import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration; +import org.onap.dcaegen2.services.config.ImmutableDmaapConsumerConfiguration; +import org.onap.dcaegen2.services.config.ImmutableDmaapPublisherConfiguration; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18 */ -public interface AppConfig { - DmaapConsumerConfiguration getDmaapConsumerConfiguration(); +@Component +@Configuration +public class AppConfig extends PrhAppConfig { - AAIHttpClientConfiguration getAAIHttpClientConfiguration(); + @Value("${dmaap.dmaapConsumerConfiguration.dmmapHostName:}") + public String consumerDmmapHostName; - DmaapPublisherConfiguration getDmaapPublisherConfiguration(); + @Value("${dmaap.dmaapConsumerConfiguration.dmmapPortNumber:}") + public Integer consumerDmmapPortNumber; - void initFileStreamReader(); + @Value("${dmaap.dmaapConsumerConfiguration.dmmapTopicName:}") + public String consumerDmmapTopicName; + + @Value("${dmaap.dmaapConsumerConfiguration.dmmapProtocol:}") + public String consumerDmmapProtocol; + + @Value("${dmaap.dmaapConsumerConfiguration.dmmapUserName:}") + public String consumerDmmapUserName; + + @Value("${dmaap.dmaapConsumerConfiguration.dmmapUserPassword:}") + public String consumerDmmapUserPassword; + + @Value("${dmaap.dmaapConsumerConfiguration.dmmapContentType:}") + public String consumerDmmapContentType; + + @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.dmmapHostName:}") + public String producerDmmapHostName; + + @Value("${dmaap.dmaapProducerConfiguration.dmmapPortNumber:}") + public Integer producerDmmapPortNumber; + + @Value("${dmaap.dmaapProducerConfiguration.dmmapTopicName:}") + public String producerDmmapTopicName; + + @Value("${dmaap.dmaapProducerConfiguration.dmmapProtocol:}") + public String producerDmmapProtocol; + + @Value("${dmaap.dmaapProducerConfiguration.dmmapUserName:}") + public String producerDmmapUserName; + + @Value("${dmaap.dmaapProducerConfiguration.dmmapUserPassword:}") + public String producerDmmapUserPassword; + + @Value("${dmaap.dmaapProducerConfiguration.dmmapContentType:}") + public String producerDmmapContentType; + + @Value("${aai.aaiHttpClientConfiguration.aaiHost:}") + public String aaiHost; + + @Value("${aai.aaiHttpClientConfiguration.aaiHostPortNumber:}") + public Integer aaiHostPortNumber; + + @Value("${aai.aaiHttpClientConfiguration.aaiProtocol:}") + public String aaiProtocol; + + @Value("${aai.aaiHttpClientConfiguration.aaiUserName:}") + public String aaiUserName; + + @Value("${aai.aaiHttpClientConfiguration.aaiUserPassword:}") + public String aaiUserPassword; + + @Value("${aai.aaiHttpClientConfiguration.aaiIgnoreSSLCertificateErrors:}") + public Boolean aaiIgnoreSSLCertificateErrors; + + @Override + public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { + return new ImmutableDmaapConsumerConfiguration.Builder() + .dmaapUserPassword( + Optional.ofNullable(consumerDmmapUserPassword).orElse(dmaapConsumerConfiguration.dmaapUserPassword())) + .dmaapUserName( + Optional.ofNullable(consumerDmmapUserName).orElse(dmaapConsumerConfiguration.dmaapUserName())) + .dmaapHostName( + Optional.ofNullable(consumerDmmapHostName).orElse(dmaapConsumerConfiguration.dmaapHostName())) + .dmaapPortNumber( + Optional.ofNullable(consumerDmmapPortNumber).orElse(dmaapConsumerConfiguration.dmaapPortNumber())) + .dmaapProtocol( + Optional.ofNullable(consumerDmmapProtocol).orElse(dmaapConsumerConfiguration.dmaapProtocol())) + .dmaapContentType( + Optional.ofNullable(consumerDmmapContentType).orElse(dmaapConsumerConfiguration.dmaapContentType())) + .dmaapTopicName( + Optional.ofNullable(consumerDmmapTopicName).orElse(dmaapConsumerConfiguration.dmaapTopicName())) + .messageLimit( + Optional.ofNullable(consumerMessageLimit).orElse(dmaapConsumerConfiguration.messageLimit())) + .timeoutMS(Optional.ofNullable(consumerTimeoutMS).orElse(dmaapConsumerConfiguration.timeoutMS())) + .consumerGroup(Optional.ofNullable(consumerGroup).orElse(dmaapConsumerConfiguration.consumerGroup())) + .consumerId(Optional.ofNullable(consumerId).orElse(dmaapConsumerConfiguration.consumerId())) + .build(); + } + + @Override + public AAIHttpClientConfiguration getAAIHttpClientConfiguration() { + return new ImmutableAAIHttpClientConfiguration.Builder() + .aaiHost(Optional.ofNullable(aaiHost).orElse(aaiHttpClientConfiguration.aaiHost())) + .aaiHostPortNumber( + Optional.ofNullable(aaiHostPortNumber).orElse(aaiHttpClientConfiguration.aaiHostPortNumber())) + .aaiIgnoreSSLCertificateErrors( + Optional.ofNullable(aaiIgnoreSSLCertificateErrors) + .orElse(aaiHttpClientConfiguration.aaiIgnoreSSLCertificateErrors())) + .aaiProtocol(Optional.ofNullable(aaiProtocol).orElse(aaiHttpClientConfiguration.aaiProtocol())) + .aaiUserName( + Optional.ofNullable(aaiUserName).orElse(aaiHttpClientConfiguration.aaiUserName())) + .aaiUserPassword(Optional.ofNullable( + aaiUserPassword).orElse(aaiHttpClientConfiguration.aaiUserPassword())) + .build(); + } + + @Override + public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { + return new ImmutableDmaapPublisherConfiguration.Builder() + .dmaapContentType( + Optional.ofNullable(producerDmmapContentType).orElse(dmaapPublisherConfiguration.dmaapContentType())) + .dmaapHostName( + Optional.ofNullable(producerDmmapHostName).orElse(dmaapPublisherConfiguration.dmaapHostName())) + .dmaapPortNumber( + Optional.ofNullable(producerDmmapPortNumber).orElse(dmaapPublisherConfiguration.dmaapPortNumber())) + .dmaapProtocol( + Optional.ofNullable(producerDmmapProtocol).orElse(dmaapPublisherConfiguration.dmaapProtocol())) + .dmaapTopicName( + Optional.ofNullable(producerDmmapTopicName).orElse(dmaapPublisherConfiguration.dmaapTopicName())) + .dmaapUserName( + Optional.ofNullable(producerDmmapUserName).orElse(dmaapPublisherConfiguration.dmaapUserName())) + .dmaapUserPassword( + Optional.ofNullable(producerDmmapUserPassword).orElse(dmaapPublisherConfiguration.dmaapUserPassword())) + .build(); + } } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java new file mode 100644 index 00000000..8dd2bf3b --- /dev/null +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/Config.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. 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.services.prh.configuration; + +import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; +import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; +import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; + +/** + * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/25/18 + */ +public interface Config { + + DmaapConsumerConfiguration getDmaapConsumerConfiguration(); + + AAIHttpClientConfiguration getAAIHttpClientConfiguration(); + + DmaapPublisherConfiguration getDmaapPublisherConfiguration(); + + void initFileStreamReader(); +} diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java index 2fa35608..8720cf47 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfig.java @@ -51,7 +51,7 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableConfigurationProperties @ConfigurationProperties("app") -public class PrhAppConfig implements AppConfig { +public abstract class PrhAppConfig implements Config { private static final String CONFIG = "configs"; private static final String AAI = "aai"; @@ -63,15 +63,31 @@ public class PrhAppConfig implements AppConfig { private static final Logger logger = LoggerFactory.getLogger(PrhAppConfig.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - private AAIHttpClientConfiguration aaiHttpClientConfiguration; + AAIHttpClientConfiguration aaiHttpClientConfiguration; - private DmaapConsumerConfiguration dmaapConsumerConfiguration; + DmaapConsumerConfiguration dmaapConsumerConfiguration; - private DmaapPublisherConfiguration dmaapPublisherConfiguration; + DmaapPublisherConfiguration dmaapPublisherConfiguration; @NotEmpty private String filepath; + + @Override + public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { + return dmaapConsumerConfiguration; + } + + @Override + public AAIHttpClientConfiguration getAAIHttpClientConfiguration() { + return aaiHttpClientConfiguration; + } + + @Override + public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { + return dmaapPublisherConfiguration; + } + @Override public void initFileStreamReader() { @@ -95,7 +111,6 @@ public class PrhAppConfig implements AppConfig { jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_PRODUCER), DmaapPublisherConfiguration.class); } - } catch (FileNotFoundException e) { logger .error( @@ -134,18 +149,4 @@ public class PrhAppConfig implements AppConfig { this.filepath = filepath; } - @Override - public DmaapConsumerConfiguration getDmaapConsumerConfiguration() { - return dmaapConsumerConfiguration; - } - - @Override - public AAIHttpClientConfiguration getAAIHttpClientConfiguration() { - return aaiHttpClientConfiguration; - } - - @Override - public DmaapPublisherConfiguration getDmaapPublisherConfiguration() { - return dmaapPublisherConfiguration; - } }
\ No newline at end of file diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java index 9a256986..aa452047 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AAIPublisherTaskImpl.java @@ -23,6 +23,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.prh.configuration.Config; import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +40,7 @@ public class AAIPublisherTaskImpl extends AAIPublisherTask<AAIHttpClientConfigur private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - private final AppConfig prhAppConfig; + private final Config prhAppConfig; @Autowired public AAIPublisherTaskImpl(AppConfig prhAppConfig) { diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java index f7cc7e1d..0db49f7c 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java @@ -23,6 +23,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import org.onap.dcaegen2.services.config.DmaapConsumerConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.prh.configuration.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +40,7 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask<DmaapConsumerConfig private static final Logger logger = LoggerFactory.getLogger(DmaapConsumerTaskImpl.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - private final AppConfig prhAppConfig; + private final Config prhAppConfig; @Autowired public DmaapConsumerTaskImpl(AppConfig prhAppConfig) { diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java index 74d08539..072f9c7d 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java @@ -23,6 +23,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration; import org.onap.dcaegen2.services.prh.configuration.AppConfig; +import org.onap.dcaegen2.services.prh.configuration.Config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -38,7 +39,7 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask<DmaapPublisherCon private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class); private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - private final AppConfig prhAppConfig; + private final Config prhAppConfig; @Autowired public DmaapPublisherTaskImpl(AppConfig prhAppConfig) { diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java index 93555665..764bafec 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/configuration/PrhAppConfigTest.java @@ -47,13 +47,15 @@ class PrhAppConfigTest { private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiHttpClientConfiguration\":{\"aaiHost\":\"\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\"}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}"; private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiHttpClientConfiguration\":{\"aaiHost\":\"\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\"}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}"; private static PrhAppConfig prhAppConfig; + private static AppConfig appConfig; private static String filePath = Objects .requireNonNull(PrhAppConfigTest.class.getClassLoader().getResource(PRH_ENDPOINTS)).getFile(); @BeforeEach public void setUp() { - prhAppConfig = spy(new PrhAppConfig()); + prhAppConfig = spy(PrhAppConfig.class); + appConfig = spy(new AppConfig()); } @Test @@ -84,6 +86,9 @@ class PrhAppConfigTest { prhAppConfig.setFilepath(filePath); doReturn(inputStream).when(prhAppConfig).getInputStream(any()); prhAppConfig.initFileStreamReader(); + appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration(); + appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration(); + appConfig.aaiHttpClientConfiguration = prhAppConfig.getAAIHttpClientConfiguration(); // // Then // @@ -92,6 +97,13 @@ class PrhAppConfigTest { Assertions.assertNotNull(prhAppConfig.getAAIHttpClientConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNotNull(prhAppConfig.getDmaapPublisherConfiguration()); + Assertions + .assertEquals(appConfig.getDmaapPublisherConfiguration(), prhAppConfig.getDmaapPublisherConfiguration()); + Assertions + .assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration()); + Assertions + .assertEquals(appConfig.getAAIHttpClientConfiguration(), prhAppConfig.getAAIHttpClientConfiguration()); + } @Test @@ -129,6 +141,7 @@ class PrhAppConfigTest { prhAppConfig.setFilepath(filePath); doReturn(inputStream).when(prhAppConfig).getInputStream(any()); prhAppConfig.initFileStreamReader(); + // // Then // @@ -138,5 +151,6 @@ class PrhAppConfigTest { Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration()); Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration()); + } }
\ No newline at end of file |