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.junit.jupiter.api.Assertions.assertEquals;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Test;
30 import org.mockito.Mockito;
31 import org.onap.dcae.analytics.model.AnalyticsProfile;
32 import org.onap.dcae.analytics.web.BaseAnalyticsWebTest;
33 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
34 import org.springframework.boot.SpringApplication;
35 import org.springframework.core.env.ConfigurableEnvironment;
36 import org.springframework.core.env.MapPropertySource;
37 import org.springframework.core.env.MutablePropertySources;
39 import com.google.gson.JsonObject;
40 import com.google.gson.JsonParser;
42 import reactor.core.publisher.Flux;
44 public class ConfigBindingServiceEnvironmentPostProcessorTest extends BaseAnalyticsWebTest {
47 static void beforeAll() throws Exception {
48 BaseAnalyticsWebTest.initializeConfigBindingServiceEnvironmentVariables();
52 void postProcessEnvironmentWithoutPolicy() {
53 CbsClient cbsClient = Mockito.mock(CbsClient.class);
54 ConfigBindingServiceEnvironmentPostProcessor testObject = Mockito.spy(new ConfigBindingServiceEnvironmentPostProcessor());
55 ConfigurableEnvironment configurableEnvironment = Mockito.mock(ConfigurableEnvironment.class);
56 SpringApplication springApplication = Mockito.mock(SpringApplication.class);
57 String[] activeProfiles = {AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME};
58 Map<String, Object> filterKeyMap = Mockito.mock(Map.class);
59 String configServicePropertiesKey = "config-binding-service";
60 MutablePropertySources sources = configurableEnvironment.getPropertySources();
62 String strConfig = "{\r\n" +
63 " \"config\": {\r\n" +
64 " \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" +
65 " \"streams_subscribes\": {\r\n" +
66 " \"tca_handle_in\": {\r\n" +
67 " \"type\": \"message_router\",\r\n" +
68 " \"dmaap_info\": {\r\n" +
69 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" +
73 " \"tca.enable_ecomp_logging\": true,\r\n" +
74 " \"tca.enable_abatement\": true,\r\n" +
75 " \"tca.aai.password\": \"DCAE\",\r\n" +
76 " \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" +
77 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" +
78 " \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" +
79 " \"streams_publishes\": {\r\n" +
80 " \"tca_handle_out\": {\r\n" +
81 " \"type\": \"message_router\",\r\n" +
82 " \"dmaap_info\": {\r\n" +
83 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" +
87 " \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" +
88 " \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" +
89 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" +
90 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" +
91 " \"tca.aai.username\": \"DCAE\",\r\n" +
92 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" +
93 " \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" +
94 " \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" +
95 " \"tca.aai.enable_enrichment\": true,\r\n" +
96 " \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"LESS_OR_EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":700,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"vLoadBalancer\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"Measurement_vGMUX\\\",\\\"controlLoopSchemaType\\\":\\\"VNF\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ABATED\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"GREATER\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]}]}\",\r\n" +
97 " \"tca.processing_batch_size\": 10000,\r\n" +
98 " \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" +
99 " \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" +
100 " \"service_calls\": [],\r\n" +
101 " \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" +
105 String parseConfig = "{\r\n" +
106 " \"config\": {\r\n" +
107 " \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" +
108 " \"streams_subscribes\": {\r\n" +
109 " \"tca_handle_in\": {\r\n" +
110 " \"type\": \"message_router\",\r\n" +
111 " \"dmaap_info\": {\r\n" +
112 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" +
116 " \"tca.enable_ecomp_logging\": true,\r\n" +
117 " \"tca.enable_abatement\": true,\r\n" +
118 " \"tca.aai.password\": \"DCAE\",\r\n" +
119 " \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" +
120 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" +
121 " \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" +
122 " \"streams_publishes\": {\r\n" +
123 " \"tca_handle_out\": {\r\n" +
124 " \"type\": \"message_router\",\r\n" +
125 " \"dmaap_info\": {\r\n" +
126 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" +
130 " \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" +
131 " \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" +
132 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" +
133 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" +
134 " \"tca.aai.username\": \"DCAE\",\r\n" +
135 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" +
136 " \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" +
137 " \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" +
138 " \"tca.aai.enable_enrichment\": true,\r\n" +
139 " \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"LESS_OR_EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":700,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"vLoadBalancer\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"Measurement_vGMUX\\\",\\\"controlLoopSchemaType\\\":\\\"VNF\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ABATED\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"GREATER\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]}]}\",\r\n" +
140 " \"tca.processing_batch_size\": 10000,\r\n" +
141 " \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" +
142 " \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" +
143 " \"service_calls\": [],\r\n" +
144 " \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" +
147 JsonParser parser = new JsonParser();
148 JsonObject json = parser.parse(strConfig).getAsJsonObject();
149 JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject();
151 Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles);
153 Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json));
154 Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
155 testObject.postProcessEnvironment(configurableEnvironment, springApplication);
156 assertEquals(ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(strConfig), ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(testObject.parseTcaConfig(parseJson)));
160 void postProcessEnvironmentWithPolicy() {
161 CbsClient cbsClient = Mockito.mock(CbsClient.class);
162 ConfigBindingServiceEnvironmentPostProcessor testObject = Mockito.spy(new ConfigBindingServiceEnvironmentPostProcessor());
163 ConfigurableEnvironment configurableEnvironment = Mockito.mock(ConfigurableEnvironment.class);
164 SpringApplication springApplication = Mockito.mock(SpringApplication.class);
165 String[] activeProfiles = {AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME};
166 Map<String, Object> filterKeyMap = Mockito.mock(Map.class);
167 String configServicePropertiesKey = "config-binding-service";
168 MutablePropertySources sources = configurableEnvironment.getPropertySources();
170 String parseConfig = "{\r\n" +
171 " \"config\": {\r\n" +
172 " \"config\": {\r\n" +
173 " \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" +
174 " \"streams_subscribes\": {\r\n" +
175 " \"tca_handle_in\": {\r\n" +
176 " \"type\": \"message_router\",\r\n" +
177 " \"dmaap_info\": {\r\n" +
178 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" +
182 " \"tca.enable_ecomp_logging\": true,\r\n" +
183 " \"tca.enable_abatement\": true,\r\n" +
184 " \"tca.aai.password\": \"DCAE\",\r\n" +
185 " \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" +
186 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" +
187 " \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" +
188 " \"streams_publishes\": {\r\n" +
189 " \"tca_handle_out\": {\r\n" +
190 " \"type\": \"message_router\",\r\n" +
191 " \"dmaap_info\": {\r\n" +
192 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" +
196 " \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" +
197 " \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" +
198 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" +
199 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" +
200 " \"tca.aai.username\": \"DCAE\",\r\n" +
201 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" +
202 " \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" +
203 " \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" +
204 " \"tca.aai.enable_enrichment\": true,\r\n" +
205 " \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"LESS_OR_EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":700,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"vLoadBalancer\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"Measurement_vGMUX\\\",\\\"controlLoopSchemaType\\\":\\\"VNF\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ABATED\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"GREATER\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]}]}\",\r\n" +
206 " \"tca.processing_batch_size\": 10000,\r\n" +
207 " \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" +
208 " \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" +
209 " \"service_calls\": [],\r\n" +
210 " \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" +
212 " \"policies\": {\r\n" +
213 " \"event\": {\r\n" +
214 " \"action\": \"gathered\",\r\n" +
215 " \"timestamp\": \"2020-04-08T19:45:38.927Z\",\r\n" +
216 " \"update_id\": \"d86a3b58-8c4b-49e9-ade7-8238501adf02\",\r\n" +
217 " \"policies_count\": 1\r\n" +
219 " \"items\": [{\r\n" +
220 " \"policyName\": \"onap.vfirewall.tca.1-0-0.xml\",\r\n" +
221 " \"name\": \"onap.vfirewall.tca\",\r\n" +
222 " \"tca.policy\": {\r\n" +
223 " \"domain\": \"measurementsForVfScaling\",\r\n" +
224 " \"metricsPerEventName\": [{\r\n" +
225 " \"policyName\": \"onap.vfirewall.tca\",\r\n" +
226 " \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" +
227 " \"thresholds\": [{\r\n" +
228 " \"direction\": \"LESS_OR_EQUAL\",\r\n" +
229 " \"severity\": \"MAJOR\",\r\n" +
230 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
231 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
232 " \"version\": \"1.0.2\",\r\n" +
233 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
234 " \"thresholdValue\": 500\r\n" +
236 " \"direction\": \"GREATER_OR_EQUAL\",\r\n" +
237 " \"severity\": \"CRITICAL\",\r\n" +
238 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
239 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
240 " \"version\": \"1.0.2\",\r\n" +
241 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
242 " \"thresholdValue\": 5000\r\n" +
244 " \"eventName\": \"vLoadBalancer\",\r\n" +
245 " \"controlLoopSchemaType\": \"VNF\",\r\n" +
246 " \"policyVersion\": \"v0.0.1\"\r\n" +
249 " \"type_version\": \"1.0.0\",\r\n" +
250 " \"version\": \"1.0.0\",\r\n" +
251 " \"policyVersion\": \"1.0.0\",\r\n" +
252 " \"type\": \"onap.policies.monitoring.cdap.tca.hi.lo.app\",\r\n" +
253 " \"metadata\": {\r\n" +
254 " \"policy-id\": \"onap.vfirewall.tca\",\r\n" +
255 " \"policy-version\": \"1.0.0\"\r\n" +
262 String strConfig = "{\r\n" +
263 " \"config\": {\r\n" +
264 " \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" +
265 " \"streams_subscribes\": {\r\n" +
266 " \"tca_handle_in\": {\r\n" +
267 " \"type\": \"message_router\",\r\n" +
268 " \"dmaap_info\": {\r\n" +
269 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" +
273 " \"tca.enable_ecomp_logging\": true,\r\n" +
274 " \"tca.enable_abatement\": true,\r\n" +
275 " \"tca.aai.password\": \"DCAE\",\r\n" +
276 " \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" +
277 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" +
278 " \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" +
279 " \"streams_publishes\": {\r\n" +
280 " \"tca_handle_out\": {\r\n" +
281 " \"type\": \"message_router\",\r\n" +
282 " \"dmaap_info\": {\r\n" +
283 " \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" +
287 " \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" +
288 " \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" +
289 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" +
290 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" +
291 " \"tca.aai.username\": \"DCAE\",\r\n" +
292 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" +
293 " \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" +
294 " \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" +
295 " \"tca.aai.enable_enrichment\": true,\r\n" +
296 " \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"LESS_OR_EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":700,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"vLoadBalancer\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedTotalPacketsDelta\\\",\\\"thresholdValue\\\":300,\\\"direction\\\":\\\"GREATER_OR_EQUAL\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]},{\\\"eventName\\\":\\\"Measurement_vGMUX\\\",\\\"controlLoopSchemaType\\\":\\\"VNF\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"EQUAL\\\",\\\"severity\\\":\\\"MAJOR\\\",\\\"closedLoopEventStatus\\\":\\\"ABATED\\\"},{\\\"closedLoopControlName\\\":\\\"ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e\\\",\\\"version\\\":\\\"1.0.2\\\",\\\"fieldPath\\\":\\\"$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value\\\",\\\"thresholdValue\\\":0,\\\"direction\\\":\\\"GREATER\\\",\\\"severity\\\":\\\"CRITICAL\\\",\\\"closedLoopEventStatus\\\":\\\"ONSET\\\"}]}]}\",\r\n" +
297 " \"tca.processing_batch_size\": 10000,\r\n" +
298 " \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" +
299 " \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" +
300 " \"service_calls\": [],\r\n" +
301 " \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" +
303 " \"policies\": {\r\n" +
304 " \"event\": {\r\n" +
305 " \"action\": \"gathered\",\r\n" +
306 " \"timestamp\": \"2020-04-08T19:45:38.927Z\",\r\n" +
307 " \"update_id\": \"d86a3b58-8c4b-49e9-ade7-8238501adf02\",\r\n" +
308 " \"policies_count\": 1\r\n" +
310 " \"items\": [{\r\n" +
311 " \"policyName\": \"onap.vfirewall.tca.1-0-0.xml\",\r\n" +
312 " \"name\": \"onap.vfirewall.tca\",\r\n" +
313 " \"tca.policy\": {\r\n" +
314 " \"domain\": \"measurementsForVfScaling\",\r\n" +
315 " \"metricsPerEventName\": [{\r\n" +
316 " \"policyName\": \"onap.vfirewall.tca\",\r\n" +
317 " \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" +
318 " \"thresholds\": [{\r\n" +
319 " \"direction\": \"LESS_OR_EQUAL\",\r\n" +
320 " \"severity\": \"MAJOR\",\r\n" +
321 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
322 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
323 " \"version\": \"1.0.2\",\r\n" +
324 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
325 " \"thresholdValue\": 500\r\n" +
327 " \"direction\": \"GREATER_OR_EQUAL\",\r\n" +
328 " \"severity\": \"CRITICAL\",\r\n" +
329 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
330 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
331 " \"version\": \"1.0.2\",\r\n" +
332 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
333 " \"thresholdValue\": 5000\r\n" +
335 " \"eventName\": \"vLoadBalancer\",\r\n" +
336 " \"controlLoopSchemaType\": \"VNF\",\r\n" +
337 " \"policyVersion\": \"v0.0.1\"\r\n" +
340 " \"type_version\": \"1.0.0\",\r\n" +
341 " \"version\": \"1.0.0\",\r\n" +
342 " \"policyVersion\": \"1.0.0\",\r\n" +
343 " \"type\": \"onap.policies.monitoring.cdap.tca.hi.lo.app\",\r\n" +
344 " \"metadata\": {\r\n" +
345 " \"policy-id\": \"onap.vfirewall.tca\",\r\n" +
346 " \"policy-version\": \"1.0.0\"\r\n" +
351 JsonParser parser = new JsonParser();
352 JsonObject json = parser.parse(strConfig).getAsJsonObject();
353 JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject();
355 Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles);
357 Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json));
358 Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
359 testObject.postProcessEnvironment(configurableEnvironment, springApplication);
360 assertEquals(ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(strConfig), ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(testObject.parseTcaConfig(parseJson)));
363 public static String replaceBlank(String str) {
366 Pattern p = Pattern.compile("\\s*|\t|\r|\n");
367 Matcher m = p.matcher(str);
368 dest = m.replaceAll("");