07d4cee9b69e9e596a2a9daf41e86cc6dc1a0dbe
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / models / vrf / vrf.model.info.spec.ts
1 import {ComponentInfoService} from "../../../component-info/component-info.service";
2 import {NgRedux} from "@angular-redux/store";
3 import {AppState} from "../../../../../shared/store/reducers";
4 import {getTestBed, TestBed} from "@angular/core/testing";
5 import {HttpClientTestingModule} from "@angular/common/http/testing";
6 import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
7 import {DynamicInputsService} from "../../dynamicInputs.service";
8 import {SharedTreeService} from "../../shared.tree.service";
9 import {DuplicateService} from "../../../duplicate/duplicate.service";
10 import {AaiService} from "../../../../../shared/services/aaiService/aai.service";
11 import {HttpClient, HttpHandler} from "@angular/common/http";
12 import {FeatureFlagsService} from "../../../../../shared/services/featureFlag/feature-flags.service";
13 import {IframeService} from "../../../../../shared/utils/iframe.service";
14 import {VrfModelInfo} from "./vrf.model.info";
15 import {ComponentInfoType} from "../../../component-info/component-info-model";
16 import {ModelInformationItem} from "../../../../../shared/components/model-information/model-information.component";
17 import {VrfModel} from "../../../../../shared/models/vrfModel";
18 import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
19 import each from 'jest-each';
20 import {DialogService} from "ng2-bootstrap-modal";
21 import {NetworkStepService} from "./vrfModal/networkStep/network.step.service";
22 import {VpnStepService} from "./vrfModal/vpnStep/vpn.step.service";
23
24 describe('Vrf Model Info', () => {
25
26   let injector;
27   let _componentInfoService : ComponentInfoService;
28
29   let _store : NgRedux<AppState>;
30   let _sharedTreeService: SharedTreeService;
31   let _dialogService : DialogService;
32   let _iframeService : IframeService;
33   let _networkStepService : NetworkStepService;
34   let _vpnStepService : VpnStepService;
35   let vrfModel: VrfModelInfo;
36
37   beforeEach(() => {
38     TestBed.configureTestingModule({
39       imports: [HttpClientTestingModule, NgReduxTestingModule],
40       providers: [
41         MockNgRedux,
42         DynamicInputsService,
43         SharedTreeService,
44         DuplicateService,
45         AaiService,
46         HttpClient,
47         HttpHandler,
48         FeatureFlagsService,
49         ComponentInfoService,
50         DialogService,
51         IframeService,
52         IframeService,
53         NetworkStepService,
54        VpnStepService]
55     }).compileComponents();
56
57     injector = getTestBed();
58     _sharedTreeService = injector.get(SharedTreeService);
59     _dialogService = injector.get(DialogService);
60     _iframeService = injector.get(IframeService);
61     _networkStepService = injector.get(NetworkStepService);
62     _vpnStepService = injector.get(VpnStepService);
63     _store = injector.get(NgRedux);
64     _componentInfoService = injector.get(ComponentInfoService);
65
66     vrfModel = new VrfModelInfo(_store,_sharedTreeService, _dialogService, _iframeService, _networkStepService, _vpnStepService);
67
68   });
69
70
71   test('vrfModel should be defined', () => {
72     expect(vrfModel).toBeDefined();
73   });
74
75   test('vrfModel should defined extra details', () => {
76     expect(vrfModel.name).toEqual('vrfs');
77     expect(vrfModel.type).toEqual('VRF');
78     expect(vrfModel.childNames).toEqual(['networks','vpns']);
79     expect(vrfModel.componentInfoType).toEqual(ComponentInfoType.VRF);
80   });
81
82   test('Info for vrf should be correct', () => {
83     const model = new VrfModel();
84     const instance = null;
85     let actualNetworkInfo = vrfModel.getInfo(model,instance);
86     let expectedNetworkInfo = [
87       ModelInformationItem.createInstance('Min instances', "1"),
88       ModelInformationItem.createInstance('Max instances', "1"),
89       ModelInformationItem.createInstance("Association", "L3-Network - VPN")
90     ];
91     expect(actualNetworkInfo).toEqual(expectedNetworkInfo);
92   });
93
94
95
96   test('getModel should return VRF model with min and max are equal to 1 (hard coded)', () => {
97     let model: VrfModel = vrfModel.getModel('VRF Entry Configuration 0', <any>{
98       originalName : 'VRF Entry Configuration 0'
99     }, getServiceHierarchy());
100     expect(model.properties['type']).toEqual('VRF-ENTRY');
101     expect(model.min).toEqual(1);
102     expect(model.max).toEqual(1);
103   });
104
105   const showNodeIconsDataProvider = [
106     [false, new AvailableNodeIcons(true , false)],
107     [true, new AvailableNodeIcons(false , true)]
108   ];
109
110   each(showNodeIconsDataProvider).test('showNodeIcons should return value according reach limit of max',(existVRFs,expectedResult)=>{
111     const serviceId : string = 'servicedId';
112     const node = getNode();
113     let state = getMockState();
114     if(existVRFs) {
115       state.service.serviceInstance.servicedId.existingVRFCounterMap = {
116         'modelCustomizationId': 1
117       };
118     }
119     jest.spyOn(MockNgRedux.getInstance(), 'getState').mockReturnValue(state);
120     const result = vrfModel.showNodeIcons(<any>node, serviceId);
121     expect(result).toEqual(expectedResult);
122   });
123
124   function getNode() {
125     return {
126       data: {
127         id: 'vrfId',
128         name: 'VRF Entry Configuration 0',
129         modelCustomizationId: 'modelCustomizationId',
130         modelUniqueId: 'modelCustomizationId',
131         getModel: function () {
132           return {max: 1}
133         }
134       }
135     };
136   }
137
138   function getMockState(){
139     return {
140       global:{
141         "drawingBoardStatus": "CREATE"
142       },
143       service : {
144         serviceHierarchy : {
145           'servicedId' : {
146           }
147         },
148         serviceInstance : {
149           'servicedId' : {
150             'existingVRFCounterMap' : {},
151             'vrfs' : {
152               'vrfName' :{
153
154               }
155             }
156           }
157         }
158       }
159     };
160   }
161
162   function getServiceHierarchy() {
163     return {
164       "service": {
165         "uuid": "f028b2e2-7080-4b13-91b2-94944d4c42d8",
166         "invariantUuid": "dfc2c44c-2429-44ca-ae26-1e6dc1f207fb",
167         "name": "infraVPN",
168         "version": "1.0",
169         "toscaModelURL": null,
170         "category": "Network Service",
171         "serviceType": "BONDING",
172         "serviceRole": "INFRASTRUCTURE-VPN",
173         "description": "ddd",
174         "serviceEcompNaming": "true",
175         "instantiationType": "A-La-Carte",
176         "inputs": {},
177         "vidNotions": {
178           "instantiationUI": "macroService",
179           "modelCategory": "other",
180           "viewEditUI": "legacy"
181         }
182       },
183       "vnfs": {},
184       "networks": {},
185       "collectionResources": {},
186       "configurations": {},
187       "fabricConfigurations": {},
188       "serviceProxies": {
189         "misvpn_service_proxy 0": {
190           "uuid": "35186eb0-e6b6-4fa5-86bb-1501b342a7b1",
191           "invariantUuid": "73f89e21-b96c-473f-8884-8b93bcbd2f76",
192           "description": "A Proxy for Service MISVPN_SERVICE",
193           "name": "MISVPN_SERVICE Service Proxy",
194           "version": "3.0",
195           "customizationUuid": "4c2fb7e0-a0a5-4b32-b6ed-6a974e55d923",
196           "inputs": {},
197           "commands": {},
198           "properties": {
199             "ecomp_generated_naming": "false"
200           },
201           "type": "Service Proxy",
202           "sourceModelUuid": "d5cc7d15-c842-450e-95ae-2a69e66dd23b",
203           "sourceModelInvariant": "c126ec86-59fe-48c0-9532-e39a9b3e5272",
204           "sourceModelName": "MISVPN_SERVICE"
205         }
206       },
207       "vfModules": {},
208       "volumeGroups": {},
209       "pnfs": {},
210       "vnfGroups": {},
211       "vrfs": {
212         "VRF Entry Configuration 0": {
213           "uuid": "9cac02be-2489-4374-888d-2863b4511a59",
214           "invariantUuid": "b67a289b-1688-496d-86e8-1583c828be0a",
215           "description": "VRF Entry configuration object",
216           "name": "VRF Entry Configuration",
217           "version": "30.0",
218           "customizationUuid": "dd024d73-9bd1-425d-9db5-476338d53433",
219           "inputs": {},
220           "commands": {},
221           "properties": {
222             "ecomp_generated_naming": "false",
223             "type": "VRF-ENTRY",
224             "role": "INFRASTRUCTURE-CLOUD-VPN"
225           },
226           "type": "Configuration",
227           "modelCustomizationName": "VRF Entry Configuration 0",
228           "sourceNodes": [],
229           "collectorNodes": null,
230           "configurationByPolicy": false
231         }
232       }
233     }
234   }
235
236
237
238 })