DefaultSchedulerService implements SchedulerService { @Override public String registerSchedulerForJob(final JobConfiguration jobConfiguration) { final JobSchedulerType schedulerType = jobConfiguration.getJobSchedulerConfiguration().getJobSchedulerType(); final String beanName; switch (schedulerType) { case CRON: beanName = this.registerScheduler(jobConfiguration, CronScheduler.class); break; case PERIOD: beanName = this.registerScheduler(jobConfiguration, PeriodScheduler.class); break; default: throw new SpringBatchLightminConfigurationException("Unknown Scheduler Type: " + schedulerType); } return 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 registerSchedulerForJobPeriodTest() throws NoSuchJobException { when(this.jobRegistry.getJob("sampleJob")).thenReturn(this.sampleJob); final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null, 10L, 10L, JobSchedulerType.PERIOD); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); jobConfiguration.setJobConfigurationId(1L); final String beanName = this.schedulerService.registerSchedulerForJob(jobConfiguration); assertThat(beanName).startsWith("sampleJob-PERIOD"); }
@Test public void registerSchedulerForJobCronTest() throws NoSuchJobException { when(this.jobRegistry.getJob("sampleJob")).thenReturn(this.sampleJob); final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration("* * *" + " * * *", null, null, JobSchedulerType.CRON); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); jobConfiguration.setJobConfigurationId(1L); final String beanName = this.schedulerService.registerSchedulerForJob(jobConfiguration); assertThat(beanName).startsWith("sampleJob-CRON"); }