DefaultAdminService implements AdminService { @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") public void stopJobConfiguration(final Long jobConfigurationId) { try { final JobConfiguration jobConfiguration = this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); final JobSchedulerConfiguration jobSchedulerConfiguration = jobConfiguration.getJobSchedulerConfiguration(); final JobListenerConfiguration jobListenerConfiguration = jobConfiguration.getJobListenerConfiguration(); if (jobSchedulerConfiguration != null) { final String beanName = jobSchedulerConfiguration.getBeanName(); this.schedulerService.terminate(beanName); jobConfiguration.getJobSchedulerConfiguration().setSchedulerStatus(SchedulerStatus.STOPPED); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); } else if (jobListenerConfiguration != null) { final String beanName = jobListenerConfiguration.getBeanName(); this.listenerService.terminateListener(beanName); jobConfiguration.getJobListenerConfiguration().setListenerStatus(ListenerStatus.STOPPED); this.jobConfigurationRepository.update(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); } } catch (final NoSuchJobConfigurationException e) { throw new SpringBatchLightminApplicationException(e, e.getMessage()); } } DefaultAdminService(final JobConfigurationRepository jobConfigurationRepository,
                               final SchedulerService schedulerService,
                               final ListenerService listenerService,
                               final SpringBatchLightminCoreConfigurationProperties springBatchLightminCoreConfigurationProperties
    ); @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") void saveJobConfiguration(@Valid final JobConfiguration jobConfiguration); @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") void updateJobConfiguration(final JobConfiguration jobConfiguration); @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") void deleteJobConfiguration(final Long jobConfigurationId); @Override Collection<JobConfiguration> getJobConfigurationsByJobName(final String jobName); @Override Map<String, Collection<JobConfiguration>> getJobConfigurationMap(final Collection<String> jobNames); @Override Collection<JobConfiguration> getJobConfigurations(final Collection<String> jobNames); @Override JobConfiguration getJobConfigurationById(final Long jobConfigurationId); @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") void stopJobConfiguration(final Long jobConfigurationId); @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") void startJobConfiguration(final Long jobConfigurationId); @Override void afterPropertiesSet();  }
@Test public void stopJobConfigurationSchedulerTest() throws NoSuchJobConfigurationException { final String beanName = "schedulerBean"; final Long jobConfigurationId = 10L; when(this.properties.getApplicationName()).thenReturn(APPLICATION_NAME); final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper .createJobSchedulerConfiguration("* * * * * *", null, null, JobSchedulerType.CRON); jobSchedulerConfiguration.setBeanName(beanName); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); when(this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, APPLICATION_NAME)).thenReturn(jobConfiguration); this.defaultAdminService.stopJobConfiguration(jobConfigurationId); verify(this.schedulerService, times(1)).terminate(beanName); }
@Test public void stopJobConfigurationListenerTest() throws NoSuchJobConfigurationException { final Long jobConfigurationId = 1L; when(this.properties.getApplicationName()).thenReturn(APPLICATION_NAME); final String beanName = "schedulerBean"; final JobListenerConfiguration jobListenerConfiguration = DomainTestHelper.createJobListenerConfiguration ("src/test/", "*.txt", JobListenerType.LOCAL_FOLDER_LISTENER); jobListenerConfiguration.setBeanName(beanName); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobListenerConfiguration); jobListenerConfiguration.setBeanName(beanName); when(this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, APPLICATION_NAME)).thenReturn(jobConfiguration); this.defaultAdminService.stopJobConfiguration(jobConfigurationId); verify(this.listenerService, times(1)).terminateListener(beanName); }
@SuppressWarnings("unchecked") @Test(expected = SpringBatchLightminApplicationException.class) public void stopJobConfigurationSchedulerExceptionTest() throws NoSuchJobConfigurationException { final Long jobConfigurationId = 10L; when(this.properties.getApplicationName()).thenReturn(APPLICATION_NAME); when(this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, APPLICATION_NAME)) .thenThrow(NoSuchJobConfigurationException.class); this.defaultAdminService.stopJobConfiguration(jobConfigurationId); }