From 7752c2d818e6d19e4d805c2fd6760b4a13d601bc Mon Sep 17 00:00:00 2001 From: PawelSzalapski Date: Thu, 2 Aug 2018 10:31:56 +0200 Subject: Implement second part of dynamic DMaaP config VESCollector app can now fetch CBS configuration and rebuilt the part regarding sending events dynamically, without restarting application. Application will still be restarted by a .sh script, if there were changes regarding collector.properties file. The decision of whether dynamic configuration should be triggered is now based on existence of env vars CONSUL_HOST, CONFIG_BINDING_SERVICE, HOSTNAME, not as previously on CBSPOLLTIME. Frequency at which the config check should happen is now exposed via property from collector.properties Change-Id: I98ff160fa51d08d84a23c716d90ceaacbe17ada6 Signed-off-by: PawelSzalapski Issue-ID: DCAEGEN2-519 --- .../controller/ConfigLoaderIntegrationE2ETest.java | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java (limited to 'src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java') diff --git a/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java b/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java new file mode 100644 index 00000000..09dca676 --- /dev/null +++ b/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * org.onap.dcaegen2.collectors.ves + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018 Nokia. 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.dcae.controller; + +import static io.vavr.API.Map; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; +import static org.onap.dcae.TestingUtilities.createTemporaryFile; +import static org.onap.dcae.TestingUtilities.readFile; +import static org.onap.dcae.TestingUtilities.readJSONFromFile; +import static org.onap.dcae.commonFunction.event.publishing.VavrUtils.f; + +import java.nio.file.Path; +import java.nio.file.Paths; +import org.json.JSONObject; +import org.junit.Test; +import org.onap.dcae.WiremockBasedTest; +import org.onap.dcae.commonFunction.event.publishing.DMaaPConfigurationParser; +import org.onap.dcae.commonFunction.event.publishing.EventPublisher; + +public class ConfigLoaderIntegrationE2ETest extends WiremockBasedTest { + + @Test + public void testSuccessfulE2EFlow() { + // given + Path dMaaPConfigFile = createTemporaryFile("{}"); + Path collectorPropertiesFile = createTemporaryFile(""); + Path dMaaPConfigSource = Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"); + JSONObject dMaaPConf = readJSONFromFile(dMaaPConfigSource); + stubConsulToReturnLocalAddressOfCBS(); + stubCBSToReturnAppConfig(f("{\"collector.port\": 8080, \"streams_publishes\": %s}}", dMaaPConf)); + + EventPublisher eventPublisherMock = mock(EventPublisher.class); + ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(dMaaPConfigFile, collectorPropertiesFile); + + // when + ConfigLoader configLoader = new ConfigLoader(eventPublisherMock::reconfigure, configFilesFacade, ConfigSource::getAppConfig, () -> wiremockBasedEnvProps()); + configLoader.updateConfig(); + + // then + assertThat(readJSONFromFile(dMaaPConfigSource).toString()).isEqualTo(dMaaPConf.toString()); + assertThat(readFile(collectorPropertiesFile).trim()).isEqualTo("collector.port = 8080"); + verify(eventPublisherMock, times(1)).reconfigure( + DMaaPConfigurationParser.parseToDomainMapping(dMaaPConf).get() + ); + } + + @Test + public void shouldNotReconfigureNotOverwriteIfConfigurationHasNotChanged() { + // given + Path dMaaPConfigFile = createTemporaryFile("{}"); + Path collectorPropertiesFile = createTemporaryFile(""); + JSONObject dMaaPConf = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json")); + stubConsulToReturnLocalAddressOfCBS(); + stubCBSToReturnAppConfig(f("{\"collector.port\": 8080, \"streams_publishes\": %s}}", dMaaPConf)); + EventPublisher eventPublisherMock = mock(EventPublisher.class); + ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(dMaaPConfigFile, collectorPropertiesFile); + configFilesFacade.writeProperties(Map("collector.port", "8080")); + configFilesFacade.writeDMaaPConfiguration(dMaaPConf); + + // when + ConfigLoader configLoader = new ConfigLoader(eventPublisherMock::reconfigure, configFilesFacade, ConfigSource::getAppConfig, () -> wiremockBasedEnvProps()); + configLoader.updateConfig(); + + // then + verifyZeroInteractions(eventPublisherMock); + } + +} \ No newline at end of file -- cgit 1.2.3-korg