1 import {DuplicateService} from './duplicate.service';
2 import {LogService} from '../../../shared/utils/log/log.service';
3 import {NgRedux} from '@angular-redux/store';
4 import {ITreeNode} from "angular-tree-component/dist/defs/api";
5 import {SdcUiServices} from "onap-ui-angular";
6 import {IModalConfig} from "onap-ui-angular/dist/components/common";
7 import {AppState} from "../../../shared/store/reducers";
8 import {getTestBed, TestBed} from "@angular/core/testing";
10 class MockAppStore<T> {
38 existingVNFCounterMap : {
53 class MockModalService<T> {}
55 describe('Drawing board tree service', () => {
57 let service: DuplicateService;
58 let store : NgRedux<AppState>;
59 beforeAll(done => (async () => {
60 TestBed.configureTestingModule({
64 {provide: NgRedux, useClass: MockAppStore},
65 {provide: SdcUiServices.ModalService, useClass: MockModalService}
68 await TestBed.compileComponents();
70 injector = getTestBed();
71 service = injector.get(DuplicateService);
72 store = injector.get(NgRedux);
74 })().then(done).catch(done.fail));
77 test('setNumberOfDuplicates should set number of duplicates', ()=>{
78 service.setNumberOfDuplicates(10);
79 expect(service.numberOfDuplicates).toEqual(10);
82 test('isEnabled should return false if type is VNF and has missing data', ()=>{
93 spyOn(node.data.menuActions, 'duplicate').and.returnValue(true);
94 spyOn(service, 'hasMissingData').and.returnValue(true);
95 let result : boolean = service.isEnabled(<any>node, null, null);
96 expect(result).toBeFalsy();
99 test('openDuplicateModal', ()=>{
100 spyOn(service, 'getRemainsInstance').and.returnValue(1);
101 let result : IModalConfig = service.openDuplicateModal(
108 expect(result.title).toEqual('Duplicate Node');
111 test('openDuplicateModal should call getRemainsInstance with correct parameters', ()=>{
112 spyOn(service, 'getRemainsInstance');
113 service.openDuplicateModal(
120 expect(service.getRemainsInstance).toHaveBeenCalledWith('currentServiceId', 'currentId', 'currentServiceId', null, null);
123 test('canDuplicate VNF should return true', () => {
124 let node : ITreeNode = <any> {data : {type : 'VF'}};
126 let result = service.canDuplicate(node);
127 expect(result).toBeTruthy();
130 test('canDuplicate Network should return true', () => {
131 let node : ITreeNode = <any> {data : {type : 'VL'}};
133 let result = service.canDuplicate(node);
134 expect(result).toBeTruthy();
137 test('canDuplicate VFModule should return false', () => {
138 let node : ITreeNode = <any> {data : {type : 'VFModule'}};
140 let result = service.canDuplicate(node);
141 expect(result).toBeFalsy();
144 test('Drawing board tree service should be defined', () => {
145 expect(service).toBeDefined();
148 test('DrawingBoardDuplicateService should be defined', () => {
149 expect(service).toBeDefined();
152 test('Duplicate multi vnfs should save multi vnfs in redux', () => {
153 service.existingNames = {
154 "2017488_pasqualevpe": "",
158 let newVnfs = service.cloneVnf(<any>{
160 "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2": {
161 "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2mtlfi": {
162 "instanceName": "rrr",
163 "volumeGroupName": "ttt"
167 "originalName": null,
168 "trackById": "pfs1f0len3",
169 "instanceName": "2017488_PASQUALEvPE"
170 }, "2017-488_PASQUALE-vPE 0");
172 expect(newVnfs.instanceName).toBe("2017488_PASQUALEvPE_001");
173 expect(newVnfs.vfModules['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2']['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2mtlfi'].instanceName).toBe("rrr_001");
174 expect(newVnfs.vfModules['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2']['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2mtlfi'].volumeGroupName).toBe("ttt_001");
176 newVnfs = service.cloneVnf(<any>{
178 "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2": {
179 "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2mtlfi": {
180 "instanceName": "rrr",
181 "volumeGroupName": "ttt"
185 "originalName": null,
186 "trackById": "pfs1f0len3",
187 "instanceName": "2017488_PASQUALEvPE"
188 }, "2017-488_PASQUALE-vPE 0");
190 expect(newVnfs.instanceName).toBe("2017488_PASQUALEvPE_002");
191 expect(newVnfs.vfModules['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2']['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2mtlfi'].instanceName).toBe("rrr_002");
192 expect(newVnfs.vfModules['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2']['2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2mtlfi'].volumeGroupName).toBe("ttt_002");
195 test('ensure name is unique - send new name - shouldn\'t change name', () => {
196 service.existingNames = {
197 "2017488_pasqualevpe": "",
198 "uniqueinstancename": ""
200 const name = "uniqueInstanceName-1";
201 let uniqueName: string = service.ensureUniqueNameOrGenerateOne(name);
202 expect(uniqueName).toEqual(name);
205 test('ensure name is unique send existing name should change name', () => {
206 service.existingNames = {
207 "2017488_pasqualevpe": "",
208 "uniqueinstancename-1": ""
210 const name = "uniqueInstanceName-1";
211 let uniqueName: string = service.ensureUniqueNameOrGenerateOne(name);
212 expect(uniqueName).toEqual(name + "_001");
215 test('isAlreadyExist - send new name should return false', () => {
216 service.existingNames = {
217 "2017488_pasqualevpe": "",
218 "uniqueinstancename": ""
220 const name = "uniqueinstancename-1";
221 let isExist: boolean = service.isAlreadyExists(name, service.existingNames);
222 expect(isExist).toBeFalsy();
225 test('isAlreadyExist - send existing name should return true', () => {
226 service.existingNames = {
227 "2017488_pasqualevpe": "",
228 "uniqueinstancename-1": ""
230 const name = "uniqueinstancename-1";
231 let isExist: boolean = service.isAlreadyExists(name, service.existingNames);
232 expect(isExist).toBeTruthy();
235 test('isAlreadyExist - send existing name case insensitive should return true', () => {
236 service.existingNames = {
237 "2017488_pasqualevpe": "",
238 "uniqueinstancename-1": ""
240 const name = "uniqueInstanceName-1";
241 let isExist: boolean = service.isAlreadyExists(name, service.existingNames);
242 expect(isExist).toBeTruthy();
245 test('getNumberAsPaddingString should return 001 if padding is 000 and val is 1 string', () => {
246 let paddingNumber: string = service.getNumberAsPaddingString(1, '0000');
247 expect(paddingNumber).toEqual('0001');
250 test('getNumberAsPaddingString should return 010 if padding is 000 and val is 10 string', () => {
251 let paddingNumber: string = service.getNumberAsPaddingString(10, '0000');
252 expect(paddingNumber).toEqual('0010');
255 test('generateVNFUniqueName should return the next free number', () => {
256 const vnfName: string = "VF_vGeraldine 0";
257 let result: string = service.generateUniqueStoreKey(
258 "6e59c5de-f052-46fa-aa7e-2fca9d674c44",
264 expect(result).toEqual(vnfName + ":0003");
267 test('generateVNFUniqueName on duplicate multi vnfs should return the next free number', () => {
268 spyOn(service, 'openDuplicateModal');
269 service.openDuplicateModal(null, null, null,null, 2, null, null);
271 expect(service.openDuplicateModal).toHaveBeenCalledWith(null, null, null,null, 2, null, null);
275 test('isEnabled should return false if node has missing data', () => {
286 let result : boolean = service.isEnabled(<any>node, null, null);
287 expect(result).toBeFalsy();
290 test('isEnabled should return true if not reach to max', () => {
293 missingData: false, modelName : "vnfModelName" , modelId : "vnfModelId", type : "VF", children: [], modelCustomizationId : "vnfModelId",modelUniqueId: "vnfModelId",
301 let result : boolean = service.isEnabled(<any>node, <any>getStoreState(), "serviceId");
302 expect(result).toBeTruthy();
305 test('isEnabled should return false if reach to max', () => {
308 missingData: false, modelName : "vnfModelName2" , modelId : "vnfModelId2", type : "VF" ,children: [],
316 let result : boolean = service.isEnabled(<any>node, <any>getStoreState(), "serviceId");
317 expect(result).toBeFalsy();
320 test('isEnabled should return true if max is null', () => {
323 missingData: false, modelName : "vnfModelName3" , modelId : "vnfModelId3",type : "VF", children: [], modelUniqueId: "vnfModelId3",
331 let result : boolean = service.isEnabled(<any>node, <any>getStoreState(), "serviceId");
332 expect(result).toBeTruthy();
335 test('isEnabled should return false if type is vf module', () => {
338 missingData: false, modelName : "vnfModelName3" , modelId : "vnfModelId3",type : "VFModule", children: [],
343 let result : boolean = service.isEnabled(<any>node, <any>getStoreState(), "serviceId");
344 expect(result).toBeFalsy();
347 test('getRemainsVNFinstance should return the remains 1 VNF', () => {
348 let result : number = service.getRemainsInstance("vnfModelId", "vnfModelName" , "serviceId" , <any>getStoreState(), <any>{data : {type : 'VF'}});
349 expect(result).toBe(1);
352 test('getRemainsVNFinstance should return the remains 0 VNF', () => {
353 let result : number = service.getRemainsInstance("vnfModelId2", "vnfModelName2" , "serviceId" , <any>getStoreState(),<any>{data : {type : 'VF'}});
354 expect(result).toBe(0);
357 test('isVNFChildrensHasMissingData should return true if vnf missing data = true', () => {
358 let result : boolean = service.hasMissingData(<any>getTreeNode(true,false));
359 expect(result).toBeTruthy();
362 test('isVNFChildrensHasMissingData return should false if vnf missing data = false', () => {
363 let result : boolean = service.hasMissingData(<any>getTreeNode(false,false));
364 expect(result).toBeFalsy();
367 test('isVNFChildrensHasMissingData should return true if vfModule missing data = true', () => {
368 let result : boolean = service.hasMissingData(<any>getTreeNode(false,true));
369 expect(result).toBeTruthy();
372 test('isVNFChildrensHasMissingData should return false if no children and vfModule missing data = false', () => {
373 let node = <any>getTreeNode(false,false);
374 node.data.children = [];
375 let result : boolean = service.hasMissingData(node);
376 expect(result).toBeFalsy();
379 function getExistingVNFs(){
380 return {"VF_vGeraldine 0":{"rollbackOnFailure":"true","vfModules":{"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1":{"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1dgbxq":{"modelInfo":{"modelInvariantId":"98a7c88b-b577-476a-90e4-e25a5871e02b","modelVersionId":"522159d5-d6e0-4c2a-aa44-5a542a12a830","modelName":"VfVgeraldine..vflorence_vlc..module-1","modelVersion":"2","modelCustomizationId":"55b1be94-671a-403e-a26c-667e9c47d091","modelCustomizationName":"VfVgeraldine..vflorence_vlc..module-1"},"instanceParams":[{}]}}},"productFamilyId":"17cc1042-527b-11e6-beb8-9e71128cae77","lcpCloudRegionId":"hvf6","tenantId":"bae71557c5bb4d5aac6743a4e5f1d054","lineOfBusiness":"ONAP","platformName":"platform","modelInfo":{"modelInvariantId":"4160458e-f648-4b30-a176-43881ffffe9e","modelVersionId":"d6557200-ecf2-4641-8094-5393ae3aae60","modelName":"VF_vGeraldine","modelVersion":"2.0","modelCustomizationId":"91415b44-753d-494c-926a-456a9172bbb9","modelCustomizationName":"VF_vGeraldine 0"}},"VF_vGeraldine 0:0001":{"rollbackOnFailure":"true","vfModules":{"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1":{"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1dgbxq":{"modelInfo":{"modelInvariantId":"98a7c88b-b577-476a-90e4-e25a5871e02b","modelVersionId":"522159d5-d6e0-4c2a-aa44-5a542a12a830","modelName":"VfVgeraldine..vflorence_vlc..module-1","modelVersion":"2","modelCustomizationId":"55b1be94-671a-403e-a26c-667e9c47d091","modelCustomizationName":"VfVgeraldine..vflorence_vlc..module-1"},"instanceParams":[{}]}}},"productFamilyId":"17cc1042-527b-11e6-beb8-9e71128cae77","lcpCloudRegionId":"hvf6","tenantId":"bae71557c5bb4d5aac6743a4e5f1d054","lineOfBusiness":"ONAP","platformName":"platform","modelInfo":{"modelInvariantId":"4160458e-f648-4b30-a176-43881ffffe9e","modelVersionId":"d6557200-ecf2-4641-8094-5393ae3aae60","modelName":"VF_vGeraldine","modelVersion":"2.0","modelCustomizationId":"91415b44-753d-494c-926a-456a9172bbb9","modelCustomizationName":"VF_vGeraldine 0"},"originalName":"VF_vGeraldine 0"},"VF_vGeraldine 0:0002":{"rollbackOnFailure":"true","vfModules":{"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1":{"vf_vgeraldine0..VfVgeraldine..vflorence_vlc..module-1dgbxq":{"modelInfo":{"modelInvariantId":"98a7c88b-b577-476a-90e4-e25a5871e02b","modelVersionId":"522159d5-d6e0-4c2a-aa44-5a542a12a830","modelName":"VfVgeraldine..vflorence_vlc..module-1","modelVersion":"2","modelCustomizationId":"55b1be94-671a-403e-a26c-667e9c47d091","modelCustomizationName":"VfVgeraldine..vflorence_vlc..module-1"},"instanceParams":[{}]}}},"productFamilyId":"17cc1042-527b-11e6-beb8-9e71128cae77","lcpCloudRegionId":"hvf6","tenantId":"bae71557c5bb4d5aac6743a4e5f1d054","lineOfBusiness":"ONAP","platformName":"platform","modelInfo":{"modelInvariantId":"4160458e-f648-4b30-a176-43881ffffe9e","modelVersionId":"d6557200-ecf2-4641-8094-5393ae3aae60","modelName":"VF_vGeraldine","modelVersion":"2.0","modelCustomizationId":"91415b44-753d-494c-926a-456a9172bbb9","modelCustomizationName":"VF_vGeraldine 0"},"originalName":"VF_vGeraldine 0"}}
383 function getStoreState(){
393 ecomp_generated_naming: "false",
399 ecomp_generated_naming: "false",
405 ecomp_generated_naming: "false",
413 existingVNFCounterMap : {
428 function getTreeNode(VNfMissingData : boolean, vfModuleMissingData : boolean){
431 children : vfModuleMissingData ?
439 missingData : VNfMissingData