QuartzScheduler implements IScheduler { protected void setJobNextRun( Job job, Trigger trigger ) { Date nextFire = trigger.getNextFireTime(); job.setNextRun( nextFire != null && ( nextFire.getTime() < new Date().getTime() ) ? trigger.getFireTimeAfter( new Date() ) : nextFire ); } QuartzScheduler( SchedulerFactory schedulerFactory );  QuartzScheduler(); void setQuartzSchedulerFactory( SchedulerFactory quartzSchedulerFactory ); Scheduler getQuartzScheduler(); Job createJob( String jobName, String actionId, Map<String, Serializable> jobParams, IJobTrigger trigger ); Job createJob( String jobName, Class<? extends IAction> action, Map<String, Serializable> jobParams,
      IJobTrigger trigger ); Job createJob( String jobName, Class<? extends IAction> action, Map<String, Serializable> jobParams,
      IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider ); Job createJob( String jobName, String actionId, Map<String, Serializable> jobParams, IJobTrigger trigger,
      IBackgroundExecutionStreamProvider outputStreamProvider ); static Trigger createQuartzTrigger( IJobTrigger jobTrigger, QuartzJobKey jobId ); @Override void updateJob( String jobId, Map<String, Serializable> jobParams, IJobTrigger trigger ); Map<IScheduleSubject, ComplexJobTrigger> getAvailabilityWindows(); List<IJobResult> getJobHistory( String jobId ); void triggerNow( String jobId ); @SuppressWarnings( "unchecked" ) Job getJob( String jobId ); @SuppressWarnings( "unchecked" ) List<Job> getJobs( IJobFilter filter ); Integer getMinScheduleInterval( IScheduleSubject subject ); ComplexJobTrigger getSubjectAvailabilityWindow( IScheduleSubject subject ); void pause(); void pauseJob( String jobId ); void removeJob( String jobId ); void start(); void resumeJob( String jobId ); void setAvailabilityWindows( Map<IScheduleSubject, ComplexJobTrigger> availability ); void setMinScheduleInterval( IScheduleSubject subject, int intervalInSeconds ); void setSubjectAvailabilityWindow( IScheduleSubject subject, ComplexJobTrigger availability ); static ComplexJobTrigger createComplexTrigger( String cronExpression ); SchedulerStatus getStatus(); void shutdown(); static String prettyPrintMap( Map<String, Serializable> map ); void addListener( ISchedulerListener listener ); void setListeners( Collection<ISchedulerListener> listeners ); void fireJobCompleted( IAction actionBean, String actionUser, Map<String, Serializable> params,
      IBackgroundExecutionStreamProvider streamProvider ); @Override void validateJobParams( Map<String, Serializable> jobParams ); static final String RESERVEDMAPKEY_ACTIONCLASS; static final String RESERVEDMAPKEY_ACTIONUSER; static final String RESERVEDMAPKEY_ACTIONID; static final String RESERVEDMAPKEY_STREAMPROVIDER; static final String RESERVEDMAPKEY_STREAMPROVIDER_INPUTFILE; static final String RESERVEDMAPKEY_UIPASSPARAM; static final String RESERVEDMAPKEY_LINEAGE_ID; static final String RESERVEDMAPKEY_RESTART_FLAG; static final String RESERVEDMAPKEY_AUTO_CREATE_UNIQUE_FILENAME; static final String RESERVEDMAPKEY_APPEND_DATE_FORMAT; }
@Test public void testSetJobNextRunToTheFuture() { Trigger trigger = Mockito.mock( Trigger.class ); Job job = new Job(); QuartzScheduler quartzScheduler = new QuartzScheduler(); long nowDate = new Date().getTime(); long futureDate = nowDate+1000000000; Mockito.when( trigger.getNextFireTime() ).thenReturn( new Date( futureDate ) ); Mockito.when( trigger.getFireTimeAfter( any() ) ).thenReturn( new Date( nowDate ) ); quartzScheduler.setJobNextRun( job, trigger ); assertEquals( new Date( futureDate ), job.getNextRun() ); }
@Test public void testSetJobNextRunToThePast() { Trigger trigger = Mockito.mock( Trigger.class ); Job job = new Job(); QuartzScheduler quartzScheduler = new QuartzScheduler(); long nowDate = new Date().getTime(); long pastDate = nowDate-1000000000; Mockito.when( trigger.getNextFireTime() ).thenReturn( new Date( pastDate ) ); Mockito.when( trigger.getFireTimeAfter( any() ) ).thenReturn( new Date( nowDate ) ); quartzScheduler.setJobNextRun( job, trigger ); assertEquals( new Date( nowDate ), job.getNextRun() ); }
@Test public void testSetJobNextRunToNullDate() { Trigger trigger = Mockito.mock( Trigger.class ); Job job = new Job(); QuartzScheduler quartzScheduler = new QuartzScheduler(); long nowDate = new Date().getTime(); Mockito.when( trigger.getNextFireTime() ).thenReturn( null ); Mockito.when( trigger.getFireTimeAfter( any() ) ).thenReturn( new Date( nowDate ) ); quartzScheduler.setJobNextRun( job, trigger ); assertEquals( null, job.getNextRun() ); }