aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java
diff options
context:
space:
mode:
authorPawelSzalapski <pawel.szalapski@nokia.com>2018-08-02 10:31:56 +0200
committerPawelSzalapski <pawel.szalapski@nokia.com>2018-08-06 09:43:32 +0200
commit7752c2d818e6d19e4d805c2fd6760b4a13d601bc (patch)
tree053cbc5afd76a8b9644ec62298053aad8cf5e2a8 /src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java
parent654ebdff4c9ec2487b819d2b76273732759de4c7 (diff)
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 <pawel.szalapski@nokia.com> Issue-ID: DCAEGEN2-519
Diffstat (limited to 'src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java')
-rw-r--r--src/test/java/org/onap/dcae/controller/ConfigLoaderIntegrationE2ETest.java92
1 files changed, 92 insertions, 0 deletions
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