834b8c34ea25d882f8a328439f8566aa1d5aa8c9
[so.git] / so-monitoring / so-monitoring-ui / src / main / frontend / src / app / data.service.spec.ts
1 /**\r
2 ============LICENSE_START=======================================================\r
3  Copyright (C) 2018 Ericsson. All rights reserved.\r
4 ================================================================================\r
5 Licensed under the Apache License, Version 2.0 (the "License");\r
6 you may not use this file except in compliance with the License.\r
7 You may obtain a copy of the License at\r
8 \r
9     http://www.apache.org/licenses/LICENSE-2.0\r
10 \r
11 Unless required by applicable law or agreed to in writing, software\r
12 distributed under the License is distributed on an "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 See the License for the specific language governing permissions and\r
15  limitations under the License.\r
16 \r
17 SPDX-License-Identifier: Apache-2.0\r
18 ============LICENSE_END=========================================================\r
19 \r
20 @authors: ronan.kenny@ericsson.com, waqas.ikram@ericsson.com\r
21 */\r
22 \r
23 import { TestBed, inject } from '@angular/core/testing';\r
24 \r
25 import { DataService } from './data.service';\r
26 import { HttpClient } from '@angular/common/http';\r
27 import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';\r
28 import { async } from '@angular/core/testing';\r
29 import { HttpClientModule } from '@angular/common/http';\r
30 import { ToastrNotificationService } from './toastr-notification-service.service';\r
31 import { environment } from '../environments/environment';\r
32 \r
33 class StubbedToastrNotificationService extends ToastrNotificationService {\r
34   toastrSettings() {\r
35   }\r
36 }\r
37 \r
38 describe('DataService', () => {\r
39   beforeEach(() => {\r
40     TestBed.configureTestingModule({\r
41       providers: [DataService, { provide: ToastrNotificationService, useClass: StubbedToastrNotificationService }],\r
42       imports: [HttpClientTestingModule]\r
43     });\r
44   });\r
45 \r
46   // Ensure creation of DataService component\r
47   it('component should be created', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
48     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
49       expect(service).toBeTruthy();\r
50     })));\r
51 \r
52   // Test retrieveInstance function making POST call\r
53   it('test retrieveInstance POST request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
54     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
55       service.retrieveInstance({}, 1, 2).subscribe(data => { });\r
56       var url = environment.soMonitoringBackendURL + 'v1/search?from=1&to=2';\r
57       const mockReq = httpClient.expectOne(url);\r
58       expect(mockReq.request.method).toEqual('POST');\r
59       mockReq.flush({});\r
60     })));\r
61 \r
62   // Test getProcessInstanceId function making GET request to retrieve processInstanceID\r
63   it('test getProcessInstanceId GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
64     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
65       service.getProcessInstanceId("").subscribe(data => { });\r
66       var url = environment.soMonitoringBackendURL + 'process-instance-id/' + "";\r
67       const mockReq = httpClient.expectOne(url);\r
68       expect(mockReq.request.method).toEqual('GET');\r
69       mockReq.flush({});\r
70     })));\r
71 \r
72   // Test getActivityInstance function making GET request to retrieve activityInstance\r
73   it('test getActivityInstance GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
74     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
75       service.getActivityInstance("").subscribe(data => { });\r
76       var url = environment.soMonitoringBackendURL + 'activity-instance/' + "";\r
77       const mockReq = httpClient.expectOne(url);\r
78       expect(mockReq.request.method).toEqual('GET');\r
79       mockReq.flush({});\r
80     })));\r
81 \r
82   // Test getProcessInstance function making GET request to retrieve processInstance\r
83   it('test getProcessInstance GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
84     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
85       service.getProcessInstance("");\r
86       var url = environment.soMonitoringBackendURL + 'process-instance/' + "";\r
87       const mockReq = httpClient.expectOne(url);\r
88       expect(mockReq.request.method).toEqual('GET');\r
89     })));\r
90 \r
91   // Test getProcessDefinition function making GET request to retrieve processDefinition\r
92   it('test getProcessDefinition GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
93     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
94       service.getProcessDefinition("").subscribe(data => { });\r
95       var url = environment.soMonitoringBackendURL + 'process-definition/' + "";\r
96       const mockReq = httpClient.expectOne(url);\r
97       expect(mockReq.request.method).toEqual('GET');\r
98       mockReq.flush({});\r
99     })));\r
100 \r
101   // Test getVariableInstance function making GET request to retrieve variableInstance\r
102   it('test getVariableInstance GET request', async(inject([HttpTestingController, DataService, ToastrNotificationService],\r
103     (httpClient: HttpTestingController, service: DataService, toastr: ToastrNotificationService) => {\r
104       service.getVariableInstance("").subscribe(data => { });\r
105       var url = environment.soMonitoringBackendURL + 'variable-instance/' + "";\r
106       const mockReq = httpClient.expectOne(url);\r
107       expect(mockReq.request.method).toEqual('GET');\r
108       mockReq.flush({});\r
109     })));\r
110 });\r