Integrate testing framework
[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('getMicroServicesJsonForType', () => {
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.getMicroServicesJsonForType("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
89       expect(loopCache.getMicroServicesJsonForType("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
90     });
91
92     it('getMicroServiceProperties', () => {
93       const msProp = {"domain": "measurementsForVfScaling"};
94       expect(loopCache.getMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
95       expect(loopCache.getMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
96     });
97
98     it('getMicroServiceJsonRepresentationForType', () => {
99       const msJsonRepresentation = {"schema": {}};
100       expect(loopCache.getMicroServiceJsonRepresentationForType("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
101     });
102
103     it('getMicroServiceJsonRepresentationForType', () => {
104       const msJsonRepresentation = {"schema": {}};
105       expect(loopCache.getMicroServiceJsonRepresentationForType("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
106     });
107
108     it('getResourceDetailsVfProperty', () => {
109       const resourceVF = {
110         "vLoadBalancerMS 0": {
111           "resourceVendor": "Test",
112           "resourceVendorModelNumber": "",
113           "name": "vLoadBalancerMS",
114           "description": "vLBMS",
115           "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506",
116           "subcategory": "Load Balancer",
117           "category": "Application L4+",
118           "type": "VF",
119           "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6",
120           "version": "1.0",
121           "resourceVendorRelease": "1.0",
122           "customizationUUID": "465246dc-7748-45f4-a013-308d92922552"
123         }
124       };
125       expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF);
126     });
127
128     it('getResourceDetailsVfModuleProperty', () => {
129       const vfModule = {
130         "Vloadbalancerms..vpkg..module-1": {
131           "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043",
132           "vfModuleModelVersion": "1",
133           "vfModuleModelName": "Vloadbalancerms..vpkg..module-1",
134           "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc",
135           "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52",
136           "min_vf_module_instances": 0,
137           "vf_module_label": "vpkg",
138           "max_vf_module_instances": 1,
139           "vf_module_type": "Expansion",
140           "isBase": false,
141           "initial_count": 0,
142           "volume_group": false
143         }
144       };
145       expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule);
146     });
147
148     it('getLoopLogsArray', () => {
149       const logs = [
150         {
151           "id": 1,
152           "logType": "INFO",
153           "logComponent": "CLAMP",
154           "message": "Operational and Guard policies UPDATED",
155           "logInstant": "2019-07-08T09:44:37Z"
156         }
157       ];
158       expect(loopCache.getLoopLogsArray()).toStrictEqual(logs);
159     });
160
161     it('getComponentStates', () => {
162       const component = {
163         "POLICY": {
164           "componentState": {
165             "stateName": "NOT_SENT",
166             "description": "The policies defined have NOT yet been created on the policy engine"
167           }
168         },
169         "DCAE": {
170           "componentState": {
171             "stateName": "BLUEPRINT_DEPLOYED",
172             "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop"
173           }
174         }
175       };
176       expect(loopCache.getComponentStates()).toStrictEqual(component);
177     });
178
179     it('updateGlobalProperties', () => {
180       const newGlobalProps = {
181         "dcaeDeployParameters": {
182           "location_id": "newLocation",
183           "service_id": "newServiceId",
184           "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2"
185         }
186       };
187       loopCache.updateGlobalProperties(newGlobalProps);
188       expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps);
189     });
190
191     it('updateOperationalPolicyProperties', () => {
192       const newOpPolicy = [{
193         "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca_new",
194         "configurationsJson": {
195           "guard_policies": {},
196           "operational_policy": {
197             "controlLoop": {},
198             "policies": []
199           }
200         }
201       }];
202       loopCache.updateOperationalPolicyProperties(newOpPolicy);
203       expect(loopCache.getOperationalPolicies()).toStrictEqual(newOpPolicy);
204     });
205
206     it('updateMicroServiceProperties', () => {
207       const newMsPolicy = {
208           "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
209           "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
210           "properties": {"domain": "measurementsForVfScalingNew"},
211           "shared": true,
212           "jsonRepresentation": {"schema": {}}
213       };;
214       loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicy);
215       expect(loopCache.getMicroServicesJsonForType("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicy);
216     });
217  });