Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit cbdeb09

Browse files
cppwfsjvalkeal
authored andcommitted
Adds tests to Jobs Service
resolves #365
1 parent 63a752a commit cbdeb09

File tree

3 files changed

+469
-4
lines changed

3 files changed

+469
-4
lines changed

ui/src/app/jobs/jobs.service.spec.ts

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@ import { Observable } from 'rxjs/Rx';
33
import { JobsService } from './jobs.service';
44
import { HttpUtils } from '../shared/support/http.utils';
55
import { ErrorHandler } from '../shared/model';
6+
import {
7+
JOB_EXECUTIONS_WITH_PAGINATION, JOBS_EXECUTIONS, JOBS_EXECUTIONS_1, JOBS_EXECUTIONS_1_STEPS_1,
8+
JOBS_EXECUTIONS_1_STEPS_1_PROGRESS
9+
} from '../tests/mocks/mock-data';
10+
import {Page} from '../shared/model/page';
11+
import {JobExecution} from './model/job-execution.model';
12+
13+
export class MockResponse {
14+
15+
private _body: any;
16+
17+
get body(): any {
18+
return this._body;
19+
}
20+
21+
set body(value: any) {
22+
this._body = value;
23+
}
24+
25+
public json(): any {
26+
return this.body;
27+
}
28+
}
629

730
describe('JobsService', () => {
831

@@ -34,11 +57,218 @@ describe('JobsService', () => {
3457
});
3558
});
3659

60+
describe('getJobExecutionsCached', () => {
61+
62+
it('should call the jobs service to get all cached job executions', () => {
63+
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
64+
65+
this.jobsService.jobExecutions = JOBS_EXECUTIONS;
66+
67+
const params = HttpUtils.getPaginationParams(0, 10);
68+
69+
this.jobsService.getJobExecutions(false);
70+
71+
expect(this.mockHttp.get).not.toHaveBeenCalledWith('/jobs/executions', { search: params });
72+
});
73+
});
74+
3775
describe('getJobExecution', () => {
3876
it('should call the jobs service with the right url to get job execution', () => {
3977
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
4078
this.jobsService.getJobExecution('1');
4179
expect(this.mockHttp.get).toHaveBeenCalledWith('/jobs/executions/1', {});
4280
});
4381
});
82+
83+
describe('getStepExecution', () => {
84+
it('should call the jobs service with the right url to get step execution', () => {
85+
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
86+
this.jobsService.getStepExecution('1', '1');
87+
expect(this.mockHttp.get).toHaveBeenCalledWith('/jobs/executions/1/steps/1', {});
88+
});
89+
});
90+
91+
describe('getStepExecutionProgress', () => {
92+
it('should call the jobs service with the right url to get step execution progress', () => {
93+
this.mockHttp.get.and.returnValue(Observable.of(this.jsonData));
94+
this.jobsService.getStepExecutionProgress('1', '1');
95+
expect(this.mockHttp.get).toHaveBeenCalledWith('/jobs/executions/1/steps/1/progress', {});
96+
});
97+
});
98+
99+
describe('extractData', () => {
100+
it('should call the jobs service to extract data from json', () => {
101+
const response = new MockResponse();
102+
response.body = JOB_EXECUTIONS_WITH_PAGINATION ;
103+
this.jobsService.jobExecutions = new Page<JobExecution>();
104+
const jobExecutions = this.jobsService.extractData(response);
105+
expect(jobExecutions.pageNumber).toBe(0);
106+
expect(jobExecutions.pageSize).toBe(10);
107+
expect(jobExecutions.totalElements).toBe(2);
108+
expect(jobExecutions.totalPages).toBe(1);
109+
110+
expect(jobExecutions.items[0].name).toBe('job2');
111+
expect(jobExecutions.items[1].name).toBe('job1');
112+
expect(jobExecutions.items[0].startTime.toISOString()).toBe('2017-09-06T00:54:46.000Z');
113+
expect(jobExecutions.items[0].stepExecutionCount).toBe(1);
114+
expect(jobExecutions.items[0].status).toBe('COMPLETED');
115+
expect(jobExecutions.items[0].jobExecutionId).toBe(2);
116+
expect(jobExecutions.items[0].taskExecutionId).toBe(95);
117+
expect(jobExecutions.items[0].jobInstanceId).toBe(2);
118+
expect(jobExecutions.items[0].restartable).toBe(false);
119+
expect(jobExecutions.items[0].abandonable).toBe(false);
120+
expect(jobExecutions.items[0].stoppable).toBe(false);
121+
expect(jobExecutions.items[0].defined).toBe(false);
122+
123+
});
124+
});
125+
126+
describe('extractStepExecutionProgressData', () => {
127+
it('should call the jobs service to parse progress from json', () => {
128+
const response = new MockResponse();
129+
response.body = JOBS_EXECUTIONS_1_STEPS_1_PROGRESS ;
130+
const stepExecutionProgress = this.jobsService.extractStepExecutionProgressData(response);
131+
132+
expect(stepExecutionProgress.stepExecution.name).toBe('job1step1');
133+
expect(stepExecutionProgress.stepExecution.executionContext.dirty).toBe(true);
134+
expect(stepExecutionProgress.percentageComplete).toBe(1);
135+
expect(stepExecutionProgress.finished).toBe(true);
136+
expect(stepExecutionProgress.duration).toBe(13);
137+
138+
expect(stepExecutionProgress.stepExecution.id).toBe(1);
139+
expect(stepExecutionProgress.stepExecution.status).toBe('COMPLETED');
140+
expect(stepExecutionProgress.stepExecution.readCount).toBe(0);
141+
expect(stepExecutionProgress.stepExecution.writeCount).toBe(0);
142+
expect(stepExecutionProgress.stepExecution.commitCount).toBe(1);
143+
expect(stepExecutionProgress.stepExecution.writeCount).toBe(0);
144+
expect(stepExecutionProgress.stepExecution.rollbackCount).toBe(0);
145+
expect(stepExecutionProgress.stepExecution.readSkipCount).toBe(0);
146+
expect(stepExecutionProgress.stepExecution.processSkipCount).toBe(0);
147+
expect(stepExecutionProgress.stepExecution.writeSkipCount).toBe(0);
148+
expect(stepExecutionProgress.stepExecution.skipCount).toBe(0);
149+
expect(stepExecutionProgress.stepExecution.startTime.toISOString()).toBe('2017-08-21T07:25:05.028Z');
150+
expect(stepExecutionProgress.stepExecution.endTime.toISOString()).toBe('2017-08-21T07:25:05.041Z');
151+
expect(stepExecutionProgress.stepExecution.exitCode).toBe('COMPLETED');
152+
expect(stepExecutionProgress.stepExecution.exitMessage).toBe('');
153+
154+
expect(stepExecutionProgress.stepExecutionHistory.stepName).toBe('job1step1');
155+
expect(stepExecutionProgress.stepExecutionHistory.count).toBe(1);
156+
157+
expect(stepExecutionProgress.stepExecutionHistory.commitCount.count).toBe(1);
158+
expect(stepExecutionProgress.stepExecutionHistory.commitCount.min).toBe(1);
159+
expect(stepExecutionProgress.stepExecutionHistory.commitCount.max).toBe(1);
160+
expect(stepExecutionProgress.stepExecutionHistory.commitCount.mean).toBe(1);
161+
expect(stepExecutionProgress.stepExecutionHistory.commitCount.standardDeviation).toBe(0);
162+
expect(stepExecutionProgress.stepExecutionHistory.rollbackCount.count).toBe( 1);
163+
expect(stepExecutionProgress.stepExecutionHistory.rollbackCount.min).toBe(0);
164+
expect(stepExecutionProgress.stepExecutionHistory.rollbackCount.max).toBe(0);
165+
expect(stepExecutionProgress.stepExecutionHistory.rollbackCount.mean).toBe(0);
166+
expect(stepExecutionProgress.stepExecutionHistory.rollbackCount.standardDeviation).toBe(0);
167+
expect(stepExecutionProgress.stepExecutionHistory.readCount.count).toBe( 1);
168+
expect(stepExecutionProgress.stepExecutionHistory.readCount.min).toBe(0);
169+
expect(stepExecutionProgress.stepExecutionHistory.readCount.max).toBe(0);
170+
expect(stepExecutionProgress.stepExecutionHistory.readCount.mean).toBe(0);
171+
expect(stepExecutionProgress.stepExecutionHistory.readCount.standardDeviation).toBe(0);
172+
expect(stepExecutionProgress.stepExecutionHistory.writeCount.count).toBe( 1);
173+
expect(stepExecutionProgress.stepExecutionHistory.writeCount.min).toBe(0);
174+
expect(stepExecutionProgress.stepExecutionHistory.writeCount.max).toBe(0);
175+
expect(stepExecutionProgress.stepExecutionHistory.writeCount.mean).toBe(0);
176+
expect(stepExecutionProgress.stepExecutionHistory.writeCount.standardDeviation).toBe(0);
177+
expect(stepExecutionProgress.stepExecutionHistory.filterCount.count).toBe( 1);
178+
expect(stepExecutionProgress.stepExecutionHistory.filterCount.min).toBe(0);
179+
expect(stepExecutionProgress.stepExecutionHistory.filterCount.max).toBe(0);
180+
expect(stepExecutionProgress.stepExecutionHistory.filterCount.mean).toBe(0);
181+
expect(stepExecutionProgress.stepExecutionHistory.filterCount.standardDeviation).toBe(0);
182+
expect(stepExecutionProgress.stepExecutionHistory.readSkipCount.count).toBe( 1);
183+
expect(stepExecutionProgress.stepExecutionHistory.readSkipCount.min).toBe(0);
184+
expect(stepExecutionProgress.stepExecutionHistory.readSkipCount.max).toBe(0);
185+
expect(stepExecutionProgress.stepExecutionHistory.readSkipCount.mean).toBe(0);
186+
expect(stepExecutionProgress.stepExecutionHistory.readSkipCount.standardDeviation).toBe(0);
187+
expect(stepExecutionProgress.stepExecutionHistory.writeSkipCount.count).toBe( 1);
188+
expect(stepExecutionProgress.stepExecutionHistory.writeSkipCount.min).toBe(0);
189+
expect(stepExecutionProgress.stepExecutionHistory.writeSkipCount.max).toBe(0);
190+
expect(stepExecutionProgress.stepExecutionHistory.writeSkipCount.mean).toBe(0);
191+
expect(stepExecutionProgress.stepExecutionHistory.writeSkipCount.standardDeviation).toBe(0);
192+
expect(stepExecutionProgress.stepExecutionHistory.processSkipCount.count).toBe( 1);
193+
expect(stepExecutionProgress.stepExecutionHistory.processSkipCount.min).toBe(0);
194+
expect(stepExecutionProgress.stepExecutionHistory.processSkipCount.max).toBe(0);
195+
expect(stepExecutionProgress.stepExecutionHistory.processSkipCount.mean).toBe(0);
196+
expect(stepExecutionProgress.stepExecutionHistory.processSkipCount.standardDeviation).toBe(0);
197+
expect(stepExecutionProgress.stepExecutionHistory.duration.count).toBe( 1);
198+
expect(stepExecutionProgress.stepExecutionHistory.duration.min).toBe(13);
199+
expect(stepExecutionProgress.stepExecutionHistory.duration.max).toBe(13);
200+
expect(stepExecutionProgress.stepExecutionHistory.duration.mean).toBe(13);
201+
expect(stepExecutionProgress.stepExecutionHistory.duration.standardDeviation).toBe(0);
202+
expect(stepExecutionProgress.stepExecutionHistory.durationPerRead.count).toBe( 0);
203+
expect(stepExecutionProgress.stepExecutionHistory.durationPerRead.min).toBe(0);
204+
expect(stepExecutionProgress.stepExecutionHistory.durationPerRead.max).toBe(0);
205+
expect(stepExecutionProgress.stepExecutionHistory.durationPerRead.mean).toBe(0);
206+
expect(stepExecutionProgress.stepExecutionHistory.durationPerRead.standardDeviation).toBe(0);
207+
208+
});
209+
});
210+
211+
describe('extractStepExecutionData', () => {
212+
it('should call the jobs service to parse step execution from json', () => {
213+
const response = new MockResponse();
214+
response.body = JOBS_EXECUTIONS_1_STEPS_1 ;
215+
const stepExecutionResource = this.jobsService.extractStepExecutionData(response);
216+
217+
expect(stepExecutionResource.stepExecution.id).toBe(1);
218+
expect(stepExecutionResource.stepExecution.name).toBe('job1step1');
219+
expect(stepExecutionResource.stepExecution.executionContext.dirty).toBe(true);
220+
expect(stepExecutionResource.stepExecution.status).toBe('COMPLETED');
221+
expect(stepExecutionResource.stepExecution.readCount).toBe(0);
222+
expect(stepExecutionResource.stepExecution.writeCount).toBe(0);
223+
expect(stepExecutionResource.stepExecution.commitCount).toBe(1);
224+
expect(stepExecutionResource.stepExecution.rollbackCount).toBe(0);
225+
expect(stepExecutionResource.stepExecution.readSkipCount).toBe(0);
226+
expect(stepExecutionResource.stepExecution.processSkipCount).toBe(0);
227+
expect(stepExecutionResource.stepExecution.writeSkipCount).toBe(0);
228+
expect(stepExecutionResource.stepExecution.filterCount).toBe(0);
229+
expect(stepExecutionResource.stepExecution.skipCount).toBe(0);
230+
expect(stepExecutionResource.stepExecution.startTime.toISOString()).toBe('2017-08-11T06:15:50.046Z');
231+
expect(stepExecutionResource.stepExecution.endTime.toISOString()).toBe('2017-08-11T06:15:50.064Z');
232+
});
233+
});
234+
235+
describe('extractJobExecutionData', () => {
236+
it('should call the jobs service to parse job execution from json', () => {
237+
const response = new MockResponse();
238+
response.body = JOBS_EXECUTIONS_1;
239+
const jobExecution = this.jobsService.extractJobExecutionData(response);
240+
241+
expect(jobExecution.name).toBe('job1');
242+
expect(jobExecution.startTime.toISOString()).toBe('2017-08-11T06:15:50.027Z');
243+
expect(jobExecution.endTime.toISOString()).toBe('2017-08-11T06:15:50.067Z');
244+
expect(jobExecution.stepExecutionCount).toBe(1);
245+
expect(jobExecution.status).toBe('COMPLETED');
246+
expect(jobExecution.exitCode).toBe('COMPLETED');
247+
expect(jobExecution.exitMessage).toBe('');
248+
expect(jobExecution.jobExecutionId).toBe(1);
249+
expect(jobExecution.taskExecutionId).toBe(2);
250+
expect(jobExecution.jobInstanceId).toBe(1);
251+
expect(jobExecution.jobParametersString).toBe('--spring.cloud.task.executionid=2');
252+
expect(jobExecution.restartable).toBe(false);
253+
expect(jobExecution.abandonable).toBe(false);
254+
expect(jobExecution.stoppable).toBe(false);
255+
expect(jobExecution.defined).toBe(true);
256+
257+
expect(jobExecution.stepExecutions[0].id).toBe(1);
258+
expect(jobExecution.stepExecutions[0].name).toBe('job1step1');
259+
expect(jobExecution.stepExecutions[0].readCount).toBe(0);
260+
expect(jobExecution.stepExecutions[0].writeCount).toBe(0);
261+
expect(jobExecution.stepExecutions[0].commitCount).toBe(1);
262+
expect(jobExecution.stepExecutions[0].rollbackCount).toBe(0);
263+
expect(jobExecution.stepExecutions[0].readSkipCount).toBe(0);
264+
expect(jobExecution.stepExecutions[0].processSkipCount).toBe(0);
265+
expect(jobExecution.stepExecutions[0].writeSkipCount).toBe(0);
266+
expect(jobExecution.stepExecutions[0].filterCount).toBe(0);
267+
expect(jobExecution.stepExecutions[0].skipCount).toBe(0);
268+
expect(jobExecution.stepExecutions[0].startTime.toISOString()).toBe('2017-08-11T06:15:50.046Z');
269+
expect(jobExecution.stepExecutions[0].endTime.toISOString()).toBe('2017-08-11T06:15:50.064Z');
270+
expect(jobExecution.stepExecutions[0].status).toBe('COMPLETED');
271+
});
272+
});
273+
44274
});

ui/src/app/jobs/jobs.service.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ export class JobsService {
9292
.map(this.extractStepExecutionProgressData.bind(this))
9393
.catch(this.errorHandler.handleError);
9494
}
95-
private extractStepExecutionProgressData(response: Response): StepExecutionProgress {
95+
96+
/**
97+
* Creates a StepExecutionProgress instance with the contents of the response.json.
98+
* @param {Response} response instance that contains the json.
99+
* @returns {StepExecutionProgress} instance of StepExecutionProgress.
100+
*/
101+
extractStepExecutionProgressData(response: Response): StepExecutionProgress {
96102
const stepExecutionProgress: StepExecutionProgress = new StepExecutionProgress();
97103
const body = response.json();
98104
stepExecutionProgress.percentageComplete = body.percentageComplete;
@@ -209,7 +215,12 @@ export class JobsService {
209215
return stepExecutionProgress;
210216
}
211217

212-
private extractStepExecutionData(response: Response): StepExecutionResource {
218+
/**
219+
* Creates a StepExecutionResource instance with the contents of the response.json.
220+
* @param {Response} response instance that contains the json.
221+
* @returns {StepExecutionResource} instance of StepExecutionResource.
222+
*/
223+
extractStepExecutionData(response: Response): StepExecutionResource {
213224
const body = response.json();
214225
const stepExecutionItem = body.stepExecution;
215226
const stepExecutionResource: StepExecutionResource = new StepExecutionResource();
@@ -250,7 +261,12 @@ export class JobsService {
250261
return stepExecutionResource;
251262
}
252263

253-
private extractJobExecutionData(response: Response): JobExecution {
264+
/**
265+
* Creates a JobExecution instance with the contents of the response.json.
266+
* @param {Response} response instance that contains the json.
267+
* @returns {JobExecution} instance of JobExecution.
268+
*/
269+
extractJobExecutionData(response: Response): JobExecution {
254270
const jsonItem = response.json();
255271
const jobExecution: JobExecution = new JobExecution();
256272
jobExecution.name = jsonItem.name;
@@ -292,7 +308,12 @@ export class JobsService {
292308
return jobExecution;
293309
}
294310

295-
private extractData(response: Response): Page<JobExecution> {
311+
/**
312+
* Creates a page instance containing JobExecutions with the contents of the response.json.
313+
* @param {Response} response instance that contains the json.
314+
* @returns {Page<JobExecution>} instance of Page containing JobExecutions.
315+
*/
316+
extractData(response: Response): Page<JobExecution> {
296317
const body = response.json();
297318
const items: JobExecution[] = [];
298319

0 commit comments

Comments
 (0)