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