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 " \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" +
173 " \"streams_subscribes\": {\r\n" +
174 " \"tca_handle_in\": {\r\n" +
175 " \"type\": \"message_router\",\r\n" +
176 " \"dmaap_info\": {\r\n" +
177 " \"topic_url\": \"http://message-router:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT/\"\r\n" +
181 " \"tca.enable_ecomp_logging\": true,\r\n" +
182 " \"tca.enable_abatement\": true,\r\n" +
183 " \"tca.aai.password\": \"DCAE\",\r\n" +
184 " \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" +
185 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" +
186 " \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" +
187 " \"streams_publishes\": {\r\n" +
188 " \"tca_handle_out\": {\r\n" +
189 " \"type\": \"message_router\",\r\n" +
190 " \"dmaap_info\": {\r\n" +
191 " \"topic_url\": \"http://message-router:3904/events/unauthenticated.TCAGEN2_OUTPUT/\"\r\n" +
195 " \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" +
196 " \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" +
197 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" +
198 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" +
199 " \"tca.aai.username\": \"DCAE\",\r\n" +
200 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" +
201 " \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" +
202 " \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" +
203 " \"tca.aai.enable_enrichment\": true,\r\n" +
204 " \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"TEST-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\\\":\\\"TEST-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" +
205 " \"tca.processing_batch_size\": 10000,\r\n" +
206 " \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" +
207 " \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" +
208 " \"service_calls\": [],\r\n" +
209 " \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" +
211 " \"policies\": {\r\n" +
212 " \"event\": {},\r\n" +
213 " \"items\": [{\r\n" +
214 " \"tca.policy\": {\r\n" +
215 " \"domain\": \"measurementsForVfScaling\",\r\n" +
216 " \"metricsPerEventName\": [{\r\n" +
217 " \"policyName\": \"onap.vfirewall.tca\",\r\n" +
218 " \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" +
219 " \"thresholds\": [{\r\n" +
220 " \"direction\": \"LESS_OR_EQUAL\",\r\n" +
221 " \"severity\": \"MAJOR\",\r\n" +
222 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
223 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
224 " \"version\": \"1.0.2\",\r\n" +
225 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
226 " \"thresholdValue\": 500\r\n" +
228 " \"direction\": \"GREATER_OR_EQUAL\",\r\n" +
229 " \"severity\": \"CRITICAL\",\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\": 5000\r\n" +
236 " \"eventName\": \"vLoadBalancer\",\r\n" +
237 " \"controlLoopSchemaType\": \"VNF\",\r\n" +
238 " \"policyVersion\": \"v0.0.1\"\r\n" +
245 String strConfig = "{\r\n" +
246 " \"config\": {\r\n" +
247 " \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" +
248 " \"streams_subscribes\": {\r\n" +
249 " \"tca_handle_in\": {\r\n" +
250 " \"type\": \"message_router\",\r\n" +
251 " \"dmaap_info\": {\r\n" +
252 " \"topic_url\": \"http://message-router:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT/\"\r\n" +
256 " \"tca.enable_ecomp_logging\": true,\r\n" +
257 " \"tca.enable_abatement\": true,\r\n" +
258 " \"tca.aai.password\": \"DCAE\",\r\n" +
259 " \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" +
260 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" +
261 " \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" +
262 " \"streams_publishes\": {\r\n" +
263 " \"tca_handle_out\": {\r\n" +
264 " \"type\": \"message_router\",\r\n" +
265 " \"dmaap_info\": {\r\n" +
266 " \"topic_url\": \"http://message-router:3904/events/unauthenticated.TCAGEN2_OUTPUT/\"\r\n" +
270 " \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" +
271 " \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" +
272 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" +
273 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" +
274 " \"tca.aai.username\": \"DCAE\",\r\n" +
275 " \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" +
276 " \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" +
277 " \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" +
278 " \"tca.aai.enable_enrichment\": true,\r\n" +
279 " \"tca.policy\": \"{\\\"domain\\\":\\\"measurementsForVfScaling\\\",\\\"metricsPerEventName\\\":[{\\\"eventName\\\":\\\"vFirewallBroadcastPackets\\\",\\\"controlLoopSchemaType\\\":\\\"VM\\\",\\\"policyScope\\\":\\\"DCAE\\\",\\\"policyName\\\":\\\"DCAE.Config_tca-hi-lo\\\",\\\"policyVersion\\\":\\\"v0.0.1\\\",\\\"thresholds\\\":[{\\\"closedLoopControlName\\\":\\\"TEST-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\\\":\\\"TEST-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" +
280 " \"tca.processing_batch_size\": 10000,\r\n" +
281 " \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" +
282 " \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" +
283 " \"service_calls\": [],\r\n" +
284 " \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" +
286 " \"policies\": {\r\n" +
287 " \"event\": {},\r\n" +
288 " \"items\": [{\r\n" +
289 " \"tca.policy\": {\r\n" +
290 " \"domain\": \"measurementsForVfScaling\",\r\n" +
291 " \"metricsPerEventName\": [{\r\n" +
292 " \"policyName\": \"onap.vfirewall.tca\",\r\n" +
293 " \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" +
294 " \"thresholds\": [{\r\n" +
295 " \"direction\": \"LESS_OR_EQUAL\",\r\n" +
296 " \"severity\": \"MAJOR\",\r\n" +
297 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
298 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
299 " \"version\": \"1.0.2\",\r\n" +
300 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
301 " \"thresholdValue\": 500\r\n" +
303 " \"direction\": \"GREATER_OR_EQUAL\",\r\n" +
304 " \"severity\": \"CRITICAL\",\r\n" +
305 " \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" +
306 " \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" +
307 " \"version\": \"1.0.2\",\r\n" +
308 " \"closedLoopEventStatus\": \"ONSET\",\r\n" +
309 " \"thresholdValue\": 5000\r\n" +
311 " \"eventName\": \"vLoadBalancer\",\r\n" +
312 " \"controlLoopSchemaType\": \"VNF\",\r\n" +
313 " \"policyVersion\": \"v0.0.1\"\r\n" +
319 JsonParser parser = new JsonParser();
320 JsonObject json = parser.parse(strConfig).getAsJsonObject();
321 JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject();
323 Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles);
325 Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json));
326 Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
327 testObject.postProcessEnvironment(configurableEnvironment, springApplication);
328 assertEquals(ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(strConfig), ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(testObject.parseTcaConfig(parseJson)));
331 public static String replaceBlank(String str) {
334 Pattern p = Pattern.compile("\\s*|\t|\r|\n");
335 Matcher m = p.matcher(str);
336 dest = m.replaceAll("");