blob: 97c09fa362aa3bb38060102398963321d31d26a2 [file] [log] [blame]
xuegaod8bed322019-07-18 17:45:34 +02001/*-
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 */
xuegaod8bed322019-07-18 17:45:34 +020023import LoopCache from '../api/LoopCache';
24
25const json = require('./LoopCache_mokeLoopJsonCache.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('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": []
xuegaod8bed322019-07-18 17:45:34 +020052 }
xuegaoc488fed2019-12-19 11:58:45 +010053 },
54 "jsonRepresentation": {
55 "schema": {}
56 }
xuegaod8bed322019-07-18 17:45:34 +020057 }];
58 expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy);
59 });
60
xuegaoc488fed2019-12-19 11:58:45 +010061 it('getOperationalPoliciesNoJsonSchema', () => {
62 const opPolicy = [{
63 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",
64 "configurationsJson": {
65 "guard_policies": {},
66 "operational_policy": {
67 "controlLoop": {},
68 "policies": []
69 }
70 }
71 }];
72 expect(loopCache.getOperationalPoliciesNoJsonSchema()).toStrictEqual(opPolicy);
73 });
74
75 it('getOperationalPolicyJsonSchema', () => {
76 const jsonSchema = {
77 "schema": {}
78 };
79
80 expect(loopCache.getOperationalPolicyJsonSchema()).toStrictEqual(jsonSchema);
81 });
xuegaod8bed322019-07-18 17:45:34 +020082 it('getGlobalProperties', () => {
83 const globelProp = {
84 "dcaeDeployParameters": {
85 "location_id": "",
86 "service_id": "",
87 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
88 }
89 };
90 expect(loopCache.getGlobalProperties()).toStrictEqual(globelProp);
91 });
92
93 it('getDcaeDeploymentProperties', () => {
94 const deploymentProp = {
95 "location_id": "",
96 "service_id": "",
97 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca"
98 };
99 expect(loopCache.getDcaeDeploymentProperties()).toStrictEqual(deploymentProp);
100 });
101
TedHumphrey4aedf732019-08-13 15:56:33 +0000102 it('getMicroServiceForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200103 const msJson = {
104 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
105 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
sebdet58135b82020-02-27 11:39:50 -0800106 "configurationsJson": {"domain": "measurementsForVfScaling"},
xuegaod8bed322019-07-18 17:45:34 +0200107 "shared": false,
108 "jsonRepresentation": {"schema": {}}
109 };
sebdetb65f1212019-08-23 07:49:25 -0700110 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
111 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200112 });
113
TedHumphrey4aedf732019-08-13 15:56:33 +0000114 it('getMicroServicePropertiesForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200115 const msProp = {"domain": "measurementsForVfScaling"};
sebdetb65f1212019-08-23 07:49:25 -0700116 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
117 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200118 });
119
TedHumphrey4aedf732019-08-13 15:56:33 +0000120 it('getMicroServiceJsonRepresentationForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200121 const msJsonRepresentation = {"schema": {}};
sebdetb65f1212019-08-23 07:49:25 -0700122 expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
xuegaod8bed322019-07-18 17:45:34 +0200123 });
124
125 it('getResourceDetailsVfProperty', () => {
126 const resourceVF = {
127 "vLoadBalancerMS 0": {
128 "resourceVendor": "Test",
129 "resourceVendorModelNumber": "",
130 "name": "vLoadBalancerMS",
131 "description": "vLBMS",
132 "invariantUUID": "1a31b9f2-e50d-43b7-89b3-a040250cf506",
133 "subcategory": "Load Balancer",
134 "category": "Application L4+",
135 "type": "VF",
136 "UUID": "b4c4f3d7-929e-4b6d-a1cd-57e952ddc3e6",
137 "version": "1.0",
138 "resourceVendorRelease": "1.0",
139 "customizationUUID": "465246dc-7748-45f4-a013-308d92922552"
140 }
141 };
142 expect(loopCache.getResourceDetailsVfProperty()).toStrictEqual(resourceVF);
143 });
144
145 it('getResourceDetailsVfModuleProperty', () => {
146 const vfModule = {
147 "Vloadbalancerms..vpkg..module-1": {
148 "vfModuleModelInvariantUUID": "ca052563-eb92-4b5b-ad41-9111768ce043",
149 "vfModuleModelVersion": "1",
150 "vfModuleModelName": "Vloadbalancerms..vpkg..module-1",
151 "vfModuleModelUUID": "1e725ccc-b823-4f67-82b9-4f4367070dbc",
152 "vfModuleModelCustomizationUUID": "1bffdc31-a37d-4dee-b65c-dde623a76e52",
153 "min_vf_module_instances": 0,
154 "vf_module_label": "vpkg",
155 "max_vf_module_instances": 1,
156 "vf_module_type": "Expansion",
157 "isBase": false,
158 "initial_count": 0,
159 "volume_group": false
160 }
161 };
162 expect(loopCache.getResourceDetailsVfModuleProperty()).toStrictEqual(vfModule);
163 });
164
165 it('getLoopLogsArray', () => {
166 const logs = [
167 {
168 "id": 1,
169 "logType": "INFO",
170 "logComponent": "CLAMP",
171 "message": "Operational and Guard policies UPDATED",
172 "logInstant": "2019-07-08T09:44:37Z"
173 }
174 ];
175 expect(loopCache.getLoopLogsArray()).toStrictEqual(logs);
176 });
177
178 it('getComponentStates', () => {
179 const component = {
180 "POLICY": {
181 "componentState": {
182 "stateName": "NOT_SENT",
183 "description": "The policies defined have NOT yet been created on the policy engine"
184 }
185 },
186 "DCAE": {
187 "componentState": {
188 "stateName": "BLUEPRINT_DEPLOYED",
189 "description": "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop"
190 }
191 }
192 };
193 expect(loopCache.getComponentStates()).toStrictEqual(component);
194 });
195
196 it('updateGlobalProperties', () => {
197 const newGlobalProps = {
198 "dcaeDeployParameters": {
199 "location_id": "newLocation",
200 "service_id": "newServiceId",
201 "policy_id": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2"
202 }
203 };
204 loopCache.updateGlobalProperties(newGlobalProps);
205 expect(loopCache.getGlobalProperties()).toStrictEqual(newGlobalProps);
206 });
207
208 it('updateOperationalPolicyProperties', () => {
209 const newOpPolicy = [{
210 "name": "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca_new",
211 "configurationsJson": {
212 "guard_policies": {},
213 "operational_policy": {
214 "controlLoop": {},
215 "policies": []
216 }
217 }
218 }];
219 loopCache.updateOperationalPolicyProperties(newOpPolicy);
220 expect(loopCache.getOperationalPolicies()).toStrictEqual(newOpPolicy);
221 });
222
223 it('updateMicroServiceProperties', () => {
sebdetb65f1212019-08-23 07:49:25 -0700224 const newMsPolicyProperties = {"domain": "measurementsForVfScalingNew"};
225 loopCache.updateMicroServiceProperties("TCA_h2NMX_v1_0_ResourceInstanceName1_tca", newMsPolicyProperties);
226 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newMsPolicyProperties);
xuegaod8bed322019-07-18 17:45:34 +0200227 });
228 });