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 | |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 33 | it('getOperationalPolicies', () => { |
| 34 | const opPolicy = [{ |
| 35 | "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", |
| 36 | "configurationsJson": { |
| 37 | "guard_policies": {}, |
| 38 | "operational_policy": { |
| 39 | "controlLoop": {}, |
| 40 | "policies": [] |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 41 | } |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 42 | }, |
| 43 | "jsonRepresentation": { |
| 44 | "schema": {} |
| 45 | } |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 46 | }]; |
| 47 | expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy); |
| 48 | }); |
| 49 | |
xuegao | c488fed | 2019-12-19 11:58:45 +0100 | [diff] [blame] | 50 | it('getOperationalPoliciesNoJsonSchema', () => { |
| 51 | const opPolicy = [{ |
| 52 | "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", |
| 53 | "configurationsJson": { |
| 54 | "guard_policies": {}, |
| 55 | "operational_policy": { |
| 56 | "controlLoop": {}, |
| 57 | "policies": [] |
| 58 | } |
| 59 | } |
| 60 | }]; |
| 61 | expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy); |
| 62 | }); |
| 63 | |
| 64 | it('getOperationalPolicyJsonSchema', () => { |
| 65 | const jsonSchema = { |
| 66 | "schema": {} |
| 67 | }; |
| 68 | |
| 69 | expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema); |
| 70 | }); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 71 | it('getGlobalProperties', () => { |
| 72 | const globelProp = { |
| 73 | "dcaeDeployParameters": { |
| 74 | "location_id": "", |
| 75 | "service_id": "", |
| 76 | "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" |
| 77 | } |
| 78 | }; |
| 79 | expect(loopCache.getGlobalProperties()).toStrictEqual(globelProp); |
| 80 | }); |
| 81 | |
| 82 | it('getDcaeDeploymentProperties', () => { |
| 83 | const deploymentProp = { |
| 84 | "location_id": "", |
| 85 | "service_id": "", |
| 86 | "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca" |
| 87 | }; |
| 88 | expect(loopCache.getDcaeDeploymentProperties()).toStrictEqual(deploymentProp); |
| 89 | }); |
| 90 | |
TedHumphrey | 4aedf73 | 2019-08-13 15:56:33 +0000 | [diff] [blame] | 91 | it('getMicroServiceForName', () => { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 92 | const msJson = { |
| 93 | "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca", |
| 94 | "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app", |
sebdet | 58135b8 | 2020-02-27 11:39:50 -0800 | [diff] [blame] | 95 | "configurationsJson": {"domain": "measurementsForVfScaling"}, |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 96 | "shared": false, |
| 97 | "jsonRepresentation": {"schema": {}} |
| 98 | }; |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 99 | expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson); |
| 100 | expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull(); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 101 | }); |
| 102 | |
TedHumphrey | 4aedf73 | 2019-08-13 15:56:33 +0000 | [diff] [blame] | 103 | it('getMicroServicePropertiesForName', () => { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 104 | const msProp = {"domain": "measurementsForVfScaling"}; |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 105 | expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp); |
| 106 | expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull(); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 107 | }); |
| 108 | |
TedHumphrey | 4aedf73 | 2019-08-13 15:56:33 +0000 | [diff] [blame] | 109 | it('getMicroServiceJsonRepresentationForName', () => { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 110 | const msJsonRepresentation = {"schema": {}}; |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 111 | expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 112 | }); |
| 113 | |
| 114 | it('getResourceDetailsVfProperty', () => { |
| 115 | const resourceVF = { |
| 116 | "vLoadBalancerMS 0": { |
| 117 | "resourceVendor": "Test", |
| 118 | "resourceVendorModelNumber": "", |
| 119 | "name": "vLoadBalancerMS", |
| 120 | "description": "vLBMS", |
| 121 | "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506", |
| 122 | "subcategory": "Load Balancer", |
| 123 | "category": "Application L4+", |
| 124 | "type": "VF", |
| 125 | "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6", |
| 126 | "version": "1.0", |
| 127 | "resourceVendorRelease": "1.0", |
| 128 | "customizationUUID": "465246dc-7748-45f4-a013-308d92922552" |
| 129 | } |
| 130 | }; |
| 131 | expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF); |
| 132 | }); |
| 133 | |
| 134 | it('getResourceDetailsVfModuleProperty', () => { |
| 135 | const vfModule = { |
| 136 | "Vloadbalancerms..vpkg..module-1": { |
| 137 | "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043", |
| 138 | "vfModuleModelVersion": "1", |
| 139 | "vfModuleModelName": "Vloadbalancerms..vpkg..module-1", |
| 140 | "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc", |
| 141 | "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52", |
| 142 | "min_vf_module_instances": 0, |
| 143 | "vf_module_label": "vpkg", |
| 144 | "max_vf_module_instances": 1, |
| 145 | "vf_module_type": "Expansion", |
| 146 | "isBase": false, |
| 147 | "initial_count": 0, |
| 148 | "volume_group": false |
| 149 | } |
| 150 | }; |
| 151 | expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule); |
| 152 | }); |
| 153 | |
| 154 | it('getLoopLogsArray', () => { |
| 155 | const logs = [ |
| 156 | { |
| 157 | "id": 1, |
| 158 | "logType": "INFO", |
| 159 | "logComponent": "CLAMP", |
| 160 | "message": "Operational and Guard policies UPDATED", |
| 161 | "logInstant": "2019-07-08T09:44:37Z" |
| 162 | } |
| 163 | ]; |
| 164 | expect(loopCache.getLoopLogsArray()).toStrictEqual(logs); |
| 165 | }); |
| 166 | |
| 167 | it('getComponentStates', () => { |
| 168 | const component = { |
| 169 | "POLICY": { |
| 170 | "componentState": { |
| 171 | "stateName": "NOT_SENT", |
| 172 | "description": "The policies defined have NOT yet been created on the policy engine" |
| 173 | } |
| 174 | }, |
| 175 | "DCAE": { |
| 176 | "componentState": { |
| 177 | "stateName": "BLUEPRINT_DEPLOYED", |
| 178 | "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop" |
| 179 | } |
| 180 | } |
| 181 | }; |
| 182 | expect(loopCache.getComponentStates()).toStrictEqual(component); |
| 183 | }); |
| 184 | |
| 185 | it('updateGlobalProperties', () => { |
| 186 | const newGlobalProps = { |
| 187 | "dcaeDeployParameters": { |
| 188 | "location_id": "newLocation", |
| 189 | "service_id": "newServiceId", |
| 190 | "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2" |
| 191 | } |
| 192 | }; |
| 193 | loopCache.updateGlobalProperties(newGlobalProps); |
| 194 | expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps); |
| 195 | }); |
| 196 | |
| 197 | it('updateOperationalPolicyProperties', () => { |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 198 | const newOpPolicy = { |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 199 | "guard_policies": {}, |
| 200 | "operational_policy": { |
| 201 | "controlLoop": {}, |
| 202 | "policies": [] |
| 203 | } |
xuegao | 635445a | 2020-03-02 11:37:20 +0100 | [diff] [blame] | 204 | }; |
| 205 | loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy); |
| 206 | expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 207 | }); |
| 208 | |
| 209 | it('updateMicroServiceProperties', () => { |
sebdet | b65f121 | 2019-08-23 07:49:25 -0700 | [diff] [blame] | 210 | const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"}; |
| 211 | loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties); |
| 212 | expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties); |
xuegao | d8bed32 | 2019-07-18 17:45:34 +0200 | [diff] [blame] | 213 | }); |
| 214 | }); |