JobScheduleController { public synchronized void rescheduleJob(final String cron) { try { CronTrigger trigger = (CronTrigger) scheduler.getTrigger(TriggerKey.triggerKey(triggerIdentity)); if (!scheduler.isShutdown() && null != trigger && !cron.equals(trigger.getCronExpression())) { scheduler.rescheduleJob(TriggerKey.triggerKey(triggerIdentity), createCronTrigger(cron)); } } catch (final SchedulerException ex) { throw new JobSystemException(ex); } }  void scheduleJob(final String cron); synchronized void rescheduleJob(final String cron); synchronized void rescheduleJob(); synchronized boolean isPaused(); synchronized void pauseJob(); synchronized void resumeJob(); synchronized void triggerJob(); synchronized void shutdown(); synchronized void shutdown(final boolean isCleanShutdown);  }
@Test public void assertRescheduleJobIfShutdown() throws SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); when(scheduler.isShutdown()).thenReturn(true); jobScheduleController.rescheduleJob("0/1 * * * * ?"); verify(scheduler, times(0)).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }
@Test(expected = JobSystemException.class) public void assertRescheduleJobFailure() throws SchedulerException { when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new CronTriggerImpl()); doThrow(SchedulerException.class).when(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); try { jobScheduleController.rescheduleJob("0/1 * * * * ?"); } finally { verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); } }
@Test public void assertRescheduleJobSuccess() throws SchedulerException { when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new CronTriggerImpl()); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); jobScheduleController.rescheduleJob("0/1 * * * * ?"); verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }
@Test public void assertRescheduleJobWhenTriggerIsNull() throws SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); jobScheduleController.rescheduleJob("0/1 * * * * ?"); verify(scheduler, times(0)).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }
@Test public void assertRescheduleJobIfShutdownForOneOffJob() throws SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); when(scheduler.isShutdown()).thenReturn(true); jobScheduleController.rescheduleJob(); verify(scheduler, times(0)).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }
@Test(expected = JobSystemException.class) public void assertRescheduleJobFailureForOneOffJob() throws SchedulerException { when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new SimpleTriggerImpl()); doThrow(SchedulerException.class).when(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); try { jobScheduleController.rescheduleJob(); } finally { verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); } }
@Test public void assertRescheduleJobSuccessForOneOffJob() throws SchedulerException { when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new SimpleTriggerImpl()); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); jobScheduleController.rescheduleJob(); verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }
@Test public void assertRescheduleJobWhenTriggerIsNullForOneOffJob() throws SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); jobScheduleController.rescheduleJob(); verify(scheduler, times(0)).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), any()); }