blob: 76f819c694650181bcd8397eca9470ef63617e6f [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
sebdeteb8e3f12021-01-24 18:12:36 +010025const json = require('./LoopCacheMockFile.json');
xuegaod8bed322019-07-18 17:45:34 +020026
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 },
xuegao28aa29f2020-05-04 15:33:06 +020042 "pdpGroup": "pdpGroupTest",
43 "pdpSubgroup": "pdpSubgroupTest",
44 "jsonRepresentation": {
xuegaoc488fed2019-12-19 11:58:45 +010045 "schema": {}
46 }
xuegaod8bed322019-07-18 17:45:34 +020047 }];
48 expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy);
49 });
50
xuegaoc488fed2019-12-19 11:58:45 +010051 it('getOperationalPoliciesNoJsonSchema', () => {
52 const opPolicy = [{
53 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
54 "configurationsJson": {
xuegaoc488fed2019-12-19 11:58:45 +010055 "operational_policy": {
56 "controlLoop": {},
57 "policies": []
58 }
xuegao28aa29f2020-05-04 15:33:06 +020059 },
60 "pdpGroup": "pdpGroupTest",
61 "pdpSubgroup": "pdpSubgroupTest",
xuegaoc488fed2019-12-19 11:58:45 +010062 }];
63 expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy);
64 });
65
66 it('getOperationalPolicyJsonSchema', () => {
67 const jsonSchema = {
68 "schema": {}
69 };
70
71 expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema);
72 });
xuegaod8bed322019-07-18 17:45:34 +020073 it('getGlobalProperties', () => {
74 const globelProp = {
75 "dcaeDeployParameters": {
76 "location_id": "",
77 "service_id": "",
78 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
79 }
80 };
81 expect(loopCache.getGlobalProperties()).toStrictEqual(globelProp);
82 });
83
84 it('getDcaeDeploymentProperties', () => {
85 const deploymentProp = {
86 "location_id": "",
87 "service_id": "",
88 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
89 };
90 expect(loopCache.getDcaeDeploymentProperties()).toStrictEqual(deploymentProp);
91 });
92
TedHumphrey4aedf732019-08-13 15:56:33 +000093 it('getMicroServiceForName', () => {
xuegaod8bed322019-07-18 17:45:34 +020094 const msJson = {
95 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
96 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
sebdet58135b82020-02-27 11:39:50 -080097 "configurationsJson": {"domain": "measurementsForVfScaling"},
xuegaod8bed322019-07-18 17:45:34 +020098 "shared": false,
xuegao28aa29f2020-05-04 15:33:06 +020099 "pdpGroup": "pdpGroupTest",
100 "pdpSubgroup": "pdpSubgroupTest",
101 "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}},
xuegaod8bed322019-07-18 17:45:34 +0200102 "jsonRepresentation": {"schema": {}}
103 };
sebdetb65f1212019-08-23 07:49:25 -0700104 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
105 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200106 });
107
TedHumphrey4aedf732019-08-13 15:56:33 +0000108 it('getMicroServicePropertiesForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200109 const msProp = {"domain": "measurementsForVfScaling"};
sebdetb65f1212019-08-23 07:49:25 -0700110 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
111 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200112 });
113
TedHumphrey4aedf732019-08-13 15:56:33 +0000114 it('getMicroServiceJsonRepresentationForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200115 const msJsonRepresentation = {"schema": {}};
sebdetb65f1212019-08-23 07:49:25 -0700116 expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
xuegaod8bed322019-07-18 17:45:34 +0200117 });
118
119 it('getResourceDetailsVfProperty', () => {
120 const resourceVF = {
121 "vLoadBalancerMS 0": {
122 "resourceVendor": "Test",
123 "resourceVendorModelNumber": "",
124 "name": "vLoadBalancerMS",
125 "description": "vLBMS",
126 "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506",
127 "subcategory": "Load Balancer",
128 "category": "Application L4+",
129 "type": "VF",
130 "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6",
131 "version": "1.0",
132 "resourceVendorRelease": "1.0",
133 "customizationUUID": "465246dc-7748-45f4-a013-308d92922552"
134 }
135 };
136 expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF);
137 });
138
139 it('getResourceDetailsVfModuleProperty', () => {
140 const vfModule = {
141 "Vloadbalancerms..vpkg..module-1": {
142 "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043",
143 "vfModuleModelVersion": "1",
144 "vfModuleModelName": "Vloadbalancerms..vpkg..module-1",
145 "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc",
146 "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52",
147 "min_vf_module_instances": 0,
148 "vf_module_label": "vpkg",
149 "max_vf_module_instances": 1,
150 "vf_module_type": "Expansion",
151 "isBase": false,
152 "initial_count": 0,
153 "volume_group": false
154 }
155 };
156 expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule);
157 });
158
159 it('getLoopLogsArray', () => {
160 const logs = [
161 {
162 "id": 1,
163 "logType": "INFO",
164 "logComponent": "CLAMP",
xuegaoc4f54bf2020-04-21 18:05:44 +0200165 "message": "Operational policies UPDATED",
xuegaod8bed322019-07-18 17:45:34 +0200166 "logInstant": "2019-07-08T09:44:37Z"
167 }
168 ];
169 expect(loopCache.getLoopLogsArray()).toStrictEqual(logs);
170 });
171
172 it('getComponentStates', () => {
173 const component = {
174 "POLICY": {
175 "componentState": {
176 "stateName": "NOT_SENT",
177 "description": "The policies defined have NOT yet been created on the policy engine"
178 }
179 },
180 "DCAE": {
181 "componentState": {
182 "stateName": "BLUEPRINT_DEPLOYED",
183 "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop"
184 }
185 }
186 };
187 expect(loopCache.getComponentStates()).toStrictEqual(component);
188 });
189
xuegao28aa29f2020-05-04 15:33:06 +0200190 it('getOperationalPolicyForName', () => {
191 const opPolicy = {
192 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
193 "configurationsJson": {
194 "operational_policy": {
195 "controlLoop": {},
196 "policies": []
197 }
198 },
199 "pdpGroup": "pdpGroupTest",
200 "pdpSubgroup": "pdpSubgroupTest",
201 "jsonRepresentation": {
202 "schema": {}
203 }
204 };
205 expect(loopCache.getOperationalPolicyForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicy);
206 expect(loopCache.getOperationalPolicyForName("Not_Exist")).toBeNull();
207 });
208
209 it('getOperationalPolicyPropertiesForName', () => {
210 const opPolicyJson = {
211 "operational_policy": {
212 "controlLoop": {},
213 "policies": []
214 }};
215 expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicyJson);
216 expect(loopCache.getOperationalPolicyPropertiesForName("Not_Exist")).toBeNull();
217 });
218
219 it('getOperationalPolicyJsonRepresentationForName', () => {
220 const opPolicySchema = {
221 "schema": {}
222 };
223 expect(loopCache.getOperationalPolicyJsonRepresentationForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(opPolicySchema);
224 expect(loopCache.getOperationalPolicyJsonRepresentationForName("Not_Exist")).toBeNull();
225 });
226
227 it('getOperationalPolicySupportedPdpGroup', () => {
228 expect(loopCache.getOperationalPolicySupportedPdpGroup("Not_Exist")).toStrictEqual([]);
229 });
230
231 it('getOperationalPolicyPdpGroup', () => {
232 expect(loopCache.getOperationalPolicyPdpGroup("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest");
233 expect(loopCache.getOperationalPolicyPdpGroup("Not_Exist")).toBeNull();
234 });
235
236 it('getOperationalPolicyPdpSubgroup', () => {
237 expect(loopCache.getOperationalPolicyPdpSubgroup("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest");
238 expect(loopCache.getOperationalPolicyPdpSubgroup("Not_Exist")).toBeNull();
239 });
240
241 it('getMicroServiceSupportedPdpGroup', () => {
242 expect(loopCache.getMicroServiceSupportedPdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("supportedPdpGroupsTest");
243 expect(loopCache.getMicroServiceSupportedPdpGroup("Not_Exist")).toStrictEqual([]);
244 });
245
246 it('getMicroServicePdpGroup', () => {
247 expect(loopCache.getMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest");
248 expect(loopCache.getMicroServicePdpGroup("Not_Exist")).toBeNull();
249 });
250
251 it('getMicroServicePdpSubgroup', () => {
252 expect(loopCache.getMicroServicePdpSubgroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest");
253 expect(loopCache.getMicroServicePdpSubgroup("Not_Exist")).toBeNull();
254 });
255
256 it('getMicroServiceJsonRepresentationForName', () => {
257 const msPolicySchema = {
258 "schema": {}
259 };
260 expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msPolicySchema);
261 expect(loopCache.getMicroServiceJsonRepresentationForName("Not_Exist")).toBeNull();
262 });
263
264 it('getTemplateName', () => {
265 expect(loopCache.getTemplateName()).toStrictEqual("loopTemplateTest");
266 });
267
xuegaod8bed322019-07-18 17:45:34 +0200268 it('updateGlobalProperties', () => {
269 const newGlobalProps = {
270 "dcaeDeployParameters": {
271 "location_id": "newLocation",
272 "service_id": "newServiceId",
273 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2"
274 }
275 };
276 loopCache.updateGlobalProperties(newGlobalProps);
277 expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps);
278 });
279
280 it('updateOperationalPolicyProperties', () => {
xuegao635445a2020-03-02 11:37:20 +0100281 const newOpPolicy = {
xuegaod8bed322019-07-18 17:45:34 +0200282 "operational_policy": {
283 "controlLoop": {},
284 "policies": []
285 }
xuegao635445a2020-03-02 11:37:20 +0100286 };
287 loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy);
288 expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy);
xuegaod8bed322019-07-18 17:45:34 +0200289 });
290
291 it('updateMicroServiceProperties', () => {
sebdetb65f1212019-08-23 07:49:25 -0700292 const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"};
293 loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties);
294 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties);
xuegaod8bed322019-07-18 17:45:34 +0200295 });
xuegao28aa29f2020-05-04 15:33:06 +0200296
297 it('updateMicroServicePdpGroup', () => {
298 const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"};
299 loopCache.updateMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", "pdpGroupTest1", "pdpSubgroupTest1");
300 expect(loopCache.getMicroServicePdpGroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpGroupTest1");
301 expect(loopCache.getMicroServicePdpGroup("Not_Exist")).toBeNull();
302 expect(loopCache.getMicroServicePdpSubgroup("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual("pdpSubgroupTest1");
303 expect(loopCache.getMicroServicePdpSubgroup("Not_Exist")).toBeNull();
304 });
xuegaod8bed322019-07-18 17:45:34 +0200305 });