@@ -3,6 +3,29 @@ import { Observable } from 'rxjs/Rx';
3
3
import { JobsService } from './jobs.service' ;
4
4
import { HttpUtils } from '../shared/support/http.utils' ;
5
5
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
+ }
6
29
7
30
describe ( 'JobsService' , ( ) => {
8
31
@@ -34,11 +57,218 @@ describe('JobsService', () => {
34
57
} ) ;
35
58
} ) ;
36
59
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
+
37
75
describe ( 'getJobExecution' , ( ) => {
38
76
it ( 'should call the jobs service with the right url to get job execution' , ( ) => {
39
77
this . mockHttp . get . and . returnValue ( Observable . of ( this . jsonData ) ) ;
40
78
this . jobsService . getJobExecution ( '1' ) ;
41
79
expect ( this . mockHttp . get ) . toHaveBeenCalledWith ( '/jobs/executions/1' , { } ) ;
42
80
} ) ;
43
81
} ) ;
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
+
44
274
} ) ;
0 commit comments