DefaultSchedulerService implements SchedulerService { @Override public void schedule(final String beanName, final Boolean forceScheduling) { if (this.applicationContext.containsBean(beanName)) { final Scheduler scheduler = this.applicationContext.getBean(beanName, Scheduler.class); if (scheduler.getSchedulerStatus().equals(SchedulerStatus.RUNNING) && Boolean.FALSE.equals(forceScheduling)) { log.info("Scheduler: " + beanName + " already running"); } else { scheduler.schedule(); } } else { throw new SpringBatchLightminConfigurationException("Could not schedule bean with name: " + beanName); } } DefaultSchedulerService(final BeanRegistrar beanRegistrar,
                                   final JobRepository jobRepository,
                                   final JobRegistry jobRegistry); @Autowired void setApplicationContext(final ApplicationContext applicationContext); @Override String registerSchedulerForJob(final JobConfiguration jobConfiguration); @Override void unregisterSchedulerForJob(final String beanName); @Override void refreshSchedulerForJob(final JobConfiguration jobConfiguration); @Override void schedule(final String beanName, final Boolean forceScheduling); @Override void terminate(final String beanName); @Override SchedulerStatus getSchedulerStatus(final String beanName); @Override void afterPropertiesSet(); @Override JobLauncher createLobLauncher(final TaskExecutorType taskExecutorType, final JobRepository jobRepository);  }
@Test public void scheduleTest() { final String beanName = "schedulerBean"; when(this.applicationContext.containsBean(beanName)).thenReturn(Boolean.TRUE); when(this.applicationContext.getBean(beanName, Scheduler.class)).thenReturn(this.scheduler); when(this.scheduler.getSchedulerStatus()).thenReturn(SchedulerStatus.INITIALIZED); this.schedulerService.schedule(beanName, Boolean.FALSE); verify(this.scheduler, times(1)).schedule(); }
@Test(expected = SpringBatchLightminConfigurationException.class) public void scheduleUnknownTest() { final String beanName = "schedulerBean"; when(this.applicationContext.containsBean(beanName)).thenReturn(Boolean.FALSE); this.schedulerService.schedule(beanName, Boolean.FALSE); }