diff options
Diffstat (limited to 'rest-services/cbs-client/src/test')
4 files changed, 283 insertions, 4 deletions
diff --git a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java index a9d8407b..aa5655fc 100644 --- a/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java +++ b/rest-services/cbs-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/impl/CbsClientConfigMapTest.java @@ -3,6 +3,7 @@ * DCAEGEN2-SERVICES-SDK * ========================================================= * Copyright (C) 2021 Nokia. All rights reserved. + * Copyright (C) 2021 Wipro Limited. * ========================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,25 +18,31 @@ * limitations under the License. * ============LICENSE_END===================================== */ + package org.onap.dcaegen2.services.sdk.rest.services.cbs.client.impl; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.stream.JsonReader; + +import java.io.FileNotFoundException; +import java.io.FileReader; + import org.junit.Rule; import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsClient; import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.api.CbsRequests; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; -import java.io.FileNotFoundException; -import java.io.FileReader; -import static org.assertj.core.api.Assertions.assertThat; public class CbsClientConfigMapTest { private static final String SAMPLE_EXPECTED_CONFIG = "src/test/resources/sample_expected_service_config.json"; + private static final String SAMPLE_EXPECTED_POLICY_CONFIG = "src/test/resources/sample_expected_policy_config.json"; + private static final String SAMPLE_EXPECTED_ALL_CONFIG = "src/test/resources/sample_expected_all_config.json"; @Rule public final EnvironmentVariables envs = new EnvironmentVariables(); @@ -45,7 +52,9 @@ public class CbsClientConfigMapTest { envs.set("AAF_USER", "admin"); envs.set("AAF_PASSWORD", "admin_secret"); String configMapFilePath = "src/test/resources/application_config.yaml"; - final CbsClient cut = new CbsClientConfigMap(configMapFilePath); + String policySyncFilePath = "src/test/resources/policies.json"; + String requestPath = "/service_component/app-name"; + final CbsClient cut = new CbsClientConfigMap(configMapFilePath, policySyncFilePath, requestPath); RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); @@ -57,8 +66,49 @@ public class CbsClientConfigMapTest { assertThat(result).isEqualTo(convertToJson(new JsonReader(new FileReader(SAMPLE_EXPECTED_CONFIG)))); } + @Test + void shouldFetchUsingConfigMapFileAndPolicySyncFile() throws FileNotFoundException { + // given + envs.set("AAF_USER", "admin"); + envs.set("AAF_PASSWORD", "admin_secret"); + String configMapFilePath = "src/test/resources/application_config.yaml"; + String policySyncFilePath = "src/test/resources/policies.json"; + String requestPath = "/service_component_all/app-name"; + final CbsClient cut = new CbsClientConfigMap(configMapFilePath, policySyncFilePath, requestPath); + + RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + + // when + final JsonObject result = cut.get(CbsRequests.getConfiguration(diagnosticContext)).block(); + + // then + assertThat(result).isNotNull(); + assertThat(result).isEqualTo(convertToJson(new JsonReader(new FileReader(SAMPLE_EXPECTED_POLICY_CONFIG)))); + } + + @Test + void shouldFetchUsingConfigMapFileWhenPolicySyncFileAbsent() throws FileNotFoundException { + // given + envs.set("AAF_USER", "admin"); + envs.set("AAF_PASSWORD", "admin_secret"); + String configMapFilePath = "src/test/resources/application_config.yaml"; + String policySyncFilePath = ""; + String requestPath = "/service_component_all/app-name"; + final CbsClient cut = new CbsClientConfigMap(configMapFilePath, policySyncFilePath, requestPath); + + RequestDiagnosticContext diagnosticContext = RequestDiagnosticContext.create(); + + // when + final JsonObject result = cut.get(CbsRequests.getConfiguration(diagnosticContext)).block(); + + // then + assertThat(result).isNotNull(); + assertThat(result).isEqualTo(convertToJson(new JsonReader(new FileReader(SAMPLE_EXPECTED_ALL_CONFIG)))); + } + private JsonObject convertToJson(JsonReader jsonReader) { Gson gson = new GsonBuilder().create(); return gson.fromJson(jsonReader, JsonObject.class); } } + diff --git a/rest-services/cbs-client/src/test/resources/policies.json b/rest-services/cbs-client/src/test/resources/policies.json new file mode 100644 index 00000000..657cdbe9 --- /dev/null +++ b/rest-services/cbs-client/src/test/resources/policies.json @@ -0,0 +1,58 @@ +{ + "policies":{ + "items":[ + { + "type":"onap.policies.monitoring.tcagen2", + "type_version":"1.0.0", + "name":"onap.vfirewall.tca", + "version":"1.0.0", + "metadata":{ + "policy-id":"onap.vfirewall.tca", + "policy-version":"1.0.0" + }, + "policyName":"onap.vfirewall.tca.1-0-0.xml", + "policyVersion":"1.0.0", + "config":{ + "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" + } + ] + } + ] + } + } + } + ] + }, + "event":{ + "action":"gathered", + "timestamp":"2021-04-19T23:37:19.709Z", + "update_id":"379fb01a-cfe2-4c06-8f6b-d51f3c8504af", + "policies_count":1 + } +} diff --git a/rest-services/cbs-client/src/test/resources/sample_expected_all_config.json b/rest-services/cbs-client/src/test/resources/sample_expected_all_config.json new file mode 100644 index 00000000..641c4817 --- /dev/null +++ b/rest-services/cbs-client/src/test/resources/sample_expected_all_config.json @@ -0,0 +1,54 @@ +{ + "config": { + "keystore.path": "/var/run/security/keystore.p12", + "streams_publishes": { + "perf3gpp": { + "testArray": [ + { + "testPrimitiveArray": ["admin", "admin_secret", {"nestedArray": ["admin"]}], + "testPrimitive": "admin", + "aaf_credentials": { + "username": "admin", + "password": "admin_secret" + } + } + ], + "type": "kafka", + "kafka_info": { + "bootstrap_servers": "dmaap-mr-kafka:6060", + "topic_name": "HVVES_PERF3GPP" + } + }, + "pnf_ready": { + "aaf_credentials": { + "username": "admin", + "password": "admin_secret" + }, + "type": "message_router", + "dmaap_info": { + "topic_url": "http://message-router:3904/events/VES_PNF_READY" + } + }, + "call_trace": { + "aaf_credentials": { + "username": "admin", + "password": "admin_secret" + }, + "type": "kafka", + "kafka_info": { + "bootstrap_servers": "dmaap-mr-kafka:6060", + "topic_name": "HVVES_TRACE" + } + } + }, + "streams_subscribes": { + "measurements": { + "type": "message_router", + "dmaap_info": { + "topic_url": "http://message-router:3904/events/VES_MEASUREMENT" + } + } + } + } +} + diff --git a/rest-services/cbs-client/src/test/resources/sample_expected_policy_config.json b/rest-services/cbs-client/src/test/resources/sample_expected_policy_config.json new file mode 100644 index 00000000..aeb3ca32 --- /dev/null +++ b/rest-services/cbs-client/src/test/resources/sample_expected_policy_config.json @@ -0,0 +1,117 @@ +{ + "policies":{ + "items":[ + { + "type":"onap.policies.monitoring.tcagen2", + "type_version":"1.0.0", + "name":"onap.vfirewall.tca", + "version":"1.0.0", + "metadata":{ + "policy-id":"onap.vfirewall.tca", + "policy-version":"1.0.0" + }, + "policyName":"onap.vfirewall.tca.1-0-0.xml", + "policyVersion":"1.0.0", + "config":{ + "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" + } + ] + } + ] + } + } + } + ] + }, + "event":{ + "action":"gathered", + "timestamp":"2021-04-19T23:37:19.709Z", + "update_id":"379fb01a-cfe2-4c06-8f6b-d51f3c8504af", + "policies_count":1 + }, + "config":{ + "keystore.path":"/var/run/security/keystore.p12", + "streams_publishes":{ + "perf3gpp":{ + "testArray":[ + { + "testPrimitiveArray":[ + "admin", + "admin_secret", + { + "nestedArray":[ + "admin" + ] + } + ], + "testPrimitive":"admin", + "aaf_credentials":{ + "username":"admin", + "password":"admin_secret" + } + } + ], + "type":"kafka", + "kafka_info":{ + "bootstrap_servers":"dmaap-mr-kafka:6060", + "topic_name":"HVVES_PERF3GPP" + } + }, + "pnf_ready":{ + "aaf_credentials":{ + "username":"admin", + "password":"admin_secret" + }, + "type":"message_router", + "dmaap_info":{ + "topic_url":"http://message-router:3904/events/VES_PNF_READY" + } + }, + "call_trace":{ + "aaf_credentials":{ + "username":"admin", + "password":"admin_secret" + }, + "type":"kafka", + "kafka_info":{ + "bootstrap_servers":"dmaap-mr-kafka:6060", + "topic_name":"HVVES_TRACE" + } + } + }, + "streams_subscribes":{ + "measurements":{ + "type":"message_router", + "dmaap_info":{ + "topic_url":"http://message-router:3904/events/VES_MEASUREMENT" + } + } + } + } +} |