summaryrefslogtreecommitdiffstats
path: root/dcae-analytics/dcae-analytics-web/src/test/java/org/onap/dcae/analytics/web/spring/ConfigBindingServiceEnvironmentPostProcessorTest.java
blob: 0fce3c20078bcc054c72a864bca4eab3e4335ace (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
 * ================================================================================
 * Copyright (c) 2018 AT&T Intellectual Property. 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.analytics.web.spring;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcae.analytics.model.AnalyticsProfile;
import org.onap.dcae.analytics.web.BaseAnalyticsWebTest;
import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient;
import org.springframework.boot.SpringApplication;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import reactor.core.publisher.Flux;

public class ConfigBindingServiceEnvironmentPostProcessorTest extends BaseAnalyticsWebTest {

    @BeforeAll
    static void beforeAll() throws Exception {
        BaseAnalyticsWebTest.initializeConfigBindingServiceEnvironmentVariables();
    }

    @Test
    void postProcessEnvironmentWithoutPolicy() {
    	CbsClient cbsClient = Mockito.mock(CbsClient.class);
    	ConfigBindingServiceEnvironmentPostProcessor testObject = Mockito.spy(new ConfigBindingServiceEnvironmentPostProcessor());
        ConfigurableEnvironment configurableEnvironment = Mockito.mock(ConfigurableEnvironment.class);
        SpringApplication springApplication = Mockito.mock(SpringApplication.class);
        String[] activeProfiles = {AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME};
    	Map<String, Object> filterKeyMap = Mockito.mock(Map.class);
    	String configServicePropertiesKey = "config-binding-service";
        MutablePropertySources sources = configurableEnvironment.getPropertySources();

        String strConfig =  "{\r\n" + 
                "    \"config\": {\r\n" + 
                "        \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" + 
                "        \"streams_subscribes\": {\r\n" + 
                "            \"tca_handle_in\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"tca.enable_ecomp_logging\": true,\r\n" + 
                "        \"tca.enable_abatement\": true,\r\n" + 
                "        \"tca.aai.password\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" + 
                "        \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" + 
                "        \"streams_publishes\": {\r\n" + 
                "            \"tca_handle_out\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" + 
                "        \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" + 
                "        \"tca.aai.username\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" + 
                "        \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" + 
                "        \"tca.aai.enable_enrichment\": true,\r\n" + 
                "        \"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" + 
                "        \"tca.processing_batch_size\": 10000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" + 
                "        \"service_calls\": [],\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" + 
                "    }\r\n" + 
                "}";

        String parseConfig = "{\r\n" + 
                "    \"config\": {\r\n" + 
                "        \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" + 
                "        \"streams_subscribes\": {\r\n" + 
                "            \"tca_handle_in\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"tca.enable_ecomp_logging\": true,\r\n" + 
                "        \"tca.enable_abatement\": true,\r\n" + 
                "        \"tca.aai.password\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" + 
                "        \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" + 
                "        \"streams_publishes\": {\r\n" + 
                "            \"tca_handle_out\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" + 
                "        \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" + 
                "        \"tca.aai.username\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" + 
                "        \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" + 
                "        \"tca.aai.enable_enrichment\": true,\r\n" + 
                "        \"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" + 
                "        \"tca.processing_batch_size\": 10000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" + 
                "        \"service_calls\": [],\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" + 
                "    }\r\n" + 
                "}"; 
        JsonParser parser = new JsonParser();
        JsonObject json = parser.parse(strConfig).getAsJsonObject();
        JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject();

        Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles);

        Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json));
        Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
        testObject.postProcessEnvironment(configurableEnvironment, springApplication);
        assertEquals(ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(strConfig), ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(testObject.parseTcaConfig(parseJson)));
    }

    @Test
    void postProcessEnvironmentWithPolicy() {
        CbsClient cbsClient = Mockito.mock(CbsClient.class);
        ConfigBindingServiceEnvironmentPostProcessor testObject = Mockito.spy(new ConfigBindingServiceEnvironmentPostProcessor());
        ConfigurableEnvironment configurableEnvironment = Mockito.mock(ConfigurableEnvironment.class);
        SpringApplication springApplication = Mockito.mock(SpringApplication.class);
        String[] activeProfiles = {AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME};
        Map<String, Object> filterKeyMap = Mockito.mock(Map.class);
        String configServicePropertiesKey = "config-binding-service";
        MutablePropertySources sources = configurableEnvironment.getPropertySources();

        String parseConfig =  "{\r\n" + 
                "    \"config\": {\r\n" + 
                "        \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" + 
                "        \"streams_subscribes\": {\r\n" + 
                "            \"tca_handle_in\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT/\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"tca.enable_ecomp_logging\": true,\r\n" + 
                "        \"tca.enable_abatement\": true,\r\n" + 
                "        \"tca.aai.password\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" + 
                "        \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" + 
                "        \"streams_publishes\": {\r\n" + 
                "            \"tca_handle_out\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router:3904/events/unauthenticated.TCAGEN2_OUTPUT/\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" + 
                "        \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" + 
                "        \"tca.aai.username\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" + 
                "        \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" + 
                "        \"tca.aai.enable_enrichment\": true,\r\n" + 
                "        \"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" + 
                "        \"tca.processing_batch_size\": 10000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" + 
                "        \"service_calls\": [],\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" + 
                "    },\r\n" + 
                "    \"policies\": {\r\n" + 
                "        \"event\": {},\r\n" + 
                "        \"items\": [{\r\n" + 
                "            \"tca.policy\": {\r\n" + 
                "                \"domain\": \"measurementsForVfScaling\",\r\n" + 
                "                \"metricsPerEventName\": [{\r\n" + 
                "                    \"policyName\": \"onap.vfirewall.tca\",\r\n" + 
                "                    \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" + 
                "                    \"thresholds\": [{\r\n" + 
                "                        \"direction\": \"LESS_OR_EQUAL\",\r\n" + 
                "                        \"severity\": \"MAJOR\",\r\n" + 
                "                        \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
                "                        \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
                "                        \"version\": \"1.0.2\",\r\n" + 
                "                        \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
                "                        \"thresholdValue\": 500\r\n" + 
                "                    }, {\r\n" + 
                "                        \"direction\": \"GREATER_OR_EQUAL\",\r\n" + 
                "                        \"severity\": \"CRITICAL\",\r\n" + 
                "                        \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
                "                        \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
                "                        \"version\": \"1.0.2\",\r\n" + 
                "                        \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
                "                        \"thresholdValue\": 5000\r\n" + 
                "                    }],\r\n" + 
                "                    \"eventName\": \"vLoadBalancer\",\r\n" + 
                "                    \"controlLoopSchemaType\": \"VNF\",\r\n" + 
                "                    \"policyVersion\": \"v0.0.1\"\r\n" + 
                "                }]\r\n" + 
                "            }\r\n" + 
                "        }]\r\n" + 
                "    }\r\n" + 
                "}";

        String strConfig = "{\r\n" + 
                "    \"config\": {\r\n" + 
                "        \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" + 
                "        \"streams_subscribes\": {\r\n" + 
                "            \"tca_handle_in\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT/\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"tca.enable_ecomp_logging\": true,\r\n" + 
                "        \"tca.enable_abatement\": true,\r\n" + 
                "        \"tca.aai.password\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" + 
                "        \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" + 
                "        \"streams_publishes\": {\r\n" + 
                "            \"tca_handle_out\": {\r\n" + 
                "                \"type\": \"message_router\",\r\n" + 
                "                \"dmaap_info\": {\r\n" + 
                "                    \"topic_url\": \"http://message-router:3904/events/unauthenticated.TCAGEN2_OUTPUT/\"\r\n" + 
                "                }\r\n" + 
                "            }\r\n" + 
                "        },\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" + 
                "        \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" + 
                "        \"tca.aai.username\": \"DCAE\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" + 
                "        \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" + 
                "        \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" + 
                "        \"tca.aai.enable_enrichment\": true,\r\n" + 
                "        \"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" + 
                "        \"tca.processing_batch_size\": 10000,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" + 
                "        \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" + 
                "        \"service_calls\": [],\r\n" + 
                "        \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" + 
                "    },\r\n" + 
                "    \"policies\": {\r\n" + 
                "        \"event\": {},\r\n" + 
                "        \"items\": [{\r\n" + 
                "            \"tca.policy\": {\r\n" + 
                "                \"domain\": \"measurementsForVfScaling\",\r\n" + 
                "                \"metricsPerEventName\": [{\r\n" + 
                "                    \"policyName\": \"onap.vfirewall.tca\",\r\n" + 
                "                    \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" + 
                "                    \"thresholds\": [{\r\n" + 
                "                        \"direction\": \"LESS_OR_EQUAL\",\r\n" + 
                "                        \"severity\": \"MAJOR\",\r\n" + 
                "                        \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
                "                        \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
                "                        \"version\": \"1.0.2\",\r\n" + 
                "                        \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
                "                        \"thresholdValue\": 500\r\n" + 
                "                    }, {\r\n" + 
                "                        \"direction\": \"GREATER_OR_EQUAL\",\r\n" + 
                "                        \"severity\": \"CRITICAL\",\r\n" + 
                "                        \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
                "                        \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
                "                        \"version\": \"1.0.2\",\r\n" + 
                "                        \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
                "                        \"thresholdValue\": 5000\r\n" + 
                "                    }],\r\n" + 
                "                    \"eventName\": \"vLoadBalancer\",\r\n" + 
                "                    \"controlLoopSchemaType\": \"VNF\",\r\n" + 
                "                    \"policyVersion\": \"v0.0.1\"\r\n" + 
                "                }]\r\n" + 
                "            }\r\n" + 
                "        }]\r\n" + 
                "    }\r\n" + 
                "}"; 
        JsonParser parser = new JsonParser();
        JsonObject json = parser.parse(strConfig).getAsJsonObject();
        JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject();

        Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles);

        Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json));
        Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
        testObject.postProcessEnvironment(configurableEnvironment, springApplication);
        assertEquals(ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(strConfig), ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(testObject.parseTcaConfig(parseJson)));
    }

    public static String replaceBlank(String str) {
		String dest = "";
		if (str!=null) {
			Pattern p = Pattern.compile("\\s*|\t|\r|\n");
			Matcher m = p.matcher(str);
			dest = m.replaceAll("");
		}
		return dest;
	}
}