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