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