aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcae/configuration
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/dcae/configuration')
-rw-r--r--src/test/java/org/onap/dcae/configuration/ConfigFilesFacadeTest.java137
-rw-r--r--src/test/java/org/onap/dcae/configuration/ConfigLoaderFactoryTest.java43
-rw-r--r--src/test/java/org/onap/dcae/configuration/ConfigLoaderTest.java294
-rw-r--r--src/test/java/org/onap/dcae/configuration/ConfigParsingTest.java73
-rw-r--r--src/test/java/org/onap/dcae/configuration/cbs/CbsClientConfigurationResolverTest.java47
-rw-r--r--src/test/java/org/onap/dcae/configuration/cbs/CbsClientFactoryTest.java36
-rw-r--r--src/test/java/org/onap/dcae/configuration/cbs/CbsConfigResolverTest.java74
7 files changed, 704 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dcae/configuration/ConfigFilesFacadeTest.java b/src/test/java/org/onap/dcae/configuration/ConfigFilesFacadeTest.java
new file mode 100644
index 00000000..8849369a
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/ConfigFilesFacadeTest.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018,2020 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.configuration;
+
+import static io.vavr.API.Map;
+import static io.vavr.API.Some;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.onap.dcae.TestingUtilities.assertFailureHasInfo;
+import static org.onap.dcae.TestingUtilities.assertJSONObjectsEqual;
+import static org.onap.dcae.TestingUtilities.createTemporaryFile;
+import static org.onap.dcae.TestingUtilities.readFile;
+import static org.onap.dcae.TestingUtilities.readJSONFromFile;
+
+import io.vavr.collection.Map;
+import io.vavr.control.Try;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.json.JSONObject;
+import org.junit.Test;
+
+public class ConfigFilesFacadeTest {
+
+ private static final Path NON_EXISTENT = Paths.get("/non-existent");
+ private static final ConfigFilesFacade TO_NON_EXISTENT_POINTING_FACADE = new ConfigFilesFacade(NON_EXISTENT,
+ NON_EXISTENT);
+
+ @Test
+ public void shouldReadPropertyFile() {
+ // given
+ Path temporaryFile = createTemporaryFile("some.property=10");
+
+ // when
+ ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
+
+ Try<Map<String, String>> propertiesConfigurations = configFilesFacade.readCollectorProperties();
+
+ // then
+ assertThat(propertiesConfigurations.isSuccess()).isTrue();
+ assertThat(propertiesConfigurations.get().containsKey("some.property")).isTrue();
+ assertThat(propertiesConfigurations.get().get("some.property")).isEqualTo(Some("10"));
+ }
+
+
+ @Test
+ public void shouldReadDMaaPFile() {
+ // given
+ Path temporaryFile = createTemporaryFile("{}");
+
+ // when
+ ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
+
+ Try<JSONObject> dMaaPConfiguration = configFilesFacade.readDMaaPConfiguration();
+
+ // then
+ assertThat(dMaaPConfiguration.isSuccess()).isTrue();
+ assertThat(dMaaPConfiguration.get().toString()).isEqualTo("{}");
+ }
+
+ @Test
+ public void shouldWriteDMaaPConf() {
+ // given
+ Path temporaryFile = createTemporaryFile("{}");
+ JSONObject desiredConf = new JSONObject("{\"key\": 1}");
+
+ // when
+ ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
+
+ Try<Void> propertiesConfigurations = configFilesFacade.writeDMaaPConfiguration(desiredConf);
+
+ // then
+ assertThat(propertiesConfigurations.isSuccess()).isTrue();
+ assertJSONObjectsEqual(readJSONFromFile(temporaryFile), desiredConf);
+ }
+
+
+ @Test
+ public void shouldWriteProperties() {
+ // given
+ Path temporaryFile = createTemporaryFile("{}");
+
+ // when
+ ConfigFilesFacade configFilesFacade = new ConfigFilesFacade(temporaryFile, temporaryFile);
+ Try<Void> propertiesConfigurations = configFilesFacade.writeProperties(Map("prop1", "hi"));
+
+ // then
+ assertThat(propertiesConfigurations.isSuccess()).isTrue();
+ assertThat(readFile(temporaryFile).trim()).isEqualTo("prop1 = hi");
+ }
+
+ @Test
+ public void shouldContainPropertiesPathInCaseOfFailures() {
+ Try<Map<String, String>> result = TO_NON_EXISTENT_POINTING_FACADE.readCollectorProperties();
+ assertThat(result.isFailure()).isTrue();
+ assertFailureHasInfo(result, NON_EXISTENT.toString());
+ }
+
+ @Test
+ public void shouldContainDMaaPPathPathInCaseOfFailures() {
+ Try<JSONObject> result = TO_NON_EXISTENT_POINTING_FACADE.readDMaaPConfiguration();
+ assertThat(result.isFailure()).isTrue();
+ assertFailureHasInfo(result, NON_EXISTENT.toString());
+ }
+
+ @Test
+ public void shouldContainPropertiesPathPathInCaseOfFailuresOnWrite() {
+ // given
+ Try<Void> result = TO_NON_EXISTENT_POINTING_FACADE.writeProperties(Map("any", "any"));
+ assertThat(result.isFailure()).isTrue();
+ assertFailureHasInfo(result, NON_EXISTENT.toString());
+ }
+
+ @Test
+ public void shouldContainDMaaPPathPathInCaseOfFailuresOnWrite() {
+ // given
+ Try<Void> result = TO_NON_EXISTENT_POINTING_FACADE.writeDMaaPConfiguration(new JSONObject());
+ assertThat(result.isFailure()).isTrue();
+ assertFailureHasInfo(result, NON_EXISTENT.toString());
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/configuration/ConfigLoaderFactoryTest.java b/src/test/java/org/onap/dcae/configuration/ConfigLoaderFactoryTest.java
new file mode 100644
index 00000000..e9421909
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/ConfigLoaderFactoryTest.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2020 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.configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.file.Path;
+import org.junit.Test;
+
+public class ConfigLoaderFactoryTest {
+
+ @Test
+ public void createsCbsConfigLoaderSuccessfully() {
+ // given
+ Path testPropertiesPath = Path.of("src/test/resources/testcollector.properties");
+ Path testDmaapConfigPath = Path.of("src/test/resources/testParseDMaaPCredentialsGen2.json");
+
+ // when
+ ConfigLoader configLoader = ConfigLoaderFactory.create(
+ testPropertiesPath,
+ testDmaapConfigPath);
+
+ // then
+ assertThat(configLoader).isNotNull();
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/configuration/ConfigLoaderTest.java b/src/test/java/org/onap/dcae/configuration/ConfigLoaderTest.java
new file mode 100644
index 00000000..46d864a0
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/ConfigLoaderTest.java
@@ -0,0 +1,294 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2020 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.configuration;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.onap.dcae.TestingUtilities.readJSONFromFile;
+import static org.onap.dcae.common.publishing.VavrUtils.f;
+
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
+import io.vavr.control.Try;
+import java.nio.file.Paths;
+import io.vavr.control.Option;
+import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.dcae.configuration.cbs.CbsConfigResolver;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class ConfigLoaderTest {
+
+ private static final String COLLECTOR_PORT = "collector.port";
+ private static final String PORT_8080 = "8080";
+ private static final String PORT_8081 = "8081";
+ private static final String COLLECTOR_KEYSTORE_FILE_LOCATION = "collector.keystore.file.location";
+ private static final String SOME_PATH = "some/path";
+ private static final String COLLECTOR_SCHEMA_FILE = "collector.schema.file";
+ private static final String SOME_SCHEMA = "some schema";
+
+ @Mock
+ private CbsConfigResolver cbsConfigResolverMock;
+
+ @Mock
+ private ConfigFilesFacade configFilesFacadeMock;
+
+ @InjectMocks
+ private ConfigLoader configLoader;
+
+ @Mock
+ private Runnable applicationRestarter;
+
+
+ @Before
+ public void setup() {
+ when(configFilesFacadeMock.readCollectorProperties()).thenReturn(Try.of(HashMap::empty));
+ when(configFilesFacadeMock.readDMaaPConfiguration()).thenReturn(Try.of(JSONObject::new));
+ }
+
+ @Test
+ public void shouldCallConfigSourceForData() {
+ // given
+ HashMap<String, String> properties = HashMap.of(COLLECTOR_PORT, PORT_8080);
+ mockVesInitialProperties(properties);
+ mockVesConfigInCbs(properties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(cbsConfigResolverMock).getAppConfig();
+ }
+
+ @Test
+ public void shouldNotUpdatePropertiesWhenSameKeySetAndSameValues() {
+ // given
+ HashMap<String, String> properties = HashMap.of(COLLECTOR_PORT, PORT_8080);
+ mockVesInitialProperties(properties);
+ mockVesConfigInCbs(properties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, never()).writeProperties(any());
+ verify(applicationRestarter, never()).run();
+ }
+
+ @Test
+ public void shouldUpdatePropertiesWhenSameKeySetButDifferentValues() {
+ // given
+ HashMap<String, String> initialProperties = HashMap.of(COLLECTOR_PORT, PORT_8080);
+ HashMap<String, String> cbsProperties = HashMap.of(COLLECTOR_PORT, PORT_8081);
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, times(1)).writeProperties(cbsProperties);
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldUpdatePropertiesWhenVesKeysAreSubsetOfCbsKeysAndSubsetHasSameValues() {
+ // given
+ HashMap<String, String> initialProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080);
+ HashMap<String, String> cbsProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080,
+ COLLECTOR_KEYSTORE_FILE_LOCATION, SOME_PATH);
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, times(1)).writeProperties(cbsProperties);
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldUpdatePropertiesWhenVesKeysAreSubsetOfCbsKeysAndSubsetHasDifferentValues() {
+ HashMap<String, String> initialProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080);
+ HashMap<String, String> cbsProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8081,
+ COLLECTOR_KEYSTORE_FILE_LOCATION, SOME_PATH);
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, times(1)).writeProperties(cbsProperties);
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldNotUpdatePropertiesWhenCbsKeysAreSubsetOfVesKeysAndSubsetHasSameValues() {
+ HashMap<String, String> initialProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080,
+ COLLECTOR_KEYSTORE_FILE_LOCATION, SOME_PATH);
+ HashMap<String, String> cbsProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080);
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, never()).writeProperties(any());
+ verify(applicationRestarter, never()).run();
+ }
+
+ @Test
+ public void shouldUpdatePropertiesWhenCbsKeysAreSubsetOfVesKeysAndSubsetHasDifferentValues() {
+ HashMap<String, String> initialProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080,
+ COLLECTOR_KEYSTORE_FILE_LOCATION, SOME_PATH);
+ HashMap<String, String> cbsProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8081);
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, times(1)).writeProperties(cbsProperties);
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldUpdatePropertiesWhenVesAndCbsKeySetsIntersectAndIntersectingKeysHaveSameValues() {
+ HashMap<String, String> initialProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080,
+ COLLECTOR_KEYSTORE_FILE_LOCATION, SOME_PATH);
+ HashMap<String, String> cbsProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080,
+ COLLECTOR_SCHEMA_FILE, SOME_SCHEMA
+ );
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, times(1)).writeProperties(cbsProperties);
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldUpdatePropertiesWhenVesAndCbsKeySetsIntersectAndIntersectingKeysHaveDifferentValues() {
+ HashMap<String, String> initialProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8080,
+ COLLECTOR_KEYSTORE_FILE_LOCATION, SOME_PATH);
+ HashMap<String, String> cbsProperties = HashMap.of(
+ COLLECTOR_PORT, PORT_8081,
+ COLLECTOR_SCHEMA_FILE, SOME_SCHEMA
+ );
+ mockVesInitialProperties(initialProperties);
+ mockVesConfigInCbs(cbsProperties);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, times(1)).writeProperties(cbsProperties);
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldUpdateDmaapConfigWhenConfigurationChanged() {
+ // given
+ JSONObject emptyDmaapConfig = new JSONObject();
+ JSONObject dmaapConfig = loadSampleDmaapConfig();
+ mockVesInitialDmaapConfig(emptyDmaapConfig);
+ mockVesDmaapConfigInCbs(dmaapConfig);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock).writeDMaaPConfiguration(argThat(dmaapConfig::similar));
+ verify(applicationRestarter, times(1)).run();
+ }
+
+ @Test
+ public void shouldNotUpdateDmaapConfigWhenConfigurationNotChanged() {
+ // given
+ JSONObject dmaapConf = loadSampleDmaapConfig();
+ mockVesInitialDmaapConfig(dmaapConf);
+ mockVesDmaapConfigInCbs(dmaapConf);
+
+ // when
+ configLoader.updateConfig();
+
+ // then
+ verify(configFilesFacadeMock, never()).writeDMaaPConfiguration(any());
+ verify(applicationRestarter, never()).run();
+ }
+
+ private void mockVesInitialDmaapConfig(JSONObject dmaapConf) {
+ when(configFilesFacadeMock.readDMaaPConfiguration()).thenReturn(Try.of(() -> dmaapConf));
+ }
+
+ private void mockVesDmaapConfigInCbs(JSONObject dmaapConf) {
+ JSONObject jsonObject = new JSONObject(f("{\"streams_publishes\": %s}}", dmaapConf));
+ when(cbsConfigResolverMock.getAppConfig()).thenReturn(Option.of(jsonObject));
+ }
+
+ private void mockVesConfigInCbs(HashMap<String, String> properties) {
+ when(cbsConfigResolverMock.getAppConfig()).thenReturn(Option.of(prepareConfigurationJson(properties)));
+ }
+
+ private void mockVesInitialProperties(HashMap<String, String> properties) {
+ when(configFilesFacadeMock.readCollectorProperties()).thenReturn(Try.of(() -> properties));
+ }
+
+
+ private JSONObject loadSampleDmaapConfig() {
+ return readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
+ }
+
+ private JSONObject prepareConfigurationJson(Map<String, String> properties) {
+ String template = "{%s, \"streams_publishes\": {}}";
+ String customProperties = properties
+ .map(property -> "\"" + property._1 + "\": \"" + property._2 + "\"")
+ .mkString(", ");
+ String jsonBody = f(template, customProperties);
+ return new JSONObject(jsonBody);
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/configuration/ConfigParsingTest.java b/src/test/java/org/onap/dcae/configuration/ConfigParsingTest.java
new file mode 100644
index 00000000..248d3c5a
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/ConfigParsingTest.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018,2020 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.configuration;
+
+import io.vavr.collection.Map;
+import io.vavr.control.Option;
+import org.json.JSONObject;
+import org.junit.Test;
+
+import java.nio.file.Paths;
+
+import static io.vavr.API.Map;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.onap.dcae.TestingUtilities.assertJSONObjectsEqual;
+import static org.onap.dcae.TestingUtilities.readJSONFromFile;
+
+public class ConfigParsingTest {
+
+ @Test
+ public void shouldReturnDMaaPConfig() {
+ JSONObject dMaaPConf = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
+ JSONObject root = new JSONObject();
+ root.put("key1", "someProperty");
+ root.put("key2", "someProperty");
+ root.put("streams_publishes", dMaaPConf);
+
+ Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
+
+ assertThat(dMaaPConfig.isEmpty()).isFalse();
+ assertJSONObjectsEqual(dMaaPConfig.get(), dMaaPConf);
+ }
+
+ @Test
+ public void shouldReturnEmptyIfDMaaPConfigIsInvalid() {
+ JSONObject root = new JSONObject();
+ root.put("streams_publishes", 1);
+
+ Option<JSONObject> dMaaPConfig = ConfigParsing.getDMaaPConfig(root);
+
+ assertThat(dMaaPConfig.isEmpty()).isTrue();
+ }
+
+ @Test
+ public void getProperties() {
+ JSONObject dMaaPConf = readJSONFromFile(Paths.get("src/test/resources/testParseDMaaPCredentialsGen2.json"));
+ JSONObject root = new JSONObject();
+ root.put("key1", "someProperty");
+ root.put("key2", "someProperty");
+ root.put("streams_publishes", dMaaPConf);
+
+ Map<String, String> properties = ConfigParsing.getProperties(root);
+ assertThat(properties).isEqualTo(Map("key1", "someProperty", "key2", "someProperty"));
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/configuration/cbs/CbsClientConfigurationResolverTest.java b/src/test/java/org/onap/dcae/configuration/cbs/CbsClientConfigurationResolverTest.java
new file mode 100644
index 00000000..57824595
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/cbs/CbsClientConfigurationResolverTest.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2020 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.configuration.cbs;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
+
+public class CbsClientConfigurationResolverTest {
+
+ private static final String DEFAULT_PROTOCOL = "http";
+ private static final String DEFAULT_HOSTNAME = "config-binding-service";
+ private static final int DEFAULT_PORT = 10000;
+ private static final String DEFAULT_APP_NAME = "dcae-ves-collector";
+
+ @Test
+ @DisabledIfEnvironmentVariable(named = "CONFIG_BINDING_SERVICE", matches = ".+")
+ public void shouldLoadDefaultConfigWhenEnvNotPresent() {
+ // when
+ CbsClientConfiguration configuration = new CbsClientConfigurationResolver().resolveCbsClientConfiguration();
+
+ // then
+ assertThat(configuration.protocol()).isEqualTo(DEFAULT_PROTOCOL);
+ assertThat(configuration.hostname()).isEqualTo(DEFAULT_HOSTNAME);
+ assertThat(configuration.port()).isEqualTo(DEFAULT_PORT);
+ assertThat(configuration.appName()).isEqualTo(DEFAULT_APP_NAME);
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/configuration/cbs/CbsClientFactoryTest.java b/src/test/java/org/onap/dcae/configuration/cbs/CbsClientFactoryTest.java
new file mode 100644
index 00000000..4b17f68d
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/cbs/CbsClientFactoryTest.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2020 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.configuration.cbs;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+public class CbsClientFactoryTest {
+
+ @Test
+ public void createsClientSuccessfully() {
+ // when
+ CbsConfigResolver cbsConfigResolver = new CbsConfigResolverFactory().create();
+
+ // then
+ assertThat(cbsConfigResolver).isNotNull();
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/dcae/configuration/cbs/CbsConfigResolverTest.java b/src/test/java/org/onap/dcae/configuration/cbs/CbsConfigResolverTest.java
new file mode 100644
index 00000000..b413a64d
--- /dev/null
+++ b/src/test/java/org/onap/dcae/configuration/cbs/CbsConfigResolverTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * org.onap.dcaegen2.collectors.ves
+ * ================================================================================
+ * Copyright (C) 2020 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.configuration.cbs;
+
+import com.github.tomakehurst.wiremock.junit.WireMockRule;
+import org.json.JSONObject;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
+import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class CbsConfigResolverTest {
+
+ private static final String VES_CONFIG = "{\"collector.port\": 8081}";
+ private static final String HOSTNAME = "localhost";
+ private static final String PROTOCOL = "http";
+ private static final String APP_NAME = "VESCollector";
+
+ @Rule
+ public final WireMockRule wireMockRule = new WireMockRule(
+ wireMockConfig().dynamicPort().dynamicPort());
+
+ @Test
+ public void shouldFetchConfigurationFromCBS() {
+ // given
+ final int PORT = wireMockRule.port();
+ stubCBSToReturnAppConfig();
+
+ // when
+ CbsClientConfiguration cbsClientConfiguration = ImmutableCbsClientConfiguration.builder()
+ .protocol(PROTOCOL)
+ .hostname(HOSTNAME)
+ .port(PORT)
+ .appName(APP_NAME)
+ .build();
+ JSONObject appConfig = new CbsConfigResolver(cbsClientConfiguration).getAppConfig().get();
+
+ // then
+ assertThat(appConfig).isNotNull();
+ assertThat(appConfig.toString()).isEqualTo(new JSONObject(VES_CONFIG).toString());
+ }
+
+ private void stubCBSToReturnAppConfig() {
+ stubFor(get(urlEqualTo("/service_component/VESCollector"))
+ .willReturn(aResponse().withBody(CbsConfigResolverTest.VES_CONFIG)));
+ }
+} \ No newline at end of file