|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
66 | 66 | import org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetailsDescriptor;
|
67 | 67 | import org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobGroupSummaryDescriptor;
|
68 | 68 | import org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobSummaryDescriptor;
|
| 69 | +import org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobTriggerDescriptor; |
69 | 70 | import org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzTriggerGroupSummaryDescriptor;
|
70 | 71 | import org.springframework.scheduling.quartz.DelegatingJob;
|
71 | 72 | import org.springframework.util.LinkedMultiValueMap;
|
72 | 73 | import org.springframework.util.MultiValueMap;
|
73 | 74 |
|
74 | 75 | import static org.assertj.core.api.Assertions.assertThat;
|
75 | 76 | import static org.assertj.core.api.Assertions.entry;
|
| 77 | +import static org.assertj.core.api.Assertions.within; |
| 78 | +import static org.mockito.ArgumentMatchers.any; |
76 | 79 | import static org.mockito.BDDMockito.given;
|
77 | 80 | import static org.mockito.BDDMockito.then;
|
78 | 81 | import static org.mockito.Mockito.mock;
|
| 82 | +import static org.mockito.Mockito.never; |
79 | 83 |
|
80 | 84 | /**
|
81 | 85 | * Tests for {@link QuartzEndpoint}.
|
@@ -755,6 +759,31 @@ void quartzJobWithDataMapAndShowUnsanitizedFalse() throws SchedulerException {
|
755 | 759 | entry("url", "******"));
|
756 | 760 | }
|
757 | 761 |
|
| 762 | + @Test |
| 763 | + void quartzJobShouldBeTriggered() throws SchedulerException { |
| 764 | + JobDetail job = JobBuilder.newJob(Job.class) |
| 765 | + .withIdentity("hello", "samples") |
| 766 | + .withDescription("A sample job") |
| 767 | + .storeDurably() |
| 768 | + .requestRecovery(false) |
| 769 | + .build(); |
| 770 | + mockJobs(job); |
| 771 | + QuartzJobTriggerDescriptor quartzJobTriggerDescriptor = this.endpoint.triggerQuartzJob("samples", "hello"); |
| 772 | + assertThat(quartzJobTriggerDescriptor).isNotNull(); |
| 773 | + assertThat(quartzJobTriggerDescriptor.getName()).isEqualTo("hello"); |
| 774 | + assertThat(quartzJobTriggerDescriptor.getGroup()).isEqualTo("samples"); |
| 775 | + assertThat(quartzJobTriggerDescriptor.getClassName()).isEqualTo("org.quartz.Job"); |
| 776 | + assertThat(quartzJobTriggerDescriptor.getTriggerTime()).isCloseTo(Instant.now(), within(5, ChronoUnit.SECONDS)); |
| 777 | + then(this.scheduler).should().triggerJob(new JobKey("hello", "samples")); |
| 778 | + } |
| 779 | + |
| 780 | + @Test |
| 781 | + void quartzJobShouldNotBeTriggeredJobDoesNotExist() throws SchedulerException { |
| 782 | + QuartzJobTriggerDescriptor quartzJobTriggerDescriptor = this.endpoint.triggerQuartzJob("samples", "hello"); |
| 783 | + assertThat(quartzJobTriggerDescriptor).isNull(); |
| 784 | + then(this.scheduler).should(never()).triggerJob(any()); |
| 785 | + } |
| 786 | + |
758 | 787 | private void mockJobs(JobDetail... jobs) throws SchedulerException {
|
759 | 788 | MultiValueMap<String, JobKey> jobKeys = new LinkedMultiValueMap<>();
|
760 | 789 | for (JobDetail jobDetail : jobs) {
|
|
0 commit comments