Rework the policy refresh
[clamp.git] / ui-react / src / api / 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 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
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": []
41           }
42         },
43        "jsonRepresentation": {
44         "schema": {}
45       }
46       }];
47       expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy);
48     });
49
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     });
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
91     it('getMicroServiceForName', () => {
92       const msJson = {
93           "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
94           "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
95           "configurationsJson": {"domain": "measurementsForVfScaling"},
96           "shared": false,
97           "jsonRepresentation": {"schema": {}}
98       };
99       expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
100       expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
101     });
102
103     it('getMicroServicePropertiesForName', () => {
104       const msProp = {"domain": "measurementsForVfScaling"};
105       expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
106       expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
107     });
108
109     it('getMicroServiceJsonRepresentationForName', () => {
110       const msJsonRepresentation = {"schema": {}};
111       expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
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', () => {
198       const newOpPolicy = {
199           "guard_policies": {},
200           "operational_policy": {
201             "controlLoop": {},
202             "policies": []
203           }
204         };
205       loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy);
206       expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy);
207     });
208
209     it('updateMicroServiceProperties', () => {
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);
213     });
214  });