Search in sources :

Example 1 with QuartzJobDetails

use of org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobOrdersTriggersAccordingNextFireTimeAndPriority.

@Test
void quartzJobOrdersTriggersAccordingNextFireTimeAndPriority() throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").build();
    mockJobs(job);
    Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
    CronTrigger triggerOne = TriggerBuilder.newTrigger().withIdentity("one", "samples").withPriority(3).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).build();
    ((OperableTrigger) triggerOne).setNextFireTime(nextFireTime);
    CronTrigger triggerTwo = TriggerBuilder.newTrigger().withIdentity("two", "samples").withPriority(7).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0)).build();
    ((OperableTrigger) triggerTwo).setNextFireTime(nextFireTime);
    mockTriggers(triggerOne, triggerTwo);
    given(this.scheduler.getTriggersOfJob(JobKey.jobKey("hello", "samples"))).willAnswer((invocation) -> Arrays.asList(triggerOne, triggerTwo));
    QuartzJobDetails jobDetails = this.endpoint.quartzJob("samples", "hello");
    assertThat(jobDetails.getTriggers()).hasSize(2);
    assertThat(jobDetails.getTriggers().get(0)).containsEntry("name", "two");
    assertThat(jobDetails.getTriggers().get(1)).containsEntry("name", "one");
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with QuartzJobDetails

use of org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobWithSensitiveDataMap.

@Test
void quartzJobWithSensitiveDataMap() throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").usingJobData("user", "user").usingJobData("password", "secret").usingJobData("url", "https://user:secret@example.com").build();
    mockJobs(job);
    QuartzJobDetails jobDetails = this.endpoint.quartzJob("samples", "hello");
    assertThat(jobDetails.getData()).containsOnly(entry("user", "user"), entry("password", "******"), entry("url", "https://user:******@example.com"));
}
Also used : JobDetail(org.quartz.JobDetail) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Job(org.quartz.Job) DelegatingJob(org.springframework.scheduling.quartz.DelegatingJob) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with QuartzJobDetails

use of org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobWithoutTrigger.

@Test
void quartzJobWithoutTrigger() throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").withDescription("A sample job").storeDurably().requestRecovery(false).build();
    mockJobs(job);
    QuartzJobDetails jobDetails = this.endpoint.quartzJob("samples", "hello");
    assertThat(jobDetails.getGroup()).isEqualTo("samples");
    assertThat(jobDetails.getName()).isEqualTo("hello");
    assertThat(jobDetails.getDescription()).isEqualTo("A sample job");
    assertThat(jobDetails.getClassName()).isEqualTo(Job.class.getName());
    assertThat(jobDetails.isDurable()).isTrue();
    assertThat(jobDetails.isRequestRecovery()).isFalse();
    assertThat(jobDetails.getData()).isEmpty();
    assertThat(jobDetails.getTriggers()).isEmpty();
}
Also used : JobDetail(org.quartz.JobDetail) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Job(org.quartz.Job) DelegatingJob(org.springframework.scheduling.quartz.DelegatingJob) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with QuartzJobDetails

use of org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobWithSensitiveDataMapAndCustomSanitizier.

@Test
void quartzJobWithSensitiveDataMapAndCustomSanitizier() throws SchedulerException {
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").usingJobData("test", "value").usingJobData("secret", "value").build();
    mockJobs(job);
    Sanitizer sanitizer = mock(Sanitizer.class);
    given(sanitizer.sanitize("test", "value")).willReturn("value");
    given(sanitizer.sanitize("secret", "value")).willReturn("----");
    QuartzJobDetails jobDetails = new QuartzEndpoint(this.scheduler, sanitizer).quartzJob("samples", "hello");
    assertThat(jobDetails.getData()).containsOnly(entry("test", "value"), entry("secret", "----"));
    then(sanitizer).should().sanitize("test", "value");
    then(sanitizer).should().sanitize("secret", "value");
    then(sanitizer).shouldHaveNoMoreInteractions();
}
Also used : JobDetail(org.quartz.JobDetail) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Sanitizer(org.springframework.boot.actuate.endpoint.Sanitizer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with QuartzJobDetails

use of org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails in project spring-boot by spring-projects.

the class QuartzEndpointTests method quartzJobWithTrigger.

@Test
void quartzJobWithTrigger() throws SchedulerException {
    Date previousFireTime = Date.from(Instant.parse("2020-11-30T03:00:00Z"));
    Date nextFireTime = Date.from(Instant.parse("2020-12-01T03:00:00Z"));
    JobDetail job = JobBuilder.newJob(Job.class).withIdentity("hello", "samples").build();
    TimeZone timeZone = TimeZone.getTimeZone("Europe/Paris");
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity("3am-every-day", "samples").withPriority(4).withSchedule(CronScheduleBuilder.dailyAtHourAndMinute(3, 0).inTimeZone(timeZone)).build();
    ((OperableTrigger) trigger).setPreviousFireTime(previousFireTime);
    ((OperableTrigger) trigger).setNextFireTime(nextFireTime);
    mockJobs(job);
    mockTriggers(trigger);
    given(this.scheduler.getTriggersOfJob(JobKey.jobKey("hello", "samples"))).willAnswer((invocation) -> Collections.singletonList(trigger));
    QuartzJobDetails jobDetails = this.endpoint.quartzJob("samples", "hello");
    assertThat(jobDetails.getTriggers()).hasSize(1);
    Map<String, Object> triggerDetails = jobDetails.getTriggers().get(0);
    assertThat(triggerDetails).containsOnly(entry("group", "samples"), entry("name", "3am-every-day"), entry("previousFireTime", previousFireTime), entry("nextFireTime", nextFireTime), entry("priority", 4));
}
Also used : OperableTrigger(org.quartz.spi.OperableTrigger) JobDetail(org.quartz.JobDetail) TimeZone(java.util.TimeZone) CalendarIntervalTrigger(org.quartz.CalendarIntervalTrigger) CronTrigger(org.quartz.CronTrigger) DailyTimeIntervalTrigger(org.quartz.DailyTimeIntervalTrigger) OperableTrigger(org.quartz.spi.OperableTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) QuartzJobDetails(org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 JobDetail (org.quartz.JobDetail)6 QuartzJobDetails (org.springframework.boot.actuate.quartz.QuartzEndpoint.QuartzJobDetails)6 Date (java.util.Date)3 CronTrigger (org.quartz.CronTrigger)3 OperableTrigger (org.quartz.spi.OperableTrigger)3 Job (org.quartz.Job)2 DelegatingJob (org.springframework.scheduling.quartz.DelegatingJob)2 TimeZone (java.util.TimeZone)1 CalendarIntervalTrigger (org.quartz.CalendarIntervalTrigger)1 DailyTimeIntervalTrigger (org.quartz.DailyTimeIntervalTrigger)1 SimpleTrigger (org.quartz.SimpleTrigger)1 Trigger (org.quartz.Trigger)1 Sanitizer (org.springframework.boot.actuate.endpoint.Sanitizer)1