|
24 | 24 | import java.util.Date;
|
25 | 25 | import java.util.LinkedHashSet;
|
26 | 26 | import java.util.List;
|
| 27 | +import java.util.Map; |
27 | 28 | import java.util.Map.Entry;
|
28 | 29 | import java.util.TimeZone;
|
29 | 30 |
|
|
54 | 55 | import org.springframework.boot.actuate.endpoint.Show;
|
55 | 56 | import org.springframework.boot.actuate.quartz.QuartzEndpoint;
|
56 | 57 | import org.springframework.boot.actuate.quartz.QuartzEndpointWebExtension;
|
| 58 | +import org.springframework.boot.json.JsonWriter; |
57 | 59 | import org.springframework.context.annotation.Bean;
|
58 | 60 | import org.springframework.context.annotation.Configuration;
|
59 | 61 | import org.springframework.context.annotation.Import;
|
| 62 | +import org.springframework.http.MediaType; |
60 | 63 | import org.springframework.restdocs.payload.FieldDescriptor;
|
61 | 64 | import org.springframework.restdocs.payload.JsonFieldType;
|
62 | 65 | import org.springframework.scheduling.quartz.DelegatingJob;
|
|
68 | 71 | import static org.mockito.BDDMockito.given;
|
69 | 72 | import static org.mockito.Mockito.mock;
|
70 | 73 | import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
| 74 | +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; |
| 75 | +import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse; |
| 76 | +import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint; |
71 | 77 | import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
| 78 | +import static org.springframework.restdocs.payload.PayloadDocumentation.relaxedRequestFields; |
72 | 79 | import static org.springframework.restdocs.payload.PayloadDocumentation.relaxedResponseFields;
|
73 | 80 | import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
74 | 81 | import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath;
|
@@ -385,6 +392,28 @@ void quartzTriggerCustom() throws Exception {
|
385 | 392 | .andWithPrefix("custom.", customTriggerSummary)));
|
386 | 393 | }
|
387 | 394 |
|
| 395 | + @Test |
| 396 | + void quartzTriggerJob() throws Exception { |
| 397 | + mockJobs(jobOne); |
| 398 | + String json = JsonWriter.<Map<String, Object>>of((members) -> members.addMapEntries(Map::copyOf)) |
| 399 | + .write(Map.of("jobData", Map.of("key", "value", "keyN", "valueN"))) |
| 400 | + .toJsonString(); |
| 401 | + assertThat(this.mvc.post() |
| 402 | + .uri("/actuator/quartz/jobs/samples/jobOne/trigger") |
| 403 | + .content(json) |
| 404 | + .contentType(MediaType.APPLICATION_JSON)) |
| 405 | + .hasStatusOk() |
| 406 | + .apply(document("quartz/trigger-job", preprocessRequest(), preprocessResponse(prettyPrint()), |
| 407 | + relaxedRequestFields(fieldWithPath("jobData").description( |
| 408 | + "A Quartz key-value JobDataMap, that will be associated with the trigger, that fires the job immediately."), |
| 409 | + fieldWithPath("jobData.key") |
| 410 | + .description("An arbitrary name that will be used as a key in JobDataMap.")), |
| 411 | + responseFields(fieldWithPath("group").description("Name of the group."), |
| 412 | + fieldWithPath("name").description("Name of the job."), |
| 413 | + fieldWithPath("className").description("Fully qualified name of the job implementation."), |
| 414 | + fieldWithPath("triggerTime").description("Time the job is triggered.")))); |
| 415 | + } |
| 416 | + |
388 | 417 | private <T extends Trigger> void setupTriggerDetails(TriggerBuilder<T> builder, TriggerState state)
|
389 | 418 | throws SchedulerException {
|
390 | 419 | T trigger = builder.withIdentity("example", "samples")
|
|
0 commit comments