regression unit test for getServicesByOwningEntityId
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / models / vnfGrouping / vnfGrouping.model.info.spec.ts
1 import {HttpClientTestingModule} from "@angular/common/http/testing";
2 import {getTestBed, TestBed} from "@angular/core/testing";
3 import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
4 import {VnfGroupingModelInfo} from "./vnfGrouping.model.info";
5 import {DynamicInputsService} from "../../dynamicInputs.service";
6 import {SharedTreeService} from "../../shared.tree.service";
7 import {VnfGroupPopupService} from "../../../../../shared/components/genericFormPopup/genericFormServices/vnfGroup/vnfGroup.popup.service";
8 import {DialogService} from "ng2-bootstrap-modal";
9 import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
10 import {VnfGroupModel} from "../../../../../shared/models/vnfGroupModel";
11 import {IframeService} from "../../../../../shared/utils/iframe.service";
12 import {RouterTestingModule} from "@angular/router/testing";
13 import {DrawingBoardModes} from "../../../drawing-board.modes";
14 import {AaiService} from "../../../../../shared/services/aaiService/aai.service";
15 import {FeatureFlagsService} from "../../../../../shared/services/featureFlag/feature-flags.service";
16 import {ITableContent} from "../../../../../shared/components/searchMembersModal/members-table/element-table-row.model";
17
18 describe('VnfGroupingModelInfo Model Info', () => {
19   let injector;
20   let _dialogService : DialogService;
21   let _vnfGroupPopupService : VnfGroupPopupService;
22   let  _dynamicInputsService : DynamicInputsService;
23   let _sharedTreeService : SharedTreeService;
24   let _iframeService : IframeService;
25   let vnfGroupModel: VnfGroupingModelInfo;
26   let _aaiService : AaiService;
27   beforeAll(done => (async () => {
28     TestBed.configureTestingModule({
29       imports: [HttpClientTestingModule, NgReduxTestingModule, RouterTestingModule],
30       providers: [
31         DialogService,
32         VnfGroupPopupService,
33         DynamicInputsService,
34         SharedTreeService,
35         IframeService,
36         AaiService,
37         FeatureFlagsService,
38         MockNgRedux]
39     });
40     await TestBed.compileComponents();
41     injector = getTestBed();
42     _sharedTreeService = injector.get(SharedTreeService);
43     _aaiService = injector.get(AaiService);
44
45     vnfGroupModel =  new VnfGroupingModelInfo(_dynamicInputsService, _sharedTreeService, _dialogService, _vnfGroupPopupService, _iframeService,  _aaiService, MockNgRedux.getInstance());
46   })().then(done).catch(done.fail));
47
48
49   test('VnfGroupingModelInfo should be defined', () => {
50     expect(vnfGroupModel).toBeDefined();
51   });
52
53   test('VnfGroupingModelInfo should defined extra details', () => {
54     expect(vnfGroupModel.name).toEqual('vnfGroups');
55     expect(vnfGroupModel.type).toEqual('VnfGroup');
56   });
57
58   test('isEcompGeneratedNaming should return true if vnf group has isEcompGeneratedNaming is "true" ', () => {
59     let isEcompGeneratedNaming : boolean = vnfGroupModel.isEcompGeneratedNaming({
60       properties: {
61         ecomp_generated_naming: 'true'
62       }
63     });
64     expect(isEcompGeneratedNaming).toBeTruthy();
65   });
66
67   test('getTooltip should return "vnfGrouping"', () => {
68     let tooltip: string = vnfGroupModel.getTooltip();
69     expect(tooltip).toEqual('VnfGroup');
70   });
71
72   test('getType should return "vnfGrouping"', () => {
73     let tooltip: string = vnfGroupModel.getType();
74     expect(tooltip).toEqual('VnfGroup');
75   });
76
77   test('getNextLevelObject should return null', () => {
78     let nextLevel = vnfGroupModel.getNextLevelObject();
79     expect(nextLevel).not.toBeNull();
80   });
81
82   test('showNodeIcons should return true if not reachLimit of max', ()=>{
83     let serviceId : string = 'servicedId';
84     let node = {
85       data : {
86         id : 'vnfGroupId',
87         name : 'vnfGroupName'
88       }
89     };
90     jest.spyOn(MockNgRedux.getInstance(), 'getState').mockReturnValue({
91         global:{
92           drawingBoardStatus: "EDIT"
93         },
94       service : {
95         serviceHierarchy : {
96           'servicedId' : {
97             'vnfGroups' : {
98               'vnfGroupName' : {
99                 'properties' : {
100                 }
101               }
102             }
103           }
104         },
105         serviceInstance : {
106           'servicedId' : {
107             'existingVnfGroupCounterMap' : {
108               'vnfGroupId' : 1
109             },
110             'vnfGroups' : {
111               'vnfGroupName' :{
112
113               }
114             }
115           }
116         }
117       }
118     });
119
120     let result = vnfGroupModel.showNodeIcons(<any>node, serviceId);
121     expect(result).toEqual(new AvailableNodeIcons(true , false));
122   });
123
124   test('getNodeCount should return number of nodes', ()=>{
125     let serviceId : string = 'servicedId';
126     jest.spyOn(_sharedTreeService, 'getExistingInstancesWithDeleteMode').mockReturnValue(0);
127     jest.spyOn(MockNgRedux.getInstance(), 'getState').mockReturnValue({
128       global : {},
129       service : {
130         serviceHierarchy : {
131           'servicedId' : {
132             'vnfGroups' : {
133               'vnfGroupName' : {
134                 'properties' : {
135                 }
136               }
137             }
138           }
139         },
140         serviceInstance : {
141           'servicedId' : {
142             'existingVnfGroupCounterMap' : {
143               'vnfGroupId' : 1
144             },
145             'vnfGroups' : {
146               'vnfGroupName' :{
147                 'originalName' : 'vnfGroupName'
148               }
149             }
150           }
151         }
152       }
153     });
154
155     let node = {
156       data : {
157         id : 'vnfGroupId',
158         name : 'vnfGroupName',
159         modelUniqueId: 'vnfGroupId',
160       }
161     };
162     let result = vnfGroupModel.getNodeCount(<any>node , serviceId);
163     expect(result).toEqual(1);
164
165     node.data.modelUniqueId = 'vnfGroupId_notExist';
166     result = vnfGroupModel.getNodeCount(<any>node , serviceId);
167     expect(result).toEqual(0);
168
169     result = vnfGroupModel.getNodeCount(<any>node , serviceId + '_notExist');
170     expect(result).toEqual(0);
171   });
172
173   test('getModel should return VnfGroup model', () => {
174     let model: VnfGroupModel = vnfGroupModel.getModel('ResourceGroup0', <any>{
175       originalName : 'ResourceGroup0'
176     }, getServiceHierarchy());
177     expect(model.type).toEqual('VnfGroup');
178   });
179
180   test('getMenuAction: showAuditInfoVnfGroup', ()=>{
181
182     jest.spyOn(MockNgRedux.getInstance(), 'getState').mockReturnValue({
183       global: {
184         "drawingBoardStatus": DrawingBoardModes.RETRY
185       }
186     });
187     jest.spyOn(_sharedTreeService, 'isRetryMode').mockReturnValue(true);
188     let node = {
189       data : {
190         "modelId": "6b528779-44a3-4472-bdff-9cd15ec93450",
191         "action": "Create",
192         "isFailed": true,
193       }
194     };
195     let serviceModelId = "6b528779-44a3-4472-bdff-9cd15ec93450";
196     let result = vnfGroupModel.getMenuAction(<any>node, serviceModelId);
197     spyOn(result['showAuditInfo'], 'method');
198     expect(result['showAuditInfo']).toBeDefined();
199     expect(result['showAuditInfo'].visible(node)).toBeTruthy();
200     expect(result['showAuditInfo'].enable(node)).toBeTruthy();
201     result['showAuditInfo']['method'](node, serviceModelId);
202     expect(result['showAuditInfo']['method']).toHaveBeenCalledWith(node, serviceModelId);
203   });
204
205
206   test('generateRelatedMemberTableContent', ()=> {
207     const tableContents: ITableContent[] = vnfGroupModel.generateRelatedMemberTableContent();
208     expect(tableContents).toEqual([
209       {
210         id: 'vnfName',
211         contents: [{
212           id: ['instanceName'],
213           value: ['instanceName']
214         }, {
215           id: ['instanceId'],
216           value: ["instanceId"],
217           prefix: 'UUID: '
218         }]
219       },
220       {
221         id: 'version',
222         contents: [{
223           id: ['modelInfo', 'modelVersion'],
224           value: ['modelInfo', 'modelVersion']
225         }]
226       },
227       {
228         id: 'modelName',
229         contents: [{
230           id: ['modelInfo', 'modelName'],
231           value: ['modelInfo', 'modelName']
232         }]
233       },
234       {
235         id: 'provStatus',
236         contents: [{
237           id: ['provStatus'],
238           value: ['provStatus']
239         }]
240       },
241       {
242         id: 'serviceInstance',
243         contents: [{
244           id: ['serviceInstanceName'],
245           value: ['serviceInstanceName']
246         }, {
247           id: ['serviceInstanceId'],
248           value: ["serviceInstanceId"],
249           prefix: 'UUID: '
250         }]
251       },
252       {
253         id: 'cloudRegion',
254         contents: [{
255           id: ['lcpCloudRegionId'],
256           value: ['lcpCloudRegionId']
257         }]
258       },
259       {
260         id: 'tenantName',
261         contents: [{
262           id: ['tenantName'],
263           value: ['tenantName']
264         }]
265       }
266     ]);
267   });
268
269   function getServiceHierarchy(){
270     return {
271       "service": {
272         "uuid": "6b528779-44a3-4472-bdff-9cd15ec93450",
273         "invariantUuid": "e49fbd11-e60c-4a8e-b4bf-30fbe8f4fcc0",
274         "name": "action-data",
275         "version": "1.0",
276         "toscaModelURL": null,
277         "category": "",
278         "serviceType": "",
279         "serviceRole": "",
280         "description": "",
281         "serviceEcompNaming": "false",
282         "instantiationType": "Macro",
283         "inputs": {
284           "2017488_pasqualevpe0_ASN": {
285             "type": "string",
286             "description": "AV/PE",
287             "entry_schema": null,
288             "inputProperties": null,
289             "constraints": [],
290             "required": true,
291             "default": "AV_vPE"
292           }
293         },
294         "vidNotions": {
295           "instantiationUI": "legacy",
296           "modelCategory": "other"
297         }
298       },
299       "vnfGroups": {
300         "ResourceGroup0": {
301           "type": "VnfGroup",
302           "uuid": "0903e1c0-8e03-4936-b5c2-260653b96413",
303           "invariantUuid": "00beb8f9-6d39-452f-816d-c709b9cbb87d",
304           "version": "1",
305           "name": "ResourceGroup0",
306           "modelCustomizationName": "ResourceGroup0",
307           "properties": {
308             "contained_resource_type": "VF",
309             "role": "SERVICE-ACCESS",
310             "function": "DATA",
311             "description": "DDD0",
312             "type": "LOAD-GROUP"
313           },
314           "members": {
315             "vdorothea_svc_vprs_proxy 0": {
316               "uuid": "65fadfa8-a0d9-443f-95ad-836cd044e26c",
317               "invariantUuid": "f4baae0c-b3a5-4ca1-a777-afbffe7010bc",
318               "description": "A Proxy for Service vDOROTHEA_Svc_vPRS",
319               "name": "vDOROTHEA_Svc_vPRS Service Proxy",
320               "version": "1.0",
321               "customizationUuid": "bdb63d23-e132-4ce7-af2c-a493b4cafac9",
322               "inputs": {},
323               "commands": {},
324               "properties": {},
325               "type": "Service Proxy",
326               "sourceModelUuid": "da7827a2-366d-4be6-8c68-a69153c61274",
327               "sourceModelInvariant": "24632e6b-584b-4f45-80d4-fefd75fd9f14",
328               "sourceModelName": "vDOROTHEA_Svc_vPRS"
329             },
330             "vdorothea_svc_vprs_proxy 1": {
331               "uuid": "111dfa8-a0d9-443f-95ad-836cd044e26c",
332               "invariantUuid": "111ae0c-b3a5-4ca1-a777-afbffe7010bc",
333               "description": "A Proxy for Service vDOROTHEA_Svc_vPRS",
334               "name": "111_Svc_vPRS Service Proxy",
335               "version": "1.0",
336               "customizationUuid": "1113d23-e132-4ce7-af2c-a493b4cafac9",
337               "inputs": {},
338               "commands": {},
339               "properties": {},
340               "type": "Service Proxy",
341               "sourceModelUuid": "11127a2-366d-4be6-8c68-a69153c61274",
342               "sourceModelInvariant": "1112e6b-584b-4f45-80d4-fefd75fd9f14",
343               "sourceModelName": "111_Svc_vPRS"
344             }
345           }
346         }
347       },
348       "networks": {},
349       "collectionResources": {},
350       "configurations": {},
351       "fabricConfigurations": {},
352       "serviceProxies": {},
353       "vfModules": {},
354       "volumeGroups": {},
355       "pnfs": {}
356     }
357   }
358
359   function loadMockMembers(): any[] {
360     return [
361       {
362         "action": "None",
363         "instanceName": "VNF1_INSTANCE_NAME",
364         "instanceId": "VNF1_INSTANCE_ID",
365         "orchStatus": null,
366         "productFamilyId": null,
367         "lcpCloudRegionId": "hvf23b",
368         "tenantId": "3e9a20a3e89e45f884e09df0cc2d2d2a",
369         "tenantName": "APPC-24595-T-IST-02C",
370         "modelInfo": {
371           "modelInvariantId": "vnf-instance-model-invariant-id",
372           "modelVersionId": "7a6ee536-f052-46fa-aa7e-2fca9d674c44",
373           "modelVersion": "2.0",
374           "modelName": "vf_vEPDG",
375           "modelType": "vnf"
376         },
377         "instanceType": "VNF1_INSTANCE_TYPE",
378         "provStatus": null,
379         "inMaint": false,
380         "uuid": "7a6ee536-f052-46fa-aa7e-2fca9d674c44",
381         "originalName": null,
382         "legacyRegion": null,
383         "lineOfBusiness": null,
384         "platformName": null,
385         "trackById": "7a6ee536-f052-46fa-aa7e-2fca9d674c44:002",
386         "serviceInstanceId": "service-instance-id1",
387         "serviceInstanceName": "service-instance-name"
388       },
389       {
390         "action": "None",
391         "instanceName": "VNF2_INSTANCE_NAME",
392         "instanceId": "VNF2_INSTANCE_ID",
393         "orchStatus": null,
394         "productFamilyId": null,
395         "lcpCloudRegionId": "hvf23b",
396         "tenantId": "3e9a20a3e89e45f884e09df0cc2d2d2a",
397         "tenantName": "APPC-24595-T-IST-02C",
398         "modelInfo": {
399           "modelInvariantId": "vnf-instance-model-invariant-id",
400           "modelVersionId": "eb5f56bf-5855-4e61-bd00-3e19a953bf02",
401           "modelVersion": "1.0",
402           "modelName": "vf_vEPDG",
403           "modelType": "vnf"
404         },
405         "instanceType": "VNF2_INSTANCE_TYPE",
406         "provStatus": null,
407         "inMaint": true,
408         "uuid": "eb5f56bf-5855-4e61-bd00-3e19a953bf02",
409         "originalName": null,
410         "legacyRegion": null,
411         "lineOfBusiness": null,
412         "platformName": null,
413         "trackById": "eb5f56bf-5855-4e61-bd00-3e19a953bf02:003",
414         "serviceInstanceId": "service-instance-id2",
415         "serviceInstanceName": "service-instance-name"
416       }
417     ];
418   }
419
420
421 });