blob: b0eef755c2671ef03db3be593f5b0eb251153a9c [file] [log] [blame]
xuegaod8bed322019-07-18 17:45:34 +02001/*-
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 */
xuegaod8bed322019-07-18 17:45:34 +020023import LoopCache from '../api/LoopCache';
24
25const json = require('./LoopCache_mokeLoopJsonCache.json');
26
27describe('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
xuegaod8bed322019-07-18 17:45:34 +020033 it('getOperationalPolicies', () => {
34 const opPolicy = [{
35 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
36 "configurationsJson": {
xuegaod8bed322019-07-18 17:45:34 +020037 "operational_policy": {
38 "controlLoop": {},
39 "policies": []
xuegaod8bed322019-07-18 17:45:34 +020040 }
xuegaoc488fed2019-12-19 11:58:45 +010041 },
42 "jsonRepresentation": {
43 "schema": {}
44 }
xuegaod8bed322019-07-18 17:45:34 +020045 }];
46 expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy);
47 });
48
xuegaoc488fed2019-12-19 11:58:45 +010049 it('getOperationalPoliciesNoJsonSchema', () => {
50 const opPolicy = [{
51 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
52 "configurationsJson": {
xuegaoc488fed2019-12-19 11:58:45 +010053 "operational_policy": {
54 "controlLoop": {},
55 "policies": []
56 }
57 }
58 }];
59 expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy);
60 });
61
62 it('getOperationalPolicyJsonSchema', () => {
63 const jsonSchema = {
64 "schema": {}
65 };
66
67 expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema);
68 });
xuegaod8bed322019-07-18 17:45:34 +020069 it('getGlobalProperties', () => {
70 const globelProp = {
71 "dcaeDeployParameters": {
72 "location_id": "",
73 "service_id": "",
74 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
75 }
76 };
77 expect(loopCache.getGlobalProperties()).toStrictEqual(globelProp);
78 });
79
80 it('getDcaeDeploymentProperties', () => {
81 const deploymentProp = {
82 "location_id": "",
83 "service_id": "",
84 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
85 };
86 expect(loopCache.getDcaeDeploymentProperties()).toStrictEqual(deploymentProp);
87 });
88
TedHumphrey4aedf732019-08-13 15:56:33 +000089 it('getMicroServiceForName', () => {
xuegaod8bed322019-07-18 17:45:34 +020090 const msJson = {
91 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
92 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
sebdet58135b82020-02-27 11:39:50 -080093 "configurationsJson": {"domain": "measurementsForVfScaling"},
xuegaod8bed322019-07-18 17:45:34 +020094 "shared": false,
95 "jsonRepresentation": {"schema": {}}
96 };
sebdetb65f1212019-08-23 07:49:25 -070097 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
98 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +020099 });
100
TedHumphrey4aedf732019-08-13 15:56:33 +0000101 it('getMicroServicePropertiesForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200102 const msProp = {"domain": "measurementsForVfScaling"};
sebdetb65f1212019-08-23 07:49:25 -0700103 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
104 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200105 });
106
TedHumphrey4aedf732019-08-13 15:56:33 +0000107 it('getMicroServiceJsonRepresentationForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200108 const msJsonRepresentation = {"schema": {}};
sebdetb65f1212019-08-23 07:49:25 -0700109 expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
xuegaod8bed322019-07-18 17:45:34 +0200110 });
111
112 it('getResourceDetailsVfProperty', () => {
113 const resourceVF = {
114 "vLoadBalancerMS 0": {
115 "resourceVendor": "Test",
116 "resourceVendorModelNumber": "",
117 "name": "vLoadBalancerMS",
118 "description": "vLBMS",
119 "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506",
120 "subcategory": "Load Balancer",
121 "category": "Application L4+",
122 "type": "VF",
123 "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6",
124 "version": "1.0",
125 "resourceVendorRelease": "1.0",
126 "customizationUUID": "465246dc-7748-45f4-a013-308d92922552"
127 }
128 };
129 expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF);
130 });
131
132 it('getResourceDetailsVfModuleProperty', () => {
133 const vfModule = {
134 "Vloadbalancerms..vpkg..module-1": {
135 "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043",
136 "vfModuleModelVersion": "1",
137 "vfModuleModelName": "Vloadbalancerms..vpkg..module-1",
138 "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc",
139 "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52",
140 "min_vf_module_instances": 0,
141 "vf_module_label": "vpkg",
142 "max_vf_module_instances": 1,
143 "vf_module_type": "Expansion",
144 "isBase": false,
145 "initial_count": 0,
146 "volume_group": false
147 }
148 };
149 expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule);
150 });
151
152 it('getLoopLogsArray', () => {
153 const logs = [
154 {
155 "id": 1,
156 "logType": "INFO",
157 "logComponent": "CLAMP",
xuegaoc4f54bf2020-04-21 18:05:44 +0200158 "message": "Operational policies UPDATED",
xuegaod8bed322019-07-18 17:45:34 +0200159 "logInstant": "2019-07-08T09:44:37Z"
160 }
161 ];
162 expect(loopCache.getLoopLogsArray()).toStrictEqual(logs);
163 });
164
165 it('getComponentStates', () => {
166 const component = {
167 "POLICY": {
168 "componentState": {
169 "stateName": "NOT_SENT",
170 "description": "The policies defined have NOT yet been created on the policy engine"
171 }
172 },
173 "DCAE": {
174 "componentState": {
175 "stateName": "BLUEPRINT_DEPLOYED",
176 "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop"
177 }
178 }
179 };
180 expect(loopCache.getComponentStates()).toStrictEqual(component);
181 });
182
183 it('updateGlobalProperties', () => {
184 const newGlobalProps = {
185 "dcaeDeployParameters": {
186 "location_id": "newLocation",
187 "service_id": "newServiceId",
188 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2"
189 }
190 };
191 loopCache.updateGlobalProperties(newGlobalProps);
192 expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps);
193 });
194
195 it('updateOperationalPolicyProperties', () => {
xuegao635445a2020-03-02 11:37:20 +0100196 const newOpPolicy = {
xuegaod8bed322019-07-18 17:45:34 +0200197 "operational_policy": {
198 "controlLoop": {},
199 "policies": []
200 }
xuegao635445a2020-03-02 11:37:20 +0100201 };
202 loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy);
203 expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy);
xuegaod8bed322019-07-18 17:45:34 +0200204 });
205
206 it('updateMicroServiceProperties', () => {
sebdetb65f1212019-08-23 07:49:25 -0700207 const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"};
208 loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties);
209 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties);
xuegaod8bed322019-07-18 17:45:34 +0200210 });
211 });