Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 1 | /* |
| 2 | ============LICENSE_START========================================== |
| 3 | =================================================================== |
| 4 | Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. |
| 5 | =================================================================== |
| 6 | |
| 7 | Unless otherwise specified, all software contained herein is licensed |
| 8 | under the Apache License, Version 2.0 (the License); |
| 9 | you may not use this software 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. |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 19 | ============LICENSE_END============================================ |
| 20 | */ |
| 21 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 22 | /* tslint:disable:no-unused-variable */ |
| 23 | |
| 24 | // Modules |
| 25 | import { async, ComponentFixture, TestBed,inject } from '@angular/core/testing'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 26 | import { By } from '@angular/platform-browser'; |
| 27 | import { DebugElement } from '@angular/core'; |
| 28 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
| 29 | import { RouterTestingModule } from '@angular/router/testing'; |
| 30 | import { SimpleNotificationsModule } from 'angular2-notifications'; |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 31 | import { Http, Headers, HttpModule, BaseRequestOptions, Response, ResponseOptions } from '@angular/http'; |
| 32 | import { MockBackend, MockConnection } from '@angular/http/testing'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 33 | import { Observable } from 'rxjs/Observable'; |
| 34 | import { Subscription } from 'rxjs/Subscription'; |
| 35 | import 'rxjs/add/observable/from'; |
| 36 | import 'rxjs/add/observable/empty'; |
| 37 | import 'rxjs/add/observable/throw'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 38 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 39 | // Component |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 40 | import { TestComponent } from './test.component'; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 41 | |
| 42 | // Services |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 43 | import { NotificationService } from '../shared/services/notification.service'; |
| 44 | import { ParamShareService } from '.././shared/services/paramShare.service'; |
| 45 | import { MappingEditorService } from '../shared/services/mapping-editor.service'; |
| 46 | import { HttpUtilService } from '../shared/services/httpUtil/http-util.service'; |
| 47 | import { UtilityService } from '../shared/services/utilityService/utility.service'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 48 | import { environment } from '../.././environments/environment'; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 49 | import { NgProgress } from 'ngx-progressbar'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 50 | import { NgProgressModule } from 'ngx-progressbar'; |
| 51 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 52 | describe( 'TestComponent', () => { |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 53 | let component: TestComponent; |
| 54 | let fixture: ComponentFixture<TestComponent>; |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 55 | |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 56 | beforeEach(async(() => { |
| 57 | TestBed.configureTestingModule({ |
| 58 | declarations: [TestComponent], |
| 59 | imports: [ |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 60 | FormsModule, |
| 61 | RouterTestingModule, |
| 62 | SimpleNotificationsModule, |
| 63 | HttpModule, |
| 64 | NgProgressModule |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 65 | ], |
| 66 | providers: [ |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 67 | NotificationService, |
| 68 | ParamShareService, |
| 69 | MappingEditorService, |
| 70 | HttpUtilService, |
| 71 | UtilityService, |
| 72 | NgProgress,MockBackend, BaseRequestOptions, |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 73 | { |
| 74 | provide: Http, |
| 75 | useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => { |
| 76 | return new Http(backend, defaultOptions); |
| 77 | }, |
| 78 | deps: [MockBackend, BaseRequestOptions], |
| 79 | } |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 80 | ] |
| 81 | }) |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 82 | .compileComponents(); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 83 | })); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 84 | |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 85 | beforeEach(() => { |
| 86 | fixture = TestBed.createComponent(TestComponent); |
| 87 | component = fixture.componentInstance; |
| 88 | fixture.detectChanges(); |
| 89 | }); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 90 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 91 | it('should ...', inject([HttpUtilService], (service: HttpUtilService) => { |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 92 | fixture.detectChanges(); // onInit() |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 93 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 94 | component.pollTestStatus(); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 95 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 96 | expect(service).toBeTruthy(); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 97 | })); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 98 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 99 | // Test download Method |
| 100 | describe('Test download Method', () => { |
| 101 | it('Should have download method', () => { |
| 102 | expect(component.download).toBeDefined(); |
| 103 | }); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 104 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 105 | it('test if apiRequest if true', inject( [SimpleNotificationsModule], (service: SimpleNotificationsModule) => { |
| 106 | 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":"ibcx0001","vserver-id":"test"},"payload":""'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 107 | component.apiResponse = ''; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 108 | component.action = 'ConfigModify'; |
| 109 | component.actionIdentifiers['vnf-id'] = 'ibcx0001'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 110 | let fileName = 'test_' + component.action + '_' + component.actionIdentifiers['vnf-id'] + '_request'; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 111 | let theJSON = component.apiRequest; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 112 | var blob = new Blob([theJSON], { |
| 113 | type: 'text/json' |
| 114 | }); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 115 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 116 | component.download(); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 117 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 118 | expect(service instanceof SimpleNotificationsModule).toBeTruthy(); |
| 119 | expect(component.apiRequest).not.toBe(''); |
| 120 | expect(fileName).not.toBe(''); |
| 121 | expect(fileName).not.toBeNull(); |
| 122 | expect(fileName).toContain('test_'); |
| 123 | expect(fileName).toContain('_request'); |
| 124 | expect(typeof (blob)).toBe('object'); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 125 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 126 | })); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 127 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 128 | it('test method if apiResponse is true', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 129 | 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":"ibcx0001","vserver-id":"test"},"payload":""'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 130 | component.apiRequest = ''; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 131 | component.action = 'ConfigModify'; |
| 132 | component.actionIdentifiers['vnf-id'] = 'ibcx0001'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 133 | let fileName = 'test_' + component.action + '_' + component.actionIdentifiers['vnf-id'] + '_response'; |
| 134 | let theJSON = component.apiRequest; |
| 135 | var blob = new Blob([theJSON], { |
| 136 | type: 'text/json' |
| 137 | }); |
| 138 | |
| 139 | component.download(); |
| 140 | |
| 141 | expect(component.apiResponse).not.toBe(''); |
| 142 | expect(fileName).not.toBe(''); |
| 143 | expect(fileName).not.toBeNull(); |
| 144 | expect(fileName).toContain('test_'); |
| 145 | expect(fileName).toContain('_response'); |
| 146 | expect(typeof (blob)).toBe('object'); |
| 147 | |
| 148 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 149 | }); |
Skip Wonnell | 2c977e2 | 2018-03-01 08:30:15 -0600 | [diff] [blame] | 150 | |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 151 | // Test abortTest Method |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 152 | describe('Test abortTest Method', () => { |
| 153 | it('Should have abortTest method', () => { |
| 154 | expect(component.abortTest).toBeDefined(); |
| 155 | }); |
| 156 | |
| 157 | it('Test abortTest Method', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 158 | component.abortTest(); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 159 | expect(component.enableBrowse).toBeTruthy(); |
| 160 | expect(component.enableTestButton).toBeTruthy(); |
| 161 | expect(component.enablePollButton).toBeTruthy(); |
| 162 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 163 | }); |
| 164 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 165 | // Test excelBrowseOption Method |
| 166 | describe('Test excelBrowseOption Method', () => { |
| 167 | it('test excelBrowseOption', () => { |
| 168 | spyOn(component, 'excelBrowseOption'); |
| 169 | let button = fixture.debugElement.query(By.css('#excelInputFile ~ button.browse')); |
| 170 | button.nativeElement.click(); |
| 171 | expect(component.excelBrowseOption).toHaveBeenCalled() |
| 172 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 173 | }); |
| 174 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 175 | // Test Upload Method |
| 176 | describe('Test Upload Method', () => { |
| 177 | it('Should have upload method', () => { |
| 178 | expect(component.upload).toBeDefined(); |
| 179 | }); |
| 180 | |
| 181 | it('should execute if file extension is XLS, XLSX', () => { |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 182 | let reader = new FileReader(); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 183 | let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}) |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 184 | let fileExtension = 'XLS'; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 185 | let event = { isTrusted: true, type: "change", target: {files: [file]} } |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 186 | |
| 187 | component.upload(event); |
| 188 | |
| 189 | expect(reader instanceof FileReader).toBeTruthy(); |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 190 | expect(component.pollCounter).toBe(0) |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 191 | }); |
| 192 | |
| 193 | it('should return an error if file extension is not XLS, XLSX', () => { |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 194 | let reader = new FileReader(); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 195 | let file = new File(["testing"], "foo.doc", {type: ""}) |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 196 | let fileExtension = 'doc'; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 197 | let event = { isTrusted: true, type: "change", target: {files: [file]} } |
| 198 | |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 199 | component.upload(event); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 200 | |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 201 | expect(reader instanceof FileReader).toBeTruthy(); |
| 202 | expect(component.flag).toBe(1) |
| 203 | }); |
| 204 | |
| 205 | it('Should return an error is files length is not equal to 1', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 206 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 207 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 208 | }); |
| 209 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 210 | // Test processUploadedFile Method |
| 211 | describe('Test processUploadedFile Method', () => { |
| 212 | it('should return valid payload', () => { |
| 213 | let data = [ |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 214 | {"TagName":"action","Value":"ConfigModify"}, |
| 215 | {"List Name":"action-identifiers","TagName":"vserver-id","Value":"test"}, |
| 216 | {"List Name":"payload","List Name_1":"request-parameters","TagName":"vnf-name","Value":"ibcx0001"}, |
| 217 | {"List Name":"payload","List Name_1":"request-parameters","List Name_2":"[vm]","List Name_3":"vnfc","TagName":"vnfc-name","Value":"ibcx0001vm001ssc001"}, |
| 218 | {"List Name":"payload","List Name_1":"configuration-parameters","TagName":"CORE_NETWORK_DEFAULT_GATEWAY","Value":"192.168.30.44"} |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 219 | ] |
| 220 | |
| 221 | let payload = component.processUploadedFile(data); |
| 222 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 223 | }); |
| 224 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 225 | // Test uploadedFileResult Method |
| 226 | describe('Test uploadedFileResult', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 227 | it('should return success message', inject([SimpleNotificationsModule],(service: SimpleNotificationsModule) => { |
| 228 | component.action = 'ConfigModify'; |
| 229 | component.actionIdentifiers['vnf-id'] = 'ibcx0001'; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 230 | |
| 231 | component.uploadedFileResult(); |
| 232 | |
| 233 | expect(service instanceof SimpleNotificationsModule).toBeTruthy(); |
| 234 | })); |
| 235 | |
| 236 | it('should return error message', inject([SimpleNotificationsModule], (service: SimpleNotificationsModule) => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 237 | component.action = ''; |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 238 | component.actionIdentifiers['vnf-id'] = ''; |
| 239 | |
| 240 | component.uploadedFileResult(); |
| 241 | |
| 242 | expect(service instanceof SimpleNotificationsModule).toBeTruthy(); |
| 243 | })); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 244 | }); |
| 245 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 246 | // Test constructTestPayload Method |
| 247 | describe('Test constructTestPayload Method', () => { |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 248 | it('Should have constructTestPayload method', () => { |
| 249 | expect(component.constructTestPayload).toBeDefined(); |
| 250 | }); |
| 251 | |
| 252 | it('test if listName2, listName3 are undefined', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 253 | let temp = component.constructTestPayload(undefined, undefined, 'vnfc-type', 'vISBC - ssc'); |
| 254 | expect(component.subPayload['vnfc-type']).toEqual('vISBC - ssc') |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 255 | }); |
| 256 | |
| 257 | it('test if lastName2 is not undefined', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 258 | let temp = component.constructTestPayload(['vm'], undefined, 'vnfc-type', 'vISBC - ssc'); |
| 259 | expect(typeof(component.vmJson)).toEqual('object'); |
| 260 | expect(typeof(component.vnfcJson)).toEqual('object'); |
| 261 | expect(component.vmJson['vnfc-type']).toBe('vISBC - ssc'); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 262 | expect(component.flag).toBe(0); |
| 263 | }); |
| 264 | |
| 265 | it('test if lastNmae2, lastName3 are not undefined', () => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 266 | let temp = component.constructTestPayload(['vm'], 'vnfc', 'vnfc-type', 'vISBC - ssc'); |
| 267 | expect(component.vnfcJson['vnfc-type']).toEqual('vISBC - ssc'); |
| 268 | expect(component.vmJson['vnfc']['vnfc-type']).toEqual('vISBC - ssc'); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 269 | expect(component.flag).toBe(1); |
| 270 | }) |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 271 | }); |
| 272 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 273 | // Test constructRequest Method |
| 274 | describe('Test constructRequest Method', () => { |
| 275 | it('Should have constructRequest method', () => { |
| 276 | expect(component.constructRequest).toBeDefined(); |
| 277 | }); |
| 278 | |
| 279 | it('test method', () => { |
| 280 | let temp = component.constructRequest(); |
| 281 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 282 | }); |
| 283 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 284 | // Test testVnf Method |
| 285 | describe('Test testVnf Method', () => { |
| 286 | it('Should have testVnf method', () => { |
| 287 | expect(component.testVnf).toBeDefined(); |
| 288 | }); |
| 289 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 290 | it('should return response on success', inject([MockBackend], (mockBackend: MockBackend) => { |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 291 | let mockData = 'testing'; |
| 292 | let response = new ResponseOptions({ |
| 293 | body: JSON.stringify(mockData) |
| 294 | }); |
| 295 | const baseResponse = new Response(response); |
| 296 | mockBackend.connections.subscribe( |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 297 | (c: MockConnection) => { |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 298 | c.mockRespond(baseResponse) |
| 299 | } |
| 300 | ); |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 301 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 302 | component.action = 'ConfigModify'; |
| 303 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 304 | component.testVnf(); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 305 | })); |
| 306 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 307 | it('should return an error if fails', inject([HttpUtilService],( httpUtilService: HttpUtilService) => { |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 308 | let error = 'Error in connecting to APPC Server'; |
| 309 | let spy = spyOn(httpUtilService, 'post').and.returnValue(Observable.throw(error)); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 310 | component.action = 'ConfigModify'; |
| 311 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 312 | component.testVnf(); |
| 313 | |
| 314 | expect(spy).toHaveBeenCalled(); |
| 315 | expect(component.enableBrowse).toBeTruthy(); |
| 316 | expect(component.enableTestButton).toBeTruthy(); |
| 317 | expect(component.enablePollButton).toBeTruthy(); |
| 318 | expect(component.enableCounterDiv).toBeFalsy(); |
| 319 | })); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 320 | |
| 321 | it('test setTimeout', inject([NgProgress], (ngProgress: NgProgress) => { |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 322 | component.action = 'ConfigModify'; |
| 323 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 324 | component.testVnf(); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 325 | })); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 326 | }); |
| 327 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 328 | // Test pollTestStatus Method |
| 329 | describe('Test pollTestStatus Method', () => { |
| 330 | it('Should have pollTestStatus method', () => { |
| 331 | expect(component.pollTestStatus).toBeDefined(); |
| 332 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 333 | |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 334 | it('should call fake server', inject([MockBackend], (mockBackend: MockBackend) => { |
| 335 | component.requestId = new Date().getTime().toString(); |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 336 | component.actionIdentifiers['vnf-id'] = 123456; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 337 | let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"FAILED\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 338 | let response = new ResponseOptions({ |
| 339 | body: JSON.stringify(mockData) |
| 340 | }); |
| 341 | const baseResponse = new Response(response); |
| 342 | mockBackend.connections.subscribe( |
| 343 | (c: MockConnection) => c.mockRespond(baseResponse) |
| 344 | ); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 345 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 346 | component.pollTestStatus(); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 347 | })); |
| 348 | |
sj108s | 9017464 | 2018-03-15 20:26:47 +0530 | [diff] [blame] | 349 | it('should call fake server if status is success', inject([MockBackend], (mockBackend: MockBackend) => { |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 350 | component.requestId = new Date().getTime().toString(); |
| 351 | component.actionIdentifiers['vnf-id'] = 123456; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 352 | let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"SUCCESS\",\"status\":\"SUCCESS\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 353 | let response = new ResponseOptions({ |
| 354 | body: JSON.stringify(mockData) |
| 355 | }); |
| 356 | const baseResponse = new Response(response); |
| 357 | mockBackend.connections.subscribe( |
| 358 | (c: MockConnection) => c.mockRespond(baseResponse) |
| 359 | ); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 360 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 361 | component.pollTestStatus(); |
| 362 | })); |
| 363 | |
| 364 | it('should execute else part if timeStamp && status && statusReason are false', inject([MockBackend], (mockBackend: MockBackend) => { |
| 365 | component.requestId = new Date().getTime().toString(); |
| 366 | component.actionIdentifiers['vnf-id'] = 123456; |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 367 | let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 368 | let response = new ResponseOptions({ |
| 369 | body: JSON.stringify(mockData) |
| 370 | }); |
| 371 | const baseResponse = new Response(response); |
| 372 | mockBackend.connections.subscribe( |
| 373 | (c: MockConnection) => c.mockRespond(baseResponse) |
| 374 | ); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 375 | |
| 376 | component.pollTestStatus(); |
| 377 | })); |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 378 | |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 379 | it('should check error condition on polling where timestamp and test status are not available', inject([MockBackend], (mockBackend: MockBackend) => { |
| 380 | component.requestId = new Date().getTime().toString(); |
| 381 | component.actionIdentifiers['vnf-id'] = 123456; |
| 382 | //let mockData = { "output": { "common-header": { "originator-id": "CDT", "sub-request-id": "653018029941", "timestamp": "2018-02-12T07:27:21.448Z", "api-ver": "2.00", "request-id": "653018029941", "flags": { "force": "TRUE", "mode": "NORMAL", "ttl": 3600 } }, "payload": "{\"status-reason\":\"FAILED\",\"status\":\"\"}", "status": { "message": "SUCCESS - request has been processed successfully", "code": 400 } } } ; |
| 383 | let mockData={"output":{"common-header":{"timestamp":"2018-03-21T14:20:30.910Z","api-ver":"2.00","request-id":"1521642030910","flags":{"force":"TRUE","mode":"NORMAL","ttl":3600},"originator-id":"CDT","sub-request-id":"1521642030910"},"status":{"message":"INVALID INPUT PARAMETER - vserver-id","code":301}}}; |
| 384 | let response = new ResponseOptions({ |
| 385 | body: JSON.stringify(mockData) |
| 386 | }); |
| 387 | const baseResponse = new Response(response); |
| 388 | mockBackend.connections.subscribe( |
| 389 | (c: MockConnection) => c.mockRespond(baseResponse) |
| 390 | ); |
| 391 | |
sj108s | b694d95 | 2018-03-21 21:25:39 +0530 | [diff] [blame] | 392 | component.pollTestStatus(); |
| 393 | })); |
| 394 | |
| 395 | it('should return an error if fails', inject([MockBackend], (mockBackend: MockBackend) => { |
| 396 | let error = 'Error Connecting to APPC server'; |
| 397 | component.requestId = new Date().getTime().toString(); |
| 398 | component.actionIdentifiers['vnf-id'] = 123456; |
| 399 | let mockData = ''; |
| 400 | let response = new ResponseOptions({ |
| 401 | body: JSON.stringify(mockData) |
| 402 | }); |
| 403 | const baseResponse = new Response(response); |
| 404 | mockBackend.connections.subscribe( |
| 405 | (c: MockConnection) => c.mockError(new Error(error)) |
| 406 | ); |
| 407 | |
| 408 | component.pollTestStatus(); |
| 409 | })); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 410 | }); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 411 | |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 412 | // Test getUrlEndPoint Method |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 413 | describe('Test getUrlEndPoint Method', () => { |
| 414 | it('Should have getUrlEndPoint method', () => { |
| 415 | expect(component.getUrlEndPoint).toBeDefined(); |
| 416 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 417 | |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 418 | it('getUrlEndPoint Should return value', () => { |
| 419 | expect(component.getUrlEndPoint('configmodify')).toEqual('config-modify'); |
| 420 | expect(component.getUrlEndPoint('configbackup')).toEqual('config-backup'); |
| 421 | expect(component.getUrlEndPoint('configrestore')).toEqual('config-restore'); |
| 422 | expect(component.getUrlEndPoint('healthcheck')).toEqual('health-check'); |
| 423 | expect(component.getUrlEndPoint('quiescetraffic')).toEqual('quiesce-traffic'); |
| 424 | expect(component.getUrlEndPoint('resumetraffic')).toEqual('resume-traffic'); |
| 425 | expect(component.getUrlEndPoint('startapplication')).toEqual('start-application'); |
| 426 | expect(component.getUrlEndPoint('stopapplication')).toEqual('stop-application'); |
| 427 | expect(component.getUrlEndPoint('upgradebackout')).toEqual('upgrade-backout'); |
| 428 | expect(component.getUrlEndPoint('upgradepostcheck')).toEqual('upgrade-post-check'); |
| 429 | expect(component.getUrlEndPoint('upgradeprecheck')).toEqual('upgrade-pre-check'); |
| 430 | expect(component.getUrlEndPoint('upgradesoftware')).toEqual('upgrade-software'); |
| 431 | expect(component.getUrlEndPoint('DeFaultCASE')).toEqual('defaultcase'); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 432 | expect(component.getUrlEndPoint('upgradebackup')).toEqual('upgrad-ebackup'); |
| 433 | expect(component.getUrlEndPoint('attachvolume')).toEqual('attach-volume'); |
| 434 | expect(component.getUrlEndPoint('detachvolume')).toEqual('detach-volume'); |
sj108s | f1e61ce | 2018-03-13 20:29:58 +0530 | [diff] [blame] | 435 | }); |
Skip Wonnell | ed798ab | 2018-03-01 09:00:36 -0600 | [diff] [blame] | 436 | }); |
Mohamed Asgar Samiulla(ma926a) | d7dffc2 | 2018-04-02 19:00:49 +0530 | [diff] [blame] | 437 | }) |