67
67
import static org .mockito .Mockito .mock ;
68
68
import static org .springframework .restdocs .mockmvc .MockMvcRestDocumentation .document ;
69
69
import static org .springframework .restdocs .payload .PayloadDocumentation .fieldWithPath ;
70
+ import static org .springframework .restdocs .payload .PayloadDocumentation .relaxedResponseFields ;
70
71
import static org .springframework .restdocs .payload .PayloadDocumentation .responseFields ;
72
+ import static org .springframework .restdocs .payload .PayloadDocumentation .subsectionWithPath ;
71
73
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
72
74
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
73
75
@@ -88,24 +90,24 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
88
90
89
91
private static final JobDetail jobThree = JobBuilder .newJob (Job .class ).withIdentity ("jobThree" , "tests" ).build ();
90
92
91
- private static final CronTrigger triggerOne = TriggerBuilder .newTrigger ().forJob (jobOne ).withPriority (3 )
93
+ private static final CronTrigger cronTrigger = TriggerBuilder .newTrigger ().forJob (jobOne ).withPriority (3 )
92
94
.withDescription ("3AM on weekdays" ).withIdentity ("3am-weekdays" , "samples" )
93
95
.withSchedule (
94
96
CronScheduleBuilder .atHourAndMinuteOnGivenDaysOfWeek (3 , 0 , 1 , 2 , 3 , 4 , 5 ).inTimeZone (timeZone ))
95
97
.build ();
96
98
97
- private static final SimpleTrigger triggerTwo = TriggerBuilder .newTrigger ().forJob (jobOne ).withPriority (7 )
99
+ private static final SimpleTrigger simpleTrigger = TriggerBuilder .newTrigger ().forJob (jobOne ).withPriority (7 )
98
100
.withDescription ("Once a day" ).withIdentity ("every-day" , "samples" )
99
101
.withSchedule (SimpleScheduleBuilder .repeatHourlyForever (24 )).build ();
100
102
101
- private static final CalendarIntervalTrigger triggerThree = TriggerBuilder .newTrigger ().forJob (jobTwo )
103
+ private static final CalendarIntervalTrigger calendarIntervalTrigger = TriggerBuilder .newTrigger ().forJob (jobTwo )
102
104
.withDescription ("Once a week" ).withIdentity ("once-a-week" , "samples" )
103
105
.withSchedule (CalendarIntervalScheduleBuilder .calendarIntervalSchedule ().withIntervalInWeeks (1 )
104
106
.inTimeZone (timeZone ))
105
107
.build ();
106
108
107
- private static final DailyTimeIntervalTrigger triggerFour = TriggerBuilder .newTrigger (). forJob ( jobThree )
108
- .withDescription ("Every hour between 9AM and 6PM on Tuesday and Thursday" )
109
+ private static final DailyTimeIntervalTrigger dailyTimeIntervalTrigger = TriggerBuilder .newTrigger ()
110
+ .forJob ( jobThree ). withDescription ("Every hour between 9AM and 6PM on Tuesday and Thursday" )
109
111
.withIdentity ("every-hour-tue-thu" )
110
112
.withSchedule (DailyTimeIntervalScheduleBuilder .dailyTimeIntervalSchedule ()
111
113
.onDaysOfTheWeek (Calendar .TUESDAY , Calendar .THURSDAY )
@@ -148,9 +150,10 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
148
150
fieldWithPath ("name" ).description ("Name of the trigger." ),
149
151
fieldWithPath ("description" ).description ("Description of the trigger, if any." ),
150
152
fieldWithPath ("state" )
151
- .description ("State of the trigger, can be NONE, NORMAL, PAUSED, COMPLETE, ERROR, or BLOCKED ." ),
153
+ .description ("State of the trigger (" + describeEnumValues ( TriggerState . class ) + ") ." ),
152
154
fieldWithPath ("type" ).description (
153
- "Type of the trigger, determine the key of the object containing implementation-specific details." ),
155
+ "Type of the trigger (`calendarInterval`, `cron`, `custom`, `dailyTimeInterval`, `simple`). "
156
+ + "Determines the key of the object containing type-specific details." ),
154
157
fieldWithPath ("calendarName" ).description ("Name of the Calendar associated with this Trigger, if any." ),
155
158
startTime ("" ), endTime ("" ), previousFireTime ("" ), nextFireTime ("" ), priority ("" ),
156
159
fieldWithPath ("finalFireTime" ).optional ().type (JsonFieldType .STRING )
@@ -164,7 +167,7 @@ class QuartzEndpointDocumentationTests extends MockMvcEndpointDocumentationTests
164
167
@ Test
165
168
void quartzReport () throws Exception {
166
169
mockJobs (jobOne , jobTwo , jobThree );
167
- mockTriggers (triggerOne , triggerTwo , triggerThree , triggerFour );
170
+ mockTriggers (cronTrigger , simpleTrigger , calendarIntervalTrigger , dailyTimeIntervalTrigger );
168
171
this .mockMvc .perform (get ("/actuator/quartz" )).andExpect (status ().isOk ())
169
172
.andDo (document ("quartz/report" ,
170
173
responseFields (fieldWithPath ("jobs.groups" ).description ("An array of job group names." ),
@@ -181,7 +184,7 @@ void quartzJobs() throws Exception {
181
184
182
185
@ Test
183
186
void quartzTriggers () throws Exception {
184
- mockTriggers (triggerOne , triggerTwo , triggerThree , triggerFour );
187
+ mockTriggers (cronTrigger , simpleTrigger , calendarIntervalTrigger , dailyTimeIntervalTrigger );
185
188
this .mockMvc .perform (get ("/actuator/quartz/triggers" )).andExpect (status ().isOk ())
186
189
.andDo (document ("quartz/triggers" ,
187
190
responseFields (fieldWithPath ("groups" ).description ("Trigger groups keyed by name." ),
@@ -202,16 +205,17 @@ void quartzJobGroup() throws Exception {
202
205
203
206
@ Test
204
207
void quartzTriggerGroup () throws Exception {
205
- CronTrigger cron = triggerOne .getTriggerBuilder ().startAt (fromUtc ("2020-11-30T17:00:00Z" ))
208
+ CronTrigger cron = cronTrigger .getTriggerBuilder ().startAt (fromUtc ("2020-11-30T17:00:00Z" ))
206
209
.endAt (fromUtc ("2020-12-30T03:00:00Z" )).withIdentity ("3am-week" , "tests" ).build ();
207
210
setPreviousNextFireTime (cron , "2020-12-04T03:00:00Z" , "2020-12-07T03:00:00Z" );
208
- SimpleTrigger simple = triggerTwo .getTriggerBuilder ().withIdentity ("every-day" , "tests" ).build ();
211
+ SimpleTrigger simple = simpleTrigger .getTriggerBuilder ().withIdentity ("every-day" , "tests" ).build ();
209
212
setPreviousNextFireTime (simple , null , "2020-12-04T12:00:00Z" );
210
- CalendarIntervalTrigger calendarInterval = triggerThree .getTriggerBuilder ().withIdentity ("once-a-week" , "tests" )
211
- .startAt (fromUtc ("2019-07-10T14:00:00Z" )).endAt (fromUtc ("2023-01-01T12:00:00Z" )).build ();
213
+ CalendarIntervalTrigger calendarInterval = calendarIntervalTrigger .getTriggerBuilder ()
214
+ .withIdentity ("once-a-week" , "tests" ).startAt (fromUtc ("2019-07-10T14:00:00Z" ))
215
+ .endAt (fromUtc ("2023-01-01T12:00:00Z" )).build ();
212
216
setPreviousNextFireTime (calendarInterval , "2020-12-02T14:00:00Z" , "2020-12-08T14:00:00Z" );
213
- DailyTimeIntervalTrigger tueThuTrigger = triggerFour .getTriggerBuilder (). withIdentity ( "tue-thu" , "tests" )
214
- .build ();
217
+ DailyTimeIntervalTrigger tueThuTrigger = dailyTimeIntervalTrigger .getTriggerBuilder ()
218
+ .withIdentity ( "tue-thu" , "tests" ). build ();
215
219
Trigger customTrigger = mock (Trigger .class );
216
220
given (customTrigger .getKey ()).willReturn (TriggerKey .triggerKey ("once-a-year-custom" , "tests" ));
217
221
given (customTrigger .toString ()).willReturn ("com.example.CustomTrigger@fdsfsd" );
@@ -242,9 +246,9 @@ void quartzTriggerGroup() throws Exception {
242
246
@ Test
243
247
void quartzJob () throws Exception {
244
248
mockJobs (jobOne );
245
- CronTrigger firstTrigger = triggerOne .getTriggerBuilder ().build ();
249
+ CronTrigger firstTrigger = cronTrigger .getTriggerBuilder ().build ();
246
250
setPreviousNextFireTime (firstTrigger , null , "2020-12-07T03:00:00Z" );
247
- SimpleTrigger secondTrigger = triggerTwo .getTriggerBuilder ().build ();
251
+ SimpleTrigger secondTrigger = simpleTrigger .getTriggerBuilder ().build ();
248
252
setPreviousNextFireTime (secondTrigger , "2020-12-04T03:00:00Z" , "2020-12-04T12:00:00Z" );
249
253
mockTriggers (firstTrigger , secondTrigger );
250
254
given (this .scheduler .getTriggersOfJob (jobOne .getKey ()))
@@ -266,53 +270,71 @@ void quartzJob() throws Exception {
266
270
previousFireTime ("triggers.[]." ), nextFireTime ("triggers.[]." ), priority ("triggers.[]." ))));
267
271
}
268
272
273
+ @ Test
274
+ void quartzTriggerCommon () throws Exception {
275
+ setupTriggerDetails (cronTrigger .getTriggerBuilder (), TriggerState .NORMAL );
276
+ this .mockMvc .perform (get ("/actuator/quartz/triggers/samples/example" )).andExpect (status ().isOk ())
277
+ .andDo (document ("quartz/trigger-details-common" , responseFields (commonCronDetails ).and (
278
+ subsectionWithPath ("calendarInterval" ).description (
279
+ "Calendar time interval trigger details, if any. Present when `type` is `calendarInterval`." )
280
+ .optional ().type (JsonFieldType .OBJECT ),
281
+ subsectionWithPath ("custom" )
282
+ .description ("Custom trigger details, if any. Present when `type` is `custom`." )
283
+ .optional ().type (JsonFieldType .OBJECT ),
284
+ subsectionWithPath ("cron" )
285
+ .description ("Cron trigger details, if any. Present when `type` is `cron`." ).optional ()
286
+ .type (JsonFieldType .OBJECT ),
287
+ subsectionWithPath ("dailyTimeInterval" ).description (
288
+ "Daily time interval trigger details, if any. Present when `type` is `dailyTimeInterval`." )
289
+ .optional ().type (JsonFieldType .OBJECT ),
290
+ subsectionWithPath ("simple" )
291
+ .description ("Simple trigger details, if any. Present when `type` is `simple`." )
292
+ .optional ().type (JsonFieldType .OBJECT ))));
293
+ }
294
+
269
295
@ Test
270
296
void quartzTriggerCron () throws Exception {
271
- setupTriggerDetails (triggerOne .getTriggerBuilder (), TriggerState .NORMAL );
297
+ setupTriggerDetails (cronTrigger .getTriggerBuilder (), TriggerState .NORMAL );
272
298
this .mockMvc .perform (get ("/actuator/quartz/triggers/samples/example" )).andExpect (status ().isOk ())
273
299
.andDo (document ("quartz/trigger-details-cron" ,
274
- responseFields (commonCronDetails )
275
- .and (fieldWithPath ("cron" ).description ("Cron trigger specific details." ))
300
+ relaxedResponseFields (fieldWithPath ("cron" ).description ("Cron trigger specific details." ))
276
301
.andWithPrefix ("cron." , cronTriggerSummary )));
277
302
}
278
303
279
304
@ Test
280
305
void quartzTriggerSimple () throws Exception {
281
- setupTriggerDetails (triggerTwo .getTriggerBuilder (), TriggerState .NORMAL );
306
+ setupTriggerDetails (simpleTrigger .getTriggerBuilder (), TriggerState .NORMAL );
282
307
this .mockMvc .perform (get ("/actuator/quartz/triggers/samples/example" )).andExpect (status ().isOk ())
283
308
.andDo (document ("quartz/trigger-details-simple" ,
284
- responseFields (commonCronDetails )
285
- .and (fieldWithPath ("simple" ).description ("Simple trigger specific details." ))
309
+ relaxedResponseFields (fieldWithPath ("simple" ).description ("Simple trigger specific details." ))
286
310
.andWithPrefix ("simple." , simpleTriggerSummary )
287
311
.and (repeatCount ("simple." ), timesTriggered ("simple." ))));
288
312
}
289
313
290
314
@ Test
291
315
void quartzTriggerCalendarInterval () throws Exception {
292
- setupTriggerDetails (triggerThree .getTriggerBuilder (), TriggerState .NORMAL );
316
+ setupTriggerDetails (calendarIntervalTrigger .getTriggerBuilder (), TriggerState .NORMAL );
293
317
this .mockMvc .perform (get ("/actuator/quartz/triggers/samples/example" )).andExpect (status ().isOk ())
294
- .andDo (document ("quartz/trigger-details-calendar-interval" , responseFields (commonCronDetails )
295
- .and (fieldWithPath ("calendarInterval" )
296
- .description ("Calendar interval trigger specific details." ))
297
- .andWithPrefix ("calendarInterval." , calendarIntervalTriggerSummary )
298
- .and (timesTriggered ("calendarInterval." ),
299
- fieldWithPath ("calendarInterval.preserveHourOfDayAcrossDaylightSavings" ).description (
300
- "Whether to fire the trigger at the same time of day, regardless of daylight "
301
- + "saving time transitions." ),
302
- fieldWithPath ("calendarInterval.skipDayIfHourDoesNotExist" ).description (
303
- "Whether to skip if the hour of the day does not exist on a given day." ))));
318
+ .andDo (document ("quartz/trigger-details-calendar-interval" , relaxedResponseFields (
319
+ fieldWithPath ("calendarInterval" ).description ("Calendar interval trigger specific details." ))
320
+ .andWithPrefix ("calendarInterval." , calendarIntervalTriggerSummary )
321
+ .and (timesTriggered ("calendarInterval." ), fieldWithPath (
322
+ "calendarInterval.preserveHourOfDayAcrossDaylightSavings" ).description (
323
+ "Whether to fire the trigger at the same time of day, regardless of daylight "
324
+ + "saving time transitions." ),
325
+ fieldWithPath ("calendarInterval.skipDayIfHourDoesNotExist" ).description (
326
+ "Whether to skip if the hour of the day does not exist on a given day." ))));
304
327
}
305
328
306
329
@ Test
307
330
void quartzTriggerDailyTimeInterval () throws Exception {
308
- setupTriggerDetails (triggerFour .getTriggerBuilder (), TriggerState .PAUSED );
331
+ setupTriggerDetails (dailyTimeIntervalTrigger .getTriggerBuilder (), TriggerState .PAUSED );
309
332
this .mockMvc .perform (get ("/actuator/quartz/triggers/samples/example" )).andExpect (status ().isOk ())
310
333
.andDo (document ("quartz/trigger-details-daily-time-interval" ,
311
- responseFields (commonCronDetails )
312
- .and (fieldWithPath ("dailyTimeInterval" )
313
- .description ("Daily time interval trigger specific details." ))
314
- .andWithPrefix ("dailyTimeInterval." , dailyTimeIntervalTriggerSummary )
315
- .and (repeatCount ("dailyTimeInterval." ), timesTriggered ("dailyTimeInterval." ))));
334
+ relaxedResponseFields (fieldWithPath ("dailyTimeInterval" )
335
+ .description ("Daily time interval trigger specific details." ))
336
+ .andWithPrefix ("dailyTimeInterval." , dailyTimeIntervalTriggerSummary )
337
+ .and (repeatCount ("dailyTimeInterval." ), timesTriggered ("dailyTimeInterval." ))));
316
338
}
317
339
318
340
@ Test
@@ -331,8 +353,7 @@ void quartzTriggerCustom() throws Exception {
331
353
mockTriggers (trigger );
332
354
this .mockMvc .perform (get ("/actuator/quartz/triggers/samples/example" )).andExpect (status ().isOk ())
333
355
.andDo (document ("quartz/trigger-details-custom" ,
334
- responseFields (commonCronDetails )
335
- .and (fieldWithPath ("custom" ).description ("Custom trigger specific details." ))
356
+ relaxedResponseFields (fieldWithPath ("custom" ).description ("Custom trigger specific details." ))
336
357
.andWithPrefix ("custom." , customTriggerSummary )));
337
358
}
338
359
0 commit comments