2 * ============LICENSE_START====================================
3 * DCAEGEN2-SERVICES-SDK
4 * =========================================================
5 * Copyright (C) 2019-2021 Nokia. All rights reserved.
6 * Copyright (C) 2022 AT&T Intellectual Property. All rights reserved.
7 * =========================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=====================================
22 package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api;
25 import org.junit.Rule;
26 import org.junit.contrib.java.lang.system.EnvironmentVariables;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.exceptions.CbsClientConfigurationException;
30 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
31 import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
33 import java.net.URISyntaxException;
34 import java.nio.file.Paths;
36 import static org.assertj.core.api.Assertions.assertThat;
37 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
40 * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
41 * @since February 2019
43 class CbsClientConfigurationTest {
45 private static final String ENV_APPNAME = "HOSTNAME";
46 private static final String ENV_CBS_CLIENT_CONFIG_PATH = "CBS_CLIENT_CONFIG_PATH";
47 private static final String ENV_CBS_CLIENT_POLICY_PATH = "CBS_CLIENT_POLICY_PATH";
50 public final EnvironmentVariables envs = new EnvironmentVariables();
54 envs.clear(ENV_APPNAME, ENV_CBS_CLIENT_CONFIG_PATH, ENV_CBS_CLIENT_POLICY_PATH);
58 void fromEnvironment_shouldReturnConfigurationWithCorrectConfigPath_when_CBS_CLIENT_CONFIG_PATH_isSet() {
60 createBasicValidEnvsConfiguration();
61 envs.set(ENV_CBS_CLIENT_CONFIG_PATH, "/new/config/path/application.yaml");
64 CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
67 assertThat(configuration).isNotNull();
68 assertThat(configuration.configMapFilePath()).isEqualTo("/new/config/path/application.yaml");
72 void fromEnvironment_shouldReturnConfigurationWithCorrectPolicyPath_when_CBS_CLIENT_POLICY_PATH_isSet() {
74 createBasicValidEnvsConfiguration();
75 envs.set(ENV_CBS_CLIENT_POLICY_PATH, "/new/config/path/policy.json");
78 CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
81 assertThat(configuration).isNotNull();
82 assertThat(configuration.policySyncFilePath()).isEqualTo("/new/config/path/policy.json");
86 void fromEnvironment_shouldReturnConfigurationWithDefaultPolicyAndConfigPaths_whenEnvsNotSet() {
88 createBasicValidEnvsConfiguration();
91 CbsClientConfiguration configuration = CbsClientConfiguration.fromEnvironment();
94 assertThat(configuration).isNotNull();
95 assertThat(configuration.configMapFilePath()).isEqualTo("/app-config/application_config.yaml");
96 assertThat(configuration.policySyncFilePath()).isEqualTo("/etc/policies/policies.json");
101 void fromEnvironment_shouldReturn_CbsClientConfigurationException_WhenAllEnvVariablesAreMissing() {
102 assertThatExceptionOfType(CbsClientConfigurationException.class)
103 .isThrownBy(CbsClientConfiguration::fromEnvironment);
106 private void createBasicValidEnvsConfiguration() {
107 envs.set(ENV_APPNAME, "dcae-prh");