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                 "                \"config\": {\r\n" + 
 
 223                 "                    \"tca.policy\": {\r\n" + 
 
 224                 "                        \"domain\": \"measurementsForVfScaling\",\r\n" + 
 
 225                 "                        \"metricsPerEventName\": [{\r\n" + 
 
 226                 "                            \"policyName\": \"onap.vfirewall.tca\",\r\n" + 
 
 227                 "                            \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" + 
 
 228                 "                            \"thresholds\": [{\r\n" + 
 
 229                 "                                \"direction\": \"LESS_OR_EQUAL\",\r\n" + 
 
 230                 "                                \"severity\": \"MAJOR\",\r\n" + 
 
 231                 "                                \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
 
 232                 "                                \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
 
 233                 "                                \"version\": \"1.0.2\",\r\n" + 
 
 234                 "                                \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
 
 235                 "                                \"thresholdValue\": 500\r\n" + 
 
 237                 "                                \"direction\": \"GREATER_OR_EQUAL\",\r\n" + 
 
 238                 "                                \"severity\": \"CRITICAL\",\r\n" + 
 
 239                 "                                \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
 
 240                 "                                \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
 
 241                 "                                \"version\": \"1.0.2\",\r\n" + 
 
 242                 "                                \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
 
 243                 "                                \"thresholdValue\": 5000\r\n" + 
 
 245                 "                            \"eventName\": \"vLoadBalancer\",\r\n" + 
 
 246                 "                            \"controlLoopSchemaType\": \"VNF\",\r\n" + 
 
 247                 "                            \"policyVersion\": \"v0.0.1\"\r\n" + 
 
 251                 "                \"type_version\": \"1.0.0\",\r\n" + 
 
 252                 "                \"version\": \"1.0.0\",\r\n" + 
 
 253                 "                \"policyVersion\": \"1.0.0\",\r\n" + 
 
 254                 "                \"type\": \"onap.policies.monitoring.cdap.tca.hi.lo.app\",\r\n" + 
 
 255                 "                \"metadata\": {\r\n" + 
 
 256                 "                    \"policy-id\": \"onap.vfirewall.tca\",\r\n" + 
 
 257                 "                    \"policy-version\": \"1.0.0\"\r\n" + 
 
 264         String strConfig = "{\r\n" + 
 
 265                 "    \"config\": {\r\n" + 
 
 266                 "        \"spring.data.mongodb.uri\": \"mongodb://dcae-mongohost/dcae-tcagen2\",\r\n" + 
 
 267                 "        \"streams_subscribes\": {\r\n" + 
 
 268                 "            \"tca_handle_in\": {\r\n" + 
 
 269                 "                \"type\": \"message_router\",\r\n" + 
 
 270                 "                \"dmaap_info\": {\r\n" + 
 
 271                 "                    \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.VES_MEASUREMENT_OUTPUT\"\r\n" + 
 
 275                 "        \"tca.enable_ecomp_logging\": true,\r\n" + 
 
 276                 "        \"tca.enable_abatement\": true,\r\n" + 
 
 277                 "        \"tca.aai.password\": \"DCAE\",\r\n" + 
 
 278                 "        \"streams_subscribes.tca_handle_in.consumer_group\": \"cg1\",\r\n" + 
 
 279                 "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up\": 10000,\r\n" + 
 
 280                 "        \"tca.aai.node_query_path\": \"aai/v11/search/nodes-query\",\r\n" + 
 
 281                 "        \"streams_publishes\": {\r\n" + 
 
 282                 "            \"tca_handle_out\": {\r\n" + 
 
 283                 "                \"type\": \"message_router\",\r\n" + 
 
 284                 "                \"dmaap_info\": {\r\n" + 
 
 285                 "                    \"topic_url\": \"http://message-router.onap.svc.cluster.local:3904/events/unauthenticated.TCAGEN2-OUTPUT\"\r\n" + 
 
 289                 "        \"streams_subscribes.tca_handle_in.consumer_ids[1]\": \"c1\",\r\n" + 
 
 290                 "        \"tca.aai.generic_vnf_path\": \"aai/v11/network/generic-vnfs/generic-vnf\",\r\n" + 
 
 291                 "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down\": 30000,\r\n" + 
 
 292                 "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.max\": 60000,\r\n" + 
 
 293                 "        \"tca.aai.username\": \"DCAE\",\r\n" + 
 
 294                 "        \"streams_subscribes.tca_handle_in.polling.auto_adjusting.min\": 30000,\r\n" + 
 
 295                 "        \"tca.aai.url\": \"http://aai.onap.svc.cluster.local\",\r\n" + 
 
 296                 "        \"streams_subscribes.tca_handle_in.timeout\": -1,\r\n" + 
 
 297                 "        \"tca.aai.enable_enrichment\": true,\r\n" + 
 
 298                 "        \"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" + 
 
 299                 "        \"tca.processing_batch_size\": 10000,\r\n" + 
 
 300                 "        \"streams_subscribes.tca_handle_in.polling.fixed_rate\": 0,\r\n" + 
 
 301                 "        \"streams_subscribes.tca_handle_in.message_limit\": 50000,\r\n" + 
 
 302                 "        \"service_calls\": [],\r\n" + 
 
 303                 "        \"streams_subscribes.tca_handle_in.consumer_ids[0]\": \"c0\"\r\n" + 
 
 305                 "    \"policies\": {\r\n" + 
 
 306                 "        \"event\": {\r\n" + 
 
 307                 "            \"action\": \"gathered\",\r\n" + 
 
 308                 "            \"timestamp\": \"2020-04-08T19:45:38.927Z\",\r\n" + 
 
 309                 "            \"update_id\": \"d86a3b58-8c4b-49e9-ade7-8238501adf02\",\r\n" + 
 
 310                 "            \"policies_count\": 1\r\n" + 
 
 312                 "        \"items\": [{\r\n" + 
 
 313                 "            \"policyName\": \"onap.vfirewall.tca.1-0-0.xml\",\r\n" + 
 
 314                 "            \"name\": \"onap.vfirewall.tca\",\r\n" + 
 
 315                 "            \"config\": {\r\n" + 
 
 316                 "                \"tca.policy\": {\r\n" + 
 
 317                 "                    \"domain\": \"measurementsForVfScaling\",\r\n" + 
 
 318                 "                    \"metricsPerEventName\": [{\r\n" + 
 
 319                 "                        \"policyName\": \"onap.vfirewall.tca\",\r\n" + 
 
 320                 "                        \"policyScope\": \"resource=vLoadBalancer;type=configuration\",\r\n" + 
 
 321                 "                        \"thresholds\": [{\r\n" + 
 
 322                 "                            \"direction\": \"LESS_OR_EQUAL\",\r\n" + 
 
 323                 "                            \"severity\": \"MAJOR\",\r\n" + 
 
 324                 "                            \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
 
 325                 "                            \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
 
 326                 "                            \"version\": \"1.0.2\",\r\n" + 
 
 327                 "                            \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
 
 328                 "                            \"thresholdValue\": 500\r\n" + 
 
 330                 "                            \"direction\": \"GREATER_OR_EQUAL\",\r\n" + 
 
 331                 "                            \"severity\": \"CRITICAL\",\r\n" + 
 
 332                 "                            \"closedLoopControlName\": \"VVK_ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a\",\r\n" + 
 
 333                 "                            \"fieldPath\": \"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\r\n" + 
 
 334                 "                            \"version\": \"1.0.2\",\r\n" + 
 
 335                 "                            \"closedLoopEventStatus\": \"ONSET\",\r\n" + 
 
 336                 "                            \"thresholdValue\": 5000\r\n" + 
 
 338                 "                        \"eventName\": \"vLoadBalancer\",\r\n" + 
 
 339                 "                        \"controlLoopSchemaType\": \"VNF\",\r\n" + 
 
 340                 "                        \"policyVersion\": \"v0.0.1\"\r\n" + 
 
 344                 "            \"type_version\": \"1.0.0\",\r\n" + 
 
 345                 "            \"version\": \"1.0.0\",\r\n" + 
 
 346                 "            \"policyVersion\": \"1.0.0\",\r\n" + 
 
 347                 "            \"type\": \"onap.policies.monitoring.cdap.tca.hi.lo.app\",\r\n" + 
 
 348                 "            \"metadata\": {\r\n" + 
 
 349                 "                \"policy-id\": \"onap.vfirewall.tca\",\r\n" + 
 
 350                 "                \"policy-version\": \"1.0.0\"\r\n" + 
 
 355         JsonParser parser = new JsonParser();
 
 356         JsonObject json = parser.parse(strConfig).getAsJsonObject();
 
 357         JsonObject parseJson = parser.parse(parseConfig).getAsJsonObject();
 
 359         Mockito.when(configurableEnvironment.getActiveProfiles()).thenReturn(activeProfiles);
 
 361         Mockito.when(testObject.periodicConfigurationUpdates(cbsClient)).thenReturn(Flux.just(json));
 
 362         Mockito.doNothing().when(testObject).addJsonPropertySource(sources, new MapPropertySource(configServicePropertiesKey, filterKeyMap));
 
 363         testObject.postProcessEnvironment(configurableEnvironment, springApplication);
 
 364         assertEquals(ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(strConfig), ConfigBindingServiceEnvironmentPostProcessorTest.replaceBlank(testObject.parseTcaConfig(parseJson)));
 
 367     public static String replaceBlank(String str) {
 
 370                         Pattern p = Pattern.compile("\\s*|\t|\r|\n");
 
 371                         Matcher m = p.matcher(str);
 
 372                         dest = m.replaceAll("");