xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * ONAP CLAMP |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2019 AT&T Intellectual Property. All rights |
| 6 | * reserved. |
| 7 | * ================================================================================ |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | * ============LICENSE_END============================================ |
| 20 | * =================================================================== |
| 21 | * |
| 22 | */ |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 23 | import LoopCache from '../api/LoopCache'; |
| 24 | |
| 25 | const json = require('./LoopCache_mokeLoopJsonCache.json'); |
| 26 | |
| 27 | describe('Verify LoopCache functions', () => { |
| 28 | const loopCache = new LoopCache(json); |
| 29 | it('getLoopName', () => { |
| 30 | expect(loopCache.getLoopName()).toBe("LOOP_Jbv1z_v1_0_ResourceInstanceName1_tca"); |
| 31 | }); |
| 32 | |
| 33 | it('getOperationalPolicyConfigurationJson', () => { |
| 34 | const opPolicyConfig = { |
| 35 | "guard_policies": {}, |
| 36 | "operational_policy": { |
| 37 | "controlLoop": {}, |
| 38 | "policies": [] |
| 39 | } |
| 40 | }; |
| 41 | expect(loopCache.getOperationalPolicyConfigurationJson()).toStrictEqual(opPolicyConfig); |
| 42 | }); |
| 43 | |
| 44 | it('getOperationalPolicies', () => { |
| 45 | const opPolicy = [{ |
| 46 | "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", |
| 47 | "configurationsJson": { |
| 48 | "guard_policies": {}, |
| 49 | "operational_policy": { |
| 50 | "controlLoop": {}, |
| 51 | "policies": [] |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 52 | } |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 53 | }, |
| 54 | "jsonRepresentation": { |
| 55 | "schema": {} |
| 56 | } |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 57 | }]; |
| 58 | expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy); |
| 59 | }); |
| 60 | |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 61 | it('getOperationalPoliciesNoJsonSchema', () => { |
| 62 | const opPolicy = [{ |
| 63 | "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", |
| 64 | "configurationsJson": { |
| 65 | "guard_policies": {}, |
| 66 | "operational_policy": { |
| 67 | "controlLoop": {}, |
| 68 | "policies": [] |
| 69 | } |
| 70 | } |
| 71 | }]; |
| 72 | expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy); |
| 73 | }); |
| 74 | |
| 75 | it('getOperationalPolicyJsonSchema', () => { |
| 76 | const jsonSchema = { |
| 77 | "schema": {} |
| 78 | }; |
| 79 | |
| 80 | expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema); |
| 81 | }); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 82 | it('getGlobalProperties', () => { |
| 83 | const globelProp = { |
| 84 | "dcaeDeployParameters": { |
| 85 | "location_id": "", |
| 86 | "service_id": "", |
| 87 | "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" |
| 88 | } |
| 89 | }; |
| 90 | expect(loopCache.getGlobalProperties()).toStrictEqual(globelProp); |
| 91 | }); |
| 92 | |
| 93 | it('getDcaeDeploymentProperties', () => { |
| 94 | const deploymentProp = { |
| 95 | "location_id": "", |
| 96 | "service_id": "", |
| 97 | "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" |
| 98 | }; |
| 99 | expect(loopCache.getDcaeDeploymentProperties()).toStrictEqual(deploymentProp); |
| 100 | }); |
| 101 | |
TedHumphrey | 4aedf73 | 2019-08-13 15:56:33 +0000 | [diff] [blame] | 102 | it('getMicroServiceForName', () => { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 103 | const msJson = { |
| 104 | "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca", |
| 105 | "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app", |
sebdet | 58135b8 | 2020-02-27 11:39:50 -0800 | [diff] [blame^] | 106 | "configurationsJson": {"domain": "measurementsForVfScaling"}, |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 107 | "shared": false, |
| 108 | "jsonRepresentation": {"schema": {}} |
| 109 | }; |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 110 | expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson); |
| 111 | expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull(); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 112 | }); |
| 113 | |
TedHumphrey | 4aedf73 | 2019-08-13 15:56:33 +0000 | [diff] [blame] | 114 | it('getMicroServicePropertiesForName', () => { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 115 | const msProp = {"domain": "measurementsForVfScaling"}; |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 116 | expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp); |
| 117 | expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull(); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 118 | }); |
| 119 | |
TedHumphrey | 4aedf73 | 2019-08-13 15:56:33 +0000 | [diff] [blame] | 120 | it('getMicroServiceJsonRepresentationForName', () => { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 121 | const msJsonRepresentation = {"schema": {}}; |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 122 | expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 123 | }); |
| 124 | |
| 125 | it('getResourceDetailsVfProperty', () => { |
| 126 | const resourceVF = { |
| 127 | "vLoadBalancerMS 0": { |
| 128 | "resourceVendor": "Test", |
| 129 | "resourceVendorModelNumber": "", |
| 130 | "name": "vLoadBalancerMS", |
| 131 | "description": "vLBMS", |
| 132 | "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506", |
| 133 | "subcategory": "Load Balancer", |
| 134 | "category": "Application L4+", |
| 135 | "type": "VF", |
| 136 | "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6", |
| 137 | "version": "1.0", |
| 138 | "resourceVendorRelease": "1.0", |
| 139 | "customizationUUID": "465246dc-7748-45f4-a013-308d92922552" |
| 140 | } |
| 141 | }; |
| 142 | expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF); |
| 143 | }); |
| 144 | |
| 145 | it('getResourceDetailsVfModuleProperty', () => { |
| 146 | const vfModule = { |
| 147 | "Vloadbalancerms..vpkg..module-1": { |
| 148 | "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043", |
| 149 | "vfModuleModelVersion": "1", |
| 150 | "vfModuleModelName": "Vloadbalancerms..vpkg..module-1", |
| 151 | "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc", |
| 152 | "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52", |
| 153 | "min_vf_module_instances": 0, |
| 154 | "vf_module_label": "vpkg", |
| 155 | "max_vf_module_instances": 1, |
| 156 | "vf_module_type": "Expansion", |
| 157 | "isBase": false, |
| 158 | "initial_count": 0, |
| 159 | "volume_group": false |
| 160 | } |
| 161 | }; |
| 162 | expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule); |
| 163 | }); |
| 164 | |
| 165 | it('getLoopLogsArray', () => { |
| 166 | const logs = [ |
| 167 | { |
| 168 | "id": 1, |
| 169 | "logType": "INFO", |
| 170 | "logComponent": "CLAMP", |
| 171 | "message": "Operational and Guard policies UPDATED", |
| 172 | "logInstant": "2019-07-08T09:44:37Z" |
| 173 | } |
| 174 | ]; |
| 175 | expect(loopCache.getLoopLogsArray()).toStrictEqual(logs); |
| 176 | }); |
| 177 | |
| 178 | it('getComponentStates', () => { |
| 179 | const component = { |
| 180 | "POLICY": { |
| 181 | "componentState": { |
| 182 | "stateName": "NOT_SENT", |
| 183 | "description": "The policies defined have NOT yet been created on the policy engine" |
| 184 | } |
| 185 | }, |
| 186 | "DCAE": { |
| 187 | "componentState": { |
| 188 | "stateName": "BLUEPRINT_DEPLOYED", |
| 189 | "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop" |
| 190 | } |
| 191 | } |
| 192 | }; |
| 193 | expect(loopCache.getComponentStates()).toStrictEqual(component); |
| 194 | }); |
| 195 | |
| 196 | it('updateGlobalProperties', () => { |
| 197 | const newGlobalProps = { |
| 198 | "dcaeDeployParameters": { |
| 199 | "location_id": "newLocation", |
| 200 | "service_id": "newServiceId", |
| 201 | "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2" |
| 202 | } |
| 203 | }; |
| 204 | loopCache.updateGlobalProperties(newGlobalProps); |
| 205 | expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps); |
| 206 | }); |
| 207 | |
| 208 | it('updateOperationalPolicyProperties', () => { |
| 209 | const newOpPolicy = [{ |
| 210 | "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca_new", |
| 211 | "configurationsJson": { |
| 212 | "guard_policies": {}, |
| 213 | "operational_policy": { |
| 214 | "controlLoop": {}, |
| 215 | "policies": [] |
| 216 | } |
| 217 | } |
| 218 | }]; |
| 219 | loopCache.updateOperationalPolicyProperties(newOpPolicy); |
| 220 | expect(loopCache.getOperationalPolicies()).toStrictEqual(newOpPolicy); |
| 221 | }); |
| 222 | |
| 223 | it('updateMicroServiceProperties', () => { |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 224 | const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"}; |
| 225 | loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties); |
| 226 | expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 227 | }); |
| 228 | }); |