blob: 997cd265aa80879ddd2865e84690ad318c3611e1 [file] [log] [blame]
Skip Wonnell2c977e22018-03-01 08:30:15 -06001/*
2============LICENSE_START==========================================
3===================================================================
4Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5===================================================================
6
7Unless otherwise specified, all software contained herein is licensed
8under the Apache License, Version 2.0 (the License);
9you may not use this software except in compliance with the License.
10You may obtain a copy of the License at
11
12 http://www.apache.org/licenses/LICENSE-2.0
13
14Unless required by applicable law or agreed to in writing, software
15distributed under the License is distributed on an "AS IS" BASIS,
16WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17See the License for the specific language governing permissions and
18limitations under the License.
Skip Wonnell2c977e22018-03-01 08:30:15 -060019============LICENSE_END============================================
20*/
21
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053022/* tslint:disable:no-unused-variable */
23
24// Modules
25import { async, ComponentFixture, TestBed,inject } from '@angular/core/testing';
Skip Wonnell2c977e22018-03-01 08:30:15 -060026import { By } from '@angular/platform-browser';
27import { DebugElement } from '@angular/core';
28import { FormsModule, ReactiveFormsModule } from '@angular/forms';
29import { RouterTestingModule } from '@angular/router/testing';
30import { SimpleNotificationsModule } from 'angular2-notifications';
sj108s90174642018-03-15 20:26:47 +053031import { Http, Headers, HttpModule, BaseRequestOptions, Response, ResponseOptions } from '@angular/http';
32import { MockBackend, MockConnection } from '@angular/http/testing';
sj108sf1e61ce2018-03-13 20:29:58 +053033import { Observable } from 'rxjs/Observable';
34import { Subscription } from 'rxjs/Subscription';
35import 'rxjs/add/observable/from';
36import 'rxjs/add/observable/empty';
37import 'rxjs/add/observable/throw';
Skip Wonnell2c977e22018-03-01 08:30:15 -060038
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053039// Component
Skip Wonnell2c977e22018-03-01 08:30:15 -060040import { TestComponent } from './test.component';
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053041
42// Services
Skip Wonnell2c977e22018-03-01 08:30:15 -060043import { NotificationService } from '../shared/services/notification.service';
44import { ParamShareService } from '.././shared/services/paramShare.service';
45import { MappingEditorService } from '../shared/services/mapping-editor.service';
46import { HttpUtilService } from '../shared/services/httpUtil/http-util.service';
47import { UtilityService } from '../shared/services/utilityService/utility.service';
sj108sf1e61ce2018-03-13 20:29:58 +053048import { environment } from '../.././environments/environment';
Skip Wonnell2c977e22018-03-01 08:30:15 -060049import { NgProgress } from 'ngx-progressbar';
sj108sf1e61ce2018-03-13 20:29:58 +053050import { NgProgressModule } from 'ngx-progressbar';
51
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053052describe( 'TestComponent', () => {
Skip Wonnelled798ab2018-03-01 09:00:36 -060053 let component: TestComponent;
54 let fixture: ComponentFixture<TestComponent>;
Skip Wonnell2c977e22018-03-01 08:30:15 -060055
Skip Wonnelled798ab2018-03-01 09:00:36 -060056 beforeEach(async(() => {
57 TestBed.configureTestingModule({
58 declarations: [TestComponent],
59 imports: [
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053060 FormsModule,
61 RouterTestingModule,
62 SimpleNotificationsModule,
63 HttpModule,
64 NgProgressModule
Skip Wonnelled798ab2018-03-01 09:00:36 -060065 ],
66 providers: [
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053067 NotificationService,
68 ParamShareService,
69 MappingEditorService,
70 HttpUtilService,
71 UtilityService,
72 NgProgress,MockBackend, BaseRequestOptions,
sj108s90174642018-03-15 20:26:47 +053073 {
74 provide: Http,
75 useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) => {
76 return new Http(backend, defaultOptions);
77 },
78 deps: [MockBackend, BaseRequestOptions],
79 }
Skip Wonnelled798ab2018-03-01 09:00:36 -060080 ]
81 })
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053082 .compileComponents();
Skip Wonnelled798ab2018-03-01 09:00:36 -060083 }));
Skip Wonnell2c977e22018-03-01 08:30:15 -060084
Skip Wonnelled798ab2018-03-01 09:00:36 -060085 beforeEach(() => {
86 fixture = TestBed.createComponent(TestComponent);
87 component = fixture.componentInstance;
88 fixture.detectChanges();
89 });
Skip Wonnell2c977e22018-03-01 08:30:15 -060090
sj108sf1e61ce2018-03-13 20:29:58 +053091 it('should ...', inject([HttpUtilService], (service: HttpUtilService) => {
sj108sf1e61ce2018-03-13 20:29:58 +053092 fixture.detectChanges(); // onInit()
Skip Wonnell2c977e22018-03-01 08:30:15 -060093
sj108sf1e61ce2018-03-13 20:29:58 +053094 component.pollTestStatus();
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053095
sj108sf1e61ce2018-03-13 20:29:58 +053096 expect(service).toBeTruthy();
sj108sf1e61ce2018-03-13 20:29:58 +053097 }));
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +053098
sj108sf1e61ce2018-03-13 20:29:58 +053099 // Test download Method
100 describe('Test download Method', () => {
101 it('Should have download method', () => {
102 expect(component.download).toBeDefined();
103 });
Skip Wonnell2c977e22018-03-01 08:30:15 -0600104
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530105 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":""';
sj108sf1e61ce2018-03-13 20:29:58 +0530107 component.apiResponse = '';
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530108 component.action = 'ConfigModify';
109 component.actionIdentifiers['vnf-id'] = 'ibcx0001';
sj108sf1e61ce2018-03-13 20:29:58 +0530110 let fileName = 'test_' + component.action + '_' + component.actionIdentifiers['vnf-id'] + '_request';
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530111 let theJSON = component.apiRequest;
sj108sf1e61ce2018-03-13 20:29:58 +0530112 var blob = new Blob([theJSON], {
113 type: 'text/json'
114 });
Skip Wonnell2c977e22018-03-01 08:30:15 -0600115
sj108sf1e61ce2018-03-13 20:29:58 +0530116 component.download();
Skip Wonnell2c977e22018-03-01 08:30:15 -0600117
sj108sf1e61ce2018-03-13 20:29:58 +0530118 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 Wonnell2c977e22018-03-01 08:30:15 -0600125
sj108sf1e61ce2018-03-13 20:29:58 +0530126 }));
Skip Wonnell2c977e22018-03-01 08:30:15 -0600127
sj108sf1e61ce2018-03-13 20:29:58 +0530128 it('test method if apiResponse is true', () => {
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530129 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":""';
sj108sf1e61ce2018-03-13 20:29:58 +0530130 component.apiRequest = '';
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530131 component.action = 'ConfigModify';
132 component.actionIdentifiers['vnf-id'] = 'ibcx0001';
sj108sf1e61ce2018-03-13 20:29:58 +0530133 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 Wonnelled798ab2018-03-01 09:00:36 -0600149 });
Skip Wonnell2c977e22018-03-01 08:30:15 -0600150
Skip Wonnelled798ab2018-03-01 09:00:36 -0600151 // Test abortTest Method
sj108sf1e61ce2018-03-13 20:29:58 +0530152 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)d7dffc22018-04-02 19:00:49 +0530158 component.abortTest();
sj108sf1e61ce2018-03-13 20:29:58 +0530159 expect(component.enableBrowse).toBeTruthy();
160 expect(component.enableTestButton).toBeTruthy();
161 expect(component.enablePollButton).toBeTruthy();
162 });
Skip Wonnelled798ab2018-03-01 09:00:36 -0600163 });
164
sj108sf1e61ce2018-03-13 20:29:58 +0530165 // 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 Wonnelled798ab2018-03-01 09:00:36 -0600173 });
174
sj108sf1e61ce2018-03-13 20:29:58 +0530175 // 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', () => {
sj108sf1e61ce2018-03-13 20:29:58 +0530182 let reader = new FileReader();
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530183 let file = new File(["testing"], "foo.XLS", {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})
sj108s90174642018-03-15 20:26:47 +0530184 let fileExtension = 'XLS';
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530185 let event = { isTrusted: true, type: "change", target: {files: [file]} }
sj108sf1e61ce2018-03-13 20:29:58 +0530186
187 component.upload(event);
188
189 expect(reader instanceof FileReader).toBeTruthy();
sj108s90174642018-03-15 20:26:47 +0530190 expect(component.pollCounter).toBe(0)
sj108sf1e61ce2018-03-13 20:29:58 +0530191 });
192
193 it('should return an error if file extension is not XLS, XLSX', () => {
sj108s90174642018-03-15 20:26:47 +0530194 let reader = new FileReader();
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530195 let file = new File(["testing"], "foo.doc", {type: ""})
sj108s90174642018-03-15 20:26:47 +0530196 let fileExtension = 'doc';
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530197 let event = { isTrusted: true, type: "change", target: {files: [file]} }
198
sj108s90174642018-03-15 20:26:47 +0530199 component.upload(event);
sj108sf1e61ce2018-03-13 20:29:58 +0530200
sj108s90174642018-03-15 20:26:47 +0530201 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)d7dffc22018-04-02 19:00:49 +0530206
sj108sf1e61ce2018-03-13 20:29:58 +0530207 });
Skip Wonnelled798ab2018-03-01 09:00:36 -0600208 });
209
sj108sf1e61ce2018-03-13 20:29:58 +0530210 // Test processUploadedFile Method
211 describe('Test processUploadedFile Method', () => {
212 it('should return valid payload', () => {
213 let data = [
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530214 {"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"}
sj108sf1e61ce2018-03-13 20:29:58 +0530219 ]
220
221 let payload = component.processUploadedFile(data);
222 });
Skip Wonnelled798ab2018-03-01 09:00:36 -0600223 });
224
sj108sf1e61ce2018-03-13 20:29:58 +0530225 // Test uploadedFileResult Method
226 describe('Test uploadedFileResult', () => {
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530227 it('should return success message', inject([SimpleNotificationsModule],(service: SimpleNotificationsModule) => {
228 component.action = 'ConfigModify';
229 component.actionIdentifiers['vnf-id'] = 'ibcx0001';
sj108sf1e61ce2018-03-13 20:29:58 +0530230
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)d7dffc22018-04-02 19:00:49 +0530237 component.action = '';
sj108sf1e61ce2018-03-13 20:29:58 +0530238 component.actionIdentifiers['vnf-id'] = '';
239
240 component.uploadedFileResult();
241
242 expect(service instanceof SimpleNotificationsModule).toBeTruthy();
243 }));
Skip Wonnelled798ab2018-03-01 09:00:36 -0600244 });
245
sj108sf1e61ce2018-03-13 20:29:58 +0530246 // Test constructTestPayload Method
247 describe('Test constructTestPayload Method', () => {
sj108sf1e61ce2018-03-13 20:29:58 +0530248 it('Should have constructTestPayload method', () => {
249 expect(component.constructTestPayload).toBeDefined();
250 });
251
252 it('test if listName2, listName3 are undefined', () => {
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530253 let temp = component.constructTestPayload(undefined, undefined, 'vnfc-type', 'vISBC - ssc');
254 expect(component.subPayload['vnfc-type']).toEqual('vISBC - ssc')
sj108sf1e61ce2018-03-13 20:29:58 +0530255 });
256
257 it('test if lastName2 is not undefined', () => {
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530258 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');
sj108sf1e61ce2018-03-13 20:29:58 +0530262 expect(component.flag).toBe(0);
263 });
264
265 it('test if lastNmae2, lastName3 are not undefined', () => {
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530266 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');
sj108sf1e61ce2018-03-13 20:29:58 +0530269 expect(component.flag).toBe(1);
270 })
Skip Wonnelled798ab2018-03-01 09:00:36 -0600271 });
272
sj108sf1e61ce2018-03-13 20:29:58 +0530273 // 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 Wonnelled798ab2018-03-01 09:00:36 -0600282 });
283
sj108sf1e61ce2018-03-13 20:29:58 +0530284 // 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)d7dffc22018-04-02 19:00:49 +0530290 it('should return response on success', inject([MockBackend], (mockBackend: MockBackend) => {
sj108sb694d952018-03-21 21:25:39 +0530291 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)d7dffc22018-04-02 19:00:49 +0530297 (c: MockConnection) => {
sj108sb694d952018-03-21 21:25:39 +0530298 c.mockRespond(baseResponse)
299 }
300 );
sj108s90174642018-03-15 20:26:47 +0530301
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530302 component.action = 'ConfigModify';
303
sj108sb694d952018-03-21 21:25:39 +0530304 component.testVnf();
sj108sf1e61ce2018-03-13 20:29:58 +0530305 }));
306
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530307 it('should return an error if fails', inject([HttpUtilService],( httpUtilService: HttpUtilService) => {
sj108sb694d952018-03-21 21:25:39 +0530308 let error = 'Error in connecting to APPC Server';
309 let spy = spyOn(httpUtilService, 'post').and.returnValue(Observable.throw(error));
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530310 component.action = 'ConfigModify';
311
sj108sb694d952018-03-21 21:25:39 +0530312 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 }));
sj108sf1e61ce2018-03-13 20:29:58 +0530320
321 it('test setTimeout', inject([NgProgress], (ngProgress: NgProgress) => {
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530322 component.action = 'ConfigModify';
323
sj108sf1e61ce2018-03-13 20:29:58 +0530324 component.testVnf();
sj108sf1e61ce2018-03-13 20:29:58 +0530325 }));
Skip Wonnelled798ab2018-03-01 09:00:36 -0600326 });
327
sj108sf1e61ce2018-03-13 20:29:58 +0530328 // Test pollTestStatus Method
329 describe('Test pollTestStatus Method', () => {
330 it('Should have pollTestStatus method', () => {
331 expect(component.pollTestStatus).toBeDefined();
332 });
Skip Wonnelled798ab2018-03-01 09:00:36 -0600333
sj108s90174642018-03-15 20:26:47 +0530334 it('should call fake server', inject([MockBackend], (mockBackend: MockBackend) => {
335 component.requestId = new Date().getTime().toString();
sj108sb694d952018-03-21 21:25:39 +0530336 component.actionIdentifiers['vnf-id'] = 123456;
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530337 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 } } } ;
sj108sb694d952018-03-21 21:25:39 +0530338 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)d7dffc22018-04-02 19:00:49 +0530345
sj108sb694d952018-03-21 21:25:39 +0530346 component.pollTestStatus();
sj108sf1e61ce2018-03-13 20:29:58 +0530347 }));
348
sj108s90174642018-03-15 20:26:47 +0530349 it('should call fake server if status is success', inject([MockBackend], (mockBackend: MockBackend) => {
sj108sb694d952018-03-21 21:25:39 +0530350 component.requestId = new Date().getTime().toString();
351 component.actionIdentifiers['vnf-id'] = 123456;
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530352 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 } } } ;
sj108sb694d952018-03-21 21:25:39 +0530353 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)d7dffc22018-04-02 19:00:49 +0530360
sj108sb694d952018-03-21 21:25:39 +0530361 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)d7dffc22018-04-02 19:00:49 +0530367 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 } } } ;
sj108sb694d952018-03-21 21:25:39 +0530368 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)d7dffc22018-04-02 19:00:49 +0530375
376 component.pollTestStatus();
377 }));
sj108sb694d952018-03-21 21:25:39 +0530378
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530379 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
sj108sb694d952018-03-21 21:25:39 +0530392 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 }));
sj108sf1e61ce2018-03-13 20:29:58 +0530410 });
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530411
Skip Wonnelled798ab2018-03-01 09:00:36 -0600412 // Test getUrlEndPoint Method
sj108sf1e61ce2018-03-13 20:29:58 +0530413 describe('Test getUrlEndPoint Method', () => {
414 it('Should have getUrlEndPoint method', () => {
415 expect(component.getUrlEndPoint).toBeDefined();
416 });
Skip Wonnelled798ab2018-03-01 09:00:36 -0600417
sj108sf1e61ce2018-03-13 20:29:58 +0530418 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)d7dffc22018-04-02 19:00:49 +0530432 expect(component.getUrlEndPoint('upgradebackup')).toEqual('upgrad-ebackup');
433 expect(component.getUrlEndPoint('attachvolume')).toEqual('attach-volume');
434 expect(component.getUrlEndPoint('detachvolume')).toEqual('detach-volume');
sj108sf1e61ce2018-03-13 20:29:58 +0530435 });
Skip Wonnelled798ab2018-03-01 09:00:36 -0600436 });
Mohamed Asgar Samiulla(ma926a)d7dffc22018-04-02 19:00:49 +0530437})