blob: 4642ff52f1b5ee51e07ef69e57ee7133df2710ee [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
xuegaod8bed322019-07-18 17:45:34 +020033 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": []
xuegaod8bed322019-07-18 17:45:34 +020041 }
xuegaoc488fed2019-12-19 11:58:45 +010042 },
43 "jsonRepresentation": {
44 "schema": {}
45 }
xuegaod8bed322019-07-18 17:45:34 +020046 }];
47 expect(loopCache.getOperationalPolicies()).toStrictEqual(opPolicy);
48 });
49
xuegaoc488fed2019-12-19 11:58:45 +010050 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 });
xuegaod8bed322019-07-18 17:45:34 +020071 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
TedHumphrey4aedf732019-08-13 15:56:33 +000091 it('getMicroServiceForName', () => {
xuegaod8bed322019-07-18 17:45:34 +020092 const msJson = {
93 "name": "TCA_h2NMX_v1_0_ResourceInstanceName1_tca",
94 "modelType": "onap.policies.monitoring.cdap.tca.hi.lo.app",
sebdet58135b82020-02-27 11:39:50 -080095 "configurationsJson": {"domain": "measurementsForVfScaling"},
xuegaod8bed322019-07-18 17:45:34 +020096 "shared": false,
97 "jsonRepresentation": {"schema": {}}
98 };
sebdetb65f1212019-08-23 07:49:25 -070099 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJson);
100 expect(loopCache.getMicroServiceForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200101 });
102
TedHumphrey4aedf732019-08-13 15:56:33 +0000103 it('getMicroServicePropertiesForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200104 const msProp = {"domain": "measurementsForVfScaling"};
sebdetb65f1212019-08-23 07:49:25 -0700105 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msProp);
106 expect(loopCache.getMicroServicePropertiesForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca_2")).toBeNull();
xuegaod8bed322019-07-18 17:45:34 +0200107 });
108
TedHumphrey4aedf732019-08-13 15:56:33 +0000109 it('getMicroServiceJsonRepresentationForName', () => {
xuegaod8bed322019-07-18 17:45:34 +0200110 const msJsonRepresentation = {"schema": {}};
sebdetb65f1212019-08-23 07:49:25 -0700111 expect(loopCache.getMicroServiceJsonRepresentationForName("TCA_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(msJsonRepresentation);
xuegaod8bed322019-07-18 17:45:34 +0200112 });
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', () => {
xuegao635445a2020-03-02 11:37:20 +0100198 const newOpPolicy = {
xuegaod8bed322019-07-18 17:45:34 +0200199 "guard_policies": {},
200 "operational_policy": {
201 "controlLoop": {},
202 "policies": []
203 }
xuegao635445a2020-03-02 11:37:20 +0100204 };
205 loopCache.updateOperationalPolicyProperties("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca",newOpPolicy);
206 expect(loopCache.getOperationalPolicyPropertiesForName("OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca")).toStrictEqual(newOpPolicy);
xuegaod8bed322019-07-18 17:45:34 +0200207 });
208
209 it('updateMicroServiceProperties', () => {
sebdetb65f1212019-08-23 07:49:25 -0700210 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);
xuegaod8bed322019-07-18 17:45:34 +0200213 });
214 });