blob: 76f819c694650181bcd8397eca9470ef63617e6f [file] [log] [blame]
brunomilitzer87111ee2021-05-18 12:50:32 +01001/*-
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 */
23import LoopCache from '../api/LoopCache';
24
25const json = require('./LoopCacheMockFile.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
33 it('getOperationalPolicies', () => {
34 const opPolicy = [{
35 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
36 "configurationsJson": {
37 "operational_policy": {
38 "controlLoop": {},
39 "policies": []
40 }
41 },
42 "pdpGroup": "pdpGroupTest",
43 "pdpSubgroup": "pdpSubgroupTest",
44 "jsonRepresentation": {
45 "schema": {}
46 }
47 }];
48 expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy);
49 });
50
51 it('getOperationalPoliciesNoJsonSchema', () => {
52 const opPolicy = [{
53 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
54 "configurationsJson": {
55 "operational_policy": {
56 "controlLoop": {},
57 "policies": []
58 }
59 },
60 "pdpGroup": "pdpGroupTest",
61 "pdpSubgroup": "pdpSubgroupTest",
62 }];
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 });
73 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
93 it('getMicroServiceForName', () => {
94 const msJson = {
95 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
96 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
97 "configurationsJson": {"domain": "measurementsForVfScaling"},
98 "shared": false,
99 "pdpGroup": "pdpGroupTest",
100 "pdpSubgroup": "pdpSubgroupTest",
101 "policyModel": {"policyPdpGroup": {"supportedPdpGroups": "supportedPdpGroupsTest"}},
102 "jsonRepresentation": {"schema": {}}
103 };
104 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
105 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
106 });
107
108 it('getMicroServicePropertiesForName', () => {
109 const msProp = {"domain": "measurementsForVfScaling"};
110 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
111 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
112 });
113
114 it('getMicroServiceJsonRepresentationForName', () => {
115 const msJsonRepresentation = {"schema": {}};
116 expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
117 });
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",
165 "message": "Operational policies UPDATED",
166 "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
190 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
268 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', () => {
281 const newOpPolicy = {
282 "operational_policy": {
283 "controlLoop": {},
284 "policies": []
285 }
286 };
287 loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy);
288 expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy);
289 });
290
291 it('updateMicroServiceProperties', () => {
292 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);
295 });
296
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 });
305 });