diff options
Diffstat (limited to 'src/app/test')
-rw-r--r-- | src/app/test/test.component.html | 25 | ||||
-rw-r--r-- | src/app/test/test.component.spec.ts | 345 | ||||
-rw-r--r-- | src/app/test/test.component.ts | 186 |
3 files changed, 370 insertions, 186 deletions
diff --git a/src/app/test/test.component.html b/src/app/test/test.component.html index ad6ff7f..3519007 100644 --- a/src/app/test/test.component.html +++ b/src/app/test/test.component.html @@ -32,16 +32,6 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <input class="form-control" type="text" disabled value="{{action}}" /> </div> - <!-- <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> - <label>Vnf Type:</label> - <input class="form-control" type="text" disabled value="{{vnfType}}" /> - - </div> - <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> - <label>Vnfc Type:</label> - <input class="form-control" type="text" disabled value="{{vnfcType}}" /> - - </div>--> <div class="col-lg-3 col-sm-6 col-md-4 col-xs-12"> <label>Vnf Id:</label> <input class="form-control" type="text" [(ngModel)]="this.actionIdentifiers['vnf-id']" /> @@ -54,11 +44,6 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. </div> - <!-- <div class="col-lg-3 col-sm-6 col-md-3 col-xs-12"> - <label>VF-Module-Id(optional):</label> - <input class="form-control" disabled type="text" value="{{this.actionIdentifiers['vmodule-id']}}" /> - - </div>--> <div class="col-12"> <div class="input-group"> @@ -113,14 +98,9 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <div class="col-md-12"> <div class="row justify-content-center" style="padding-top:0.3cm"> - - <!-- <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button" (click)="clearLog()">Abort Test</button> --> - <button style="margin-left:6%;" [disabled]="!enableTestButton" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary" type="submit" (click)="testVnf()">Execute Test </button> - <!-- <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button" (click)="abortTest()">Abort Test</button> --> - <!--button class="btn btn-primary" type="submit"> Save Revised Name/Value Pair to APPC</button--> - + </div> </div> @@ -130,8 +110,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. </div> <div style="padding-left:60%;padding-bottom:0.5cm"> - <!-- <a href="javascript:void(0)" style="color:darkblue; text-decoration: double; font-size: 15px;" (click)="download()">Download Raw Request/Response.</a>--> - <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary" type="button" (click)="download()">Download Raw Request/Response + <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--primary" type="button" [disabled]="!enableDownload" (click)="download()">Download Raw Request/Response </button> <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" type="button" [disabled]="!enableAbort" (click)="abortTest()">Abort Test </button> diff --git a/src/app/test/test.component.spec.ts b/src/app/test/test.component.spec.ts index 8d96554..e07ff93 100644 --- a/src/app/test/test.component.spec.ts +++ b/src/app/test/test.component.spec.ts @@ -21,9 +21,6 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. ============LICENSE_END============================================ */ -/* tslint:disable:no-unused-variable */ - -// Modules import { async, ComponentFixture, TestBed,inject } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { DebugElement } from '@angular/core'; @@ -31,23 +28,32 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { RouterTestingModule } from '@angular/router/testing'; import { SimpleNotificationsModule } from 'angular2-notifications'; import { Http, Response, Headers, RequestOptions, HttpModule } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import { Subscription } from 'rxjs/Subscription'; +import 'rxjs/add/observable/from'; +import 'rxjs/add/observable/empty'; +import 'rxjs/add/observable/throw'; -// Component import { TestComponent } from './test.component'; - -// Services import { NotificationService } from '../shared/services/notification.service'; import { ParamShareService } from '.././shared/services/paramShare.service'; import { MappingEditorService } from '../shared/services/mapping-editor.service'; import { HttpUtilService } from '../shared/services/httpUtil/http-util.service'; import { UtilityService } from '../shared/services/utilityService/utility.service'; +import { environment } from '../.././environments/environment'; import { NgProgress } from 'ngx-progressbar'; -import {NgProgressModule} from 'ngx-progressbar'; +import { NgProgressModule } from 'ngx-progressbar'; + +class MockService { + doStuff() { + return this; + } +} describe( 'TestComponent', () => { let component: TestComponent; let fixture: ComponentFixture<TestComponent>; - + let http = new MockService(); beforeEach(async(() => { TestBed.configureTestingModule({ @@ -60,12 +66,13 @@ describe( 'TestComponent', () => { NgProgressModule ], providers: [ - NotificationService, + NotificationService, ParamShareService, MappingEditorService, HttpUtilService, UtilityService, - NgProgress + NgProgress, + {provide: Http, useValue: http} ] }) .compileComponents(); @@ -77,82 +84,300 @@ describe( 'TestComponent', () => { fixture.detectChanges(); }); - it( 'should create', () => { - expect(component).toBeTruthy(); - }); + it('should ...', inject([HttpUtilService], (service: HttpUtilService) => { + let spy = spyOn(service, 'post').and.returnValue(Observable.empty()); + fixture.detectChanges(); // onInit() - // it('test', () => { - // expect(2).toEqual(1) - // }); + component.pollTestStatus(); + + expect(service).toBeTruthy(); + expect(spy).toHaveBeenCalled(); + expect(spy.calls.any()).toBe(true, 'test'); + })); + + // Test download Method + describe('Test download Method', () => { + it('Should have download method', () => { + expect(component.download).toBeDefined(); + }); + + it('test if apiRequest if true', inject( [SimpleNotificationsModule], (service: SimpleNotificationsModule) => { + component.apiRequest = '{"input":{"common-header":{"timestamp":"2018-03-05T07:41:14.329Z","api-ver":"2.00","originator-id":"CDT","request-id":"1520235674330","sub-request-id":"1520235674330","flags":{"mode":"NORMAL","force":"TRUE","ttl":3600}},"action":"ConfigModify","action-identifiers":{"vnf-id":"testVnf","vserver-id":"test"},"payload":""'; + component.apiResponse = ''; + component.action = 'ConfigModify'; + component.actionIdentifiers['vnf-id'] = 'testVnf'; + let fileName = 'test_' + component.action + '_' + component.actionIdentifiers['vnf-id'] + '_request'; + let theJSON = component.apiRequest; + var blob = new Blob([theJSON], { + type: 'text/json' + }); + + component.download(); + expect(service instanceof SimpleNotificationsModule).toBeTruthy(); + expect(component.apiRequest).not.toBe(''); + expect(fileName).not.toBe(''); + expect(fileName).not.toBeNull(); + expect(fileName).toContain('test_'); + expect(fileName).toContain('_request'); + expect(typeof (blob)).toBe('object'); - // it('test preparfilename', inject([MappingEditorService], (mappingEditorService: MappingEditorService) => { - // // fixture = TestBed.createComponent(TestComponent); - // // component = fixture.componentInstance; - // mappingEditorService.latestAction=undefined + })); - // expect(component.prepareFileName()).toBe(undefined); - // })); + it('test method if apiResponse is true', () => { + component.apiResponse = '{"input":{"common-header":{"timestamp":"2018-03-05T07:41:14.329Z","api-ver":"2.00","originator-id":"CDT","request-id":"1520235674330","sub-request-id":"1520235674330","flags":{"mode":"NORMAL","force":"TRUE","ttl":3600}},"action":"ConfigModify","action-identifiers":{"vnf-id":"testvnf","vserver-id":"test"},"payload":""'; + component.apiRequest = ''; + component.action = 'ConfigModify'; + component.actionIdentifiers['vnf-id'] = 'testvnf'; + let fileName = 'test_' + component.action + '_' + component.actionIdentifiers['vnf-id'] + '_response'; + let theJSON = component.apiRequest; + var blob = new Blob([theJSON], { + type: 'text/json' + }); + component.download(); - it('Should have download method', () => { - expect(component.download).toBeDefined(); + expect(component.apiResponse).not.toBe(''); + expect(fileName).not.toBe(''); + expect(fileName).not.toBeNull(); + expect(fileName).toContain('test_'); + expect(fileName).toContain('_response'); + expect(typeof (blob)).toBe('object'); + + }); }); // Test abortTest Method - it('Should have abortTest method', () => { - expect(component.abortTest).toBeDefined(); + describe('Test abortTest Method', () => { + it('Should have abortTest method', () => { + expect(component.abortTest).toBeDefined(); + }); + + it('Test abortTest Method', () => { + const temp = component.abortTest(); + expect(component.enableBrowse).toBeTruthy(); + expect(component.enableTestButton).toBeTruthy(); + expect(component.enablePollButton).toBeTruthy(); + }); }); - it('Test abortTest Method', () => { - const temp = component.abortTest(); - expect(component.enableBrowse).toBeTruthy(); - expect(component.enableTestButton).toBeTruthy(); + // Test excelBrowseOption Method + describe('Test excelBrowseOption Method', () => { + it('test excelBrowseOption', () => { + spyOn(component, 'excelBrowseOption'); + let button = fixture.debugElement.query(By.css('#excelInputFile ~ button.browse')); + button.nativeElement.click(); + expect(component.excelBrowseOption).toHaveBeenCalled() + }); }); - it('Should have excelBrowseOption method', () => { - expect(component.excelBrowseOption).toBeDefined(); + // Test Upload Method + describe('Test Upload Method', () => { + it('Should have upload method', () => { + expect(component.upload).toBeDefined(); + }); + + it('should execute if file extension is XLS, XLSX', () => { + let fileExtension = 'XLS'; + let event = { isTrusted: true, type: "change", target: {files: [{name:'foo.XLS', size: 500001}]} } + let reader = new FileReader(); + spyOn(reader, 'onload'); + + component.upload(event); + + expect(reader instanceof FileReader).toBeTruthy(); + expect(reader.onload).toHaveBeenCalled(); + expect(component.enableTestButton).toBeTruthy(); + console.log('aaa',component.enableTestButton, component.uploadFileName); + }); + + it('should return an error if file extension is not XLS, XLSX', () => { + spyOn(component, 'upload'); + let ele = fixture.debugElement.query(By.css('#filesparam')); + const target = { files: ['']}; + component.uploadFileName = 'test.doc'; + let fileExtension = 'DOC'; + component.upload('change'); + + expect(target.files.length).toEqual(1) + expect(fileExtension).not.toBe('XLS'); + expect(fileExtension).not.toBe('XLSX'); + }); }); - it('Should have upload method', () => { - expect(component.upload).toBeDefined(); + // Test processUploadedFile Method + describe('Test processUploadedFile Method', () => { + it('should return valid payload', () => { + let data = [ + {"TagName":"action","Value":"ConfigModify"}, + {"List Name":"action-identifiers","TagName":"vserver-id","Value":"test"}, + {"List Name":"payload","List Name_1":"request-parameters","TagName":"vnf-name","Value":"testVnf"}, + {"List Name":"payload","List Name_1":"request-parameters","List Name_2":"[vm]","List Name_3":"vnfc","TagName":"vnfc-name","Value":"testVnfcName"}, + {"List Name":"payload","List Name_1":"configuration-parameters","TagName":"testConfigParam","Value":"testConfigValue"} + ] + + let payload = component.processUploadedFile(data); + }); }); - it('Should have constructTestPayload method', () => { - expect(component.constructTestPayload).toBeDefined(); + // Test uploadedFileResult Method + describe('Test uploadedFileResult', () => { + it('should return success message', inject([SimpleNotificationsModule],(service: SimpleNotificationsModule) => { + component.action = 'ConfigModify'; + component.actionIdentifiers['vnf-id'] = 'testvnf'; + + component.uploadedFileResult(); + + expect(service instanceof SimpleNotificationsModule).toBeTruthy(); + })); + + it('should return error message', inject([SimpleNotificationsModule], (service: SimpleNotificationsModule) => { + component.action = ''; + component.actionIdentifiers['vnf-id'] = ''; + + component.uploadedFileResult(); + + expect(service instanceof SimpleNotificationsModule).toBeTruthy(); + })); }); - it('Should have constructRequest method', () => { - expect(component.constructRequest).toBeDefined(); + // Test constructTestPayload Method + describe('Test constructTestPayload Method', () => { + //3rd , 4th columnd, tag name , tag value + it('Should have constructTestPayload method', () => { + expect(component.constructTestPayload).toBeDefined(); + }); + + it('test if listName2, listName3 are undefined', () => { + let temp = component.constructTestPayload(undefined, undefined, 'vnfc-type', 'testvnfc'); + expect(component.subPayload['vnfc-type']).toEqual('testvnfc') + }); + + it('test if lastName2 is not undefined', () => { + let temp = component.constructTestPayload(['vm'], undefined, 'vnfc-type', 'testvnfc'); + expect(typeof(component.vmJson)).toEqual('object'); + expect(typeof(component.vnfcJson)).toEqual('object'); + expect(component.vmJson['vnfc-type']).toBe('testvnfc'); + expect(component.flag).toBe(0); + }); + + it('test if lastNmae2, lastName3 are not undefined', () => { + let temp = component.constructTestPayload(['vm'], 'vnfc', 'vnfc-type', 'testvnfc'); + expect(component.vnfcJson['vnfc-type']).toEqual('testvnfc'); + expect(component.vmJson['vnfc']['vnfc-type']).toEqual('testvnfc'); + expect(component.flag).toBe(1); + }) }); - it('Should have testVnf method', () => { - expect(component.testVnf).toBeDefined(); + // Test constructRequest Method + describe('Test constructRequest Method', () => { + it('Should have constructRequest method', () => { + expect(component.constructRequest).toBeDefined(); + }); + + it('test method', () => { + let temp = component.constructRequest(); + }); }); - it('Should have pollTestStatus method', () => { - expect(component.pollTestStatus).toBeDefined(); + // Test testVnf Method + describe('Test testVnf Method', () => { + it('Should have testVnf method', () => { + expect(component.testVnf).toBeDefined(); + }); + + it('should return response on success', inject([HttpUtilService, NgProgress], (httpUtilService: HttpUtilService, ngProgress: NgProgress) => { + let spy = spyOn(httpUtilService, 'post').and.callFake( ({}) => { + return Observable.empty(); + }); + component.action = 'ConfigModify'; + + component.testVnf(); + expect(component.enableBrowse).toBeFalsy() + expect(component.enableTestButton).toBeFalsy(); + expect(component.enablePollButton).toBeFalsy(); + expect(spy).toHaveBeenCalled(); + })); + + it('should return an error if fails', inject([HttpUtilService],( httpUtilService: HttpUtilService) => { + let error = 'Error in connecting to APPC Server'; + let spy = spyOn(httpUtilService, 'post').and.returnValue(Observable.throw(error)); + component.action = 'ConfigModify'; + + component.testVnf(); + + expect(spy).toHaveBeenCalled(); + expect(component.enableBrowse).toBeTruthy(); + expect(component.enableTestButton).toBeTruthy(); + expect(component.enablePollButton).toBeTruthy(); + expect(component.enableCounterDiv).toBeFalsy(); + })); + + it('test setTimeout', inject([NgProgress], (ngProgress: NgProgress) => { + let spy = spyOn(ngProgress, 'done'); + component.action = 'ConfigModify'; + + component.testVnf(); + + })); }); + // Test pollTestStatus Method + describe('Test pollTestStatus Method', () => { + it('Should have pollTestStatus method', () => { + expect(component.pollTestStatus).toBeDefined(); + }); - // Test getUrlEndPoint Method - it('Should have getUrlEndPoint method', () => { - expect(component.getUrlEndPoint).toBeDefined(); + it('test method', () => { + let temp = component.pollTestStatus(); + let requestId = new Date().getTime().toString(); + let actionIdentifiers = 123456; + }); + + it('should call fake server', inject([HttpUtilService], (httpUtilService: HttpUtilService) => { + let spy = spyOn(httpUtilService, 'post').and.callFake(({}) => { + return Observable.empty(); + }); + + component.pollTestStatus(); + + expect(spy).toHaveBeenCalled(); + })); + + it('should return an error if fails', inject([HttpUtilService], (httpUtilService: HttpUtilService) => { + let error = 'Error Connecting to APPC server'; + let spy = spyOn(httpUtilService, 'post').and.callFake( ({}) => { + return Observable.throw(error); + }); + component.requestId = null; + component.actionIdentifiers['vnf-id'] = false; + + component.pollTestStatus(); + + expect(spy).toHaveBeenCalled(); + })); }); + + // Test getUrlEndPoint Method + describe('Test getUrlEndPoint Method', () => { + it('Should have getUrlEndPoint method', () => { + expect(component.getUrlEndPoint).toBeDefined(); + }); - it('getUrlEndPoint Should return value', () => { - expect(component.getUrlEndPoint('configmodify')).toEqual('config-modify'); - expect(component.getUrlEndPoint('configbackup')).toEqual('config-backup'); - expect(component.getUrlEndPoint('configrestore')).toEqual('config-restore'); - expect(component.getUrlEndPoint('healthcheck')).toEqual('health-check'); - expect(component.getUrlEndPoint('quiescetraffic')).toEqual('quiesce-traffic'); - expect(component.getUrlEndPoint('resumetraffic')).toEqual('resume-traffic'); - expect(component.getUrlEndPoint('startapplication')).toEqual('start-application'); - expect(component.getUrlEndPoint('stopapplication')).toEqual('stop-application'); - expect(component.getUrlEndPoint('upgradebackout')).toEqual('upgrade-backout'); - expect(component.getUrlEndPoint('upgradepostcheck')).toEqual('upgrade-post-check'); - expect(component.getUrlEndPoint('upgradeprecheck')).toEqual('upgrade-pre-check'); - expect(component.getUrlEndPoint('upgradesoftware')).toEqual('upgrade-software'); - expect(component.getUrlEndPoint('DeFaultCASE')).toEqual('defaultcase'); + it('getUrlEndPoint Should return value', () => { + expect(component.getUrlEndPoint('configmodify')).toEqual('config-modify'); + expect(component.getUrlEndPoint('configbackup')).toEqual('config-backup'); + expect(component.getUrlEndPoint('configrestore')).toEqual('config-restore'); + expect(component.getUrlEndPoint('healthcheck')).toEqual('health-check'); + expect(component.getUrlEndPoint('quiescetraffic')).toEqual('quiesce-traffic'); + expect(component.getUrlEndPoint('resumetraffic')).toEqual('resume-traffic'); + expect(component.getUrlEndPoint('startapplication')).toEqual('start-application'); + expect(component.getUrlEndPoint('stopapplication')).toEqual('stop-application'); + expect(component.getUrlEndPoint('upgradebackout')).toEqual('upgrade-backout'); + expect(component.getUrlEndPoint('upgradepostcheck')).toEqual('upgrade-post-check'); + expect(component.getUrlEndPoint('upgradeprecheck')).toEqual('upgrade-pre-check'); + expect(component.getUrlEndPoint('upgradesoftware')).toEqual('upgrade-software'); + expect(component.getUrlEndPoint('DeFaultCASE')).toEqual('defaultcase'); + }); }); -}) +})
\ No newline at end of file diff --git a/src/app/test/test.component.ts b/src/app/test/test.component.ts index 1874904..411b057 100644 --- a/src/app/test/test.component.ts +++ b/src/app/test/test.component.ts @@ -101,6 +101,7 @@ export class TestComponent implements OnInit { public enablePollButton: boolean = true; public pollCounter = 0; public enableCounterDiv: boolean = false; + public enableDownload: boolean = false; constructor(private location: Location, private activeRoutes: ActivatedRoute, private notificationService: NotificationService, private nService: NotificationsService, private router: Router, private paramShareService: ParamShareService, private mappingEditorService: MappingEditorService, private httpUtil: HttpUtilService, private utiltiy: UtilityService, private ngProgress: NgProgress) { @@ -112,20 +113,6 @@ export class TestComponent implements OnInit { } - prepareFileName(): any { - let fileNameObject: any = this.mappingEditorService.latestAction; - return fileNameObject; - } - - /*public download() { - let stringData: any; - stringData = JSON.stringify(this.paramShareService.getSessionParamData()); - let paramsKeyValueFromEditor: JSON; - paramsKeyValueFromEditor = JSON.parse(stringData); - let fileName = 'param_' + this.action + '_' + this.type + '_' + "0.0.1" + 'V'; - this.JSONToCSVConvertor([paramsKeyValueFromEditor], fileName, true); - - }*/ public download() { if (this.apiRequest) { @@ -166,40 +153,6 @@ export class TestComponent implements OnInit { } - /*JSONToCSVConvertor(JSONData, fileName, ShowLabel) { - //If JSONData is not an object then JSON.parse will parse the JSON string in an Object - var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData; - - var CSV = ''; - - //This condition will generate the Label/Header - if (ShowLabel) { - var testRow = ""; - for (var index in arrData[0]) { - - CSV += arrData[0][index].name + '\t' + arrData[0][index].value + '\t' + arrData[0][index].source + '\r\n'; - } - } - - if (CSV == '') { - alert("Invalid data"); - return; - } - - //Initialize file format you want csv or xls - var uri = 'data:application/vnd.ms-excel,' + encodeURI(CSV); - - var link = document.createElement("a"); - link.href = uri; - - link.download = fileName + ".xls"; - - //this part will append the anchor tag and remove it after automatic click - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); - }*/ - excelBrowseOption() { $('#excelInputFile').trigger('click'); } @@ -209,7 +162,7 @@ export class TestComponent implements OnInit { /* wire up file reader */ $('#filesparam').trigger('click'); const target: DataTransfer = <DataTransfer>(evt.target); - + this.pollCounter = 0; this.uploadFileName = evt.target.files[0].name; var fileExtension = this.uploadFileName.substr(this.uploadFileName.lastIndexOf('.') + 1); @@ -241,9 +194,9 @@ export class TestComponent implements OnInit { this.showStatusResponseDiv = false; this.errorResponse = ''; this.statusResponse = ''; - + this.enableDownload=true; let arrData = (<AOA>(XLSX.utils.sheet_to_json(ws, { blankrows: false }))); - this.nService.success('Success', 'SpreadSheet uploaded successfully'); + console.log('Array data ==' + arrData[0]); @@ -254,53 +207,84 @@ export class TestComponent implements OnInit { this.payload = {}; this.oldListName1 = ''; this.actionIdentifiers = {}; - for (var i = 0; i < arrData.length; i++) { - var element = arrData[i]; - if (element['TagName'] === 'action') { - this.action = element['Value']; - } - if (element['List Name'] === 'action-identifiers') { - this.vnfId = element['Value']; - var key = element['TagName']; - var value = element['Value']; - if (key && value) { - this.actionIdentifiers[key] = value; + // Refactor + this.payload = this.processUploadedFile(arrData); + this.uploadedFileResult(); + }; - } - } + reader.readAsBinaryString(target.files[0]); + - if (element['List Name'] === 'payload') { - var listName1 = element['List Name_1']; - var listName2 = element['List Name_2']; - var listName3 = element['List Name_3']; - var key = element['TagName']; - var value = element['Value']; - if (listName1) { - if (this.oldListName1 == '' || (listName1 === this.oldListName1)) { - this.constructTestPayload(listName2, listName3, key, value); - this.payload[listName1] = this.subPayload; - } - else { - this.subPayload = {}; - this.constructTestPayload(listName2, listName3, key, value); - this.payload[listName1] = this.subPayload; - } - this.oldListName1 = listName1; - } - else { - this.payload[key] = value; - } + } + else { + this.nService.error('Error', 'Incorrect spreadsheet uploaded'); + this.flag = 1; + this.oldListName1 = ''; + this.vmJson = {}; + this.vnfcJson = {}; + this.subPayload = {}; + this.vmPayload = []; + this.payload = {}; + this.action = ''; + this.actionIdentifiers = {}; + this.apiRequest = ''; + this.apiResponse = ''; + this.enableCounterDiv = false; + this.enableAbort = false; + this.enableTestButton = false; + this.enableDownload = false; + } + } + +processUploadedFile(arrData) { + let tempPayload = {}; + for (var i = 0; i < arrData.length; i++) { + var element = arrData[i]; + if (element['TagName'] === 'action') { + this.action = element['Value']; + } + if (element['List Name'] === 'action-identifiers') { + this.vnfId = element['Value']; + var key = element['TagName']; + var value = element['Value']; + if (key && value) { + this.actionIdentifiers[key] = value; + + } + } + + if (element['List Name'] === 'payload') { + var listName1 = element['List Name_1']; + var listName2 = element['List Name_2']; + var listName3 = element['List Name_3']; + var key = element['TagName']; + var value = element['Value']; + if (listName1) { + if (this.oldListName1 == '' || (listName1 === this.oldListName1)) { + this.constructTestPayload(listName2, listName3, key, value); + tempPayload[listName1] = this.subPayload; + } + else { + this.subPayload = {}; + this.constructTestPayload(listName2, listName3, key, value); + tempPayload[listName1] = this.subPayload; } + this.oldListName1 = listName1; } + else { + tempPayload[key] = value; + } + } + } - //console.log("VM JSON===" + JSON.stringify(this.vmPayload)) - // console.log('VM payload===' + JSON.stringify(this.payload)); - }; + return tempPayload; + } - reader.readAsBinaryString(target.files[0]); + uploadedFileResult() { + if (this.action && this.actionIdentifiers['vnf-id']) { + this.nService.success('Success', 'SpreadSheet uploaded successfully'); } else { - this.nService.error('Error', 'Incorrect spreadsheet uploaded'); this.flag = 1; this.oldListName1 = ''; this.vmJson = {}; @@ -313,9 +297,15 @@ export class TestComponent implements OnInit { this.apiRequest = ''; this.apiResponse = ''; this.enableCounterDiv = false; + this.enableAbort = false; + this.enableTestButton = false; + this.enableDownload = false; + this.nService.error("Error", "Please check the contents of the file uploaded") } } + + constructTestPayload(listName2, listName3, key, value) { if (listName2 == undefined && listName3 == undefined) { this.subPayload[key] = value; @@ -373,9 +363,6 @@ export class TestComponent implements OnInit { } testVnf() { - //let payload = '{"request-parameters":{"vnf-host-ip-address":"' + this.host + '"},"configuration-parameters":"' + JSON.stringify(this.formattedNameValuePairs) + '"}"'; - //let payload = '{"request-parameters":{"host-ip-address:"' + this.host + '",port-number:"'+port+'"}}'; - this.enableBrowse = false; this.enableTestButton = false; this.enablePollButton = false; @@ -412,9 +399,7 @@ export class TestComponent implements OnInit { pollTestStatus() { if (this.requestId && this.actionIdentifiers['vnf-id']) { - // console.log("payload==" + JSON.stringify(this.payload)) let timeStamp = new Date().toISOString(); - // console.log("timestamp==" + timeStamp) let reqId = new Date().getTime().toString(); let data = { 'input': { @@ -435,20 +420,17 @@ export class TestComponent implements OnInit { 'payload': '{"request-id":' + this.requestId + '}' } }; - //this.ngProgress.start(); this.httpUtil.post( { url: environment.checkTestStatus, data: data }) .subscribe(resp => { - // console.log('Response==' + JSON.stringify(resp)); this.statusResponse = JSON.stringify(resp); var status = '' var statusReason = '' this.enableCounterDiv = true; this.pollCounter++; - //this.statusResponse=JSON.parse(this.statusResponse) if (resp.output) var timeStamp = resp.output['common-header'].timestamp; if (resp.output.payload) { var payload = resp.output.payload.replace(/\\/g, "") @@ -466,7 +448,7 @@ export class TestComponent implements OnInit { this.outputTimeStamp = timeStamp; this.status = status; this.statusReason = statusReason; - if (status.toUpperCase() === 'SUCCESS') { + if (status.toUpperCase() === 'SUCCESS' || status.toUpperCase() === 'SUCCESSFUL') { this.subscribe.unsubscribe(); this.enablePollButton = true; } @@ -479,7 +461,7 @@ export class TestComponent implements OnInit { this.showStatusResponseDiv = false; } - // this.ngProgress.done(); + }, error => { this.statusResponse = null; @@ -493,9 +475,7 @@ export class TestComponent implements OnInit { else { this.nService.error("Error", "Please enter vnf Id & request Id"); } - // setTimeout(() => { - // this.ngProgress.done(); - // }, 3500); + } getUrlEndPoint(action) { |