2 * ================================================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
20 package org.onap.dcae.analytics.web.spring;
22 import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants
23 .CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY;
24 import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants
25 .CONFIG_BINDING_SERVICE_PROPERTIES_KEY;
26 import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants
27 .CONSUL_HOST_ENV_VARIABLE_KEY;
28 import static org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants
29 .SERVICE_NAME_ENV_VARIABLE_KEY;
31 import java.util.HashMap;
34 import org.junit.jupiter.api.BeforeAll;
35 import org.junit.jupiter.api.Disabled;
36 import org.junit.jupiter.api.Test;
37 import org.onap.dcae.analytics.model.AnalyticsProfile;
38 import org.onap.dcae.analytics.web.BaseAnalyticsWebSpringBootIT;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.core.env.AbstractEnvironment;
41 import org.springframework.core.env.Environment;
42 import org.springframework.core.env.MapPropertySource;
43 import org.springframework.core.env.PropertySource;
44 import org.springframework.test.context.ActiveProfiles;
47 * @author Rajiv Singla
49 @ActiveProfiles(value = {AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME}, inheritProfiles = false)
51 class ConfigBindingServiceEnvironmentPostProcessorIT extends BaseAnalyticsWebSpringBootIT {
54 static void beforeAll() throws Exception {
55 // sets up environment variables for testing purposes
56 final HashMap<String, String> testEnvironmentVariables = new HashMap<>();
57 final String testConsulHostValue = "localhost";
58 final String testConfigBindingService = "config_binding_service";
59 final String testServiceName = "tca_dev";
60 testEnvironmentVariables.put(CONSUL_HOST_ENV_VARIABLE_KEY, testConsulHostValue);
61 testEnvironmentVariables.put(CONFIG_BINDING_SERVICE_ENV_VARIABLE_KEY, testConfigBindingService);
62 testEnvironmentVariables.put(SERVICE_NAME_ENV_VARIABLE_KEY, testServiceName);
63 setEnvironmentVariables(testEnvironmentVariables);
67 private Environment environment;
70 void postProcessEnvironment() {
72 final Map<String, Object> properties = new HashMap<>();
73 for (final PropertySource<?> propertySource : ((AbstractEnvironment) environment).getPropertySources()) {
74 if (propertySource.getName().equals(CONFIG_BINDING_SERVICE_PROPERTIES_KEY)) {
75 properties.putAll(((MapPropertySource) propertySource).getSource());
78 properties.forEach((key, value) -> logger.debug("{} -> {}", key, value));