DefaultAdminService implements AdminService { @Override @Transactional(propagation = Propagation.REQUIRED, transactionManager = "lightminTransactionManager") public void deleteJobConfiguration(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); this.schedulerService.unregisterSchedulerForJob(beanName); this.jobConfigurationRepository.delete(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); } if (jobListenerConfiguration != null) { final String beanName = jobListenerConfiguration.getBeanName(); this.listenerService.terminateListener(beanName); this.jobConfigurationRepository.delete(jobConfiguration, this.springBatchLightminCoreConfigurationProperties.getApplicationName()); } } catch (final NoSuchJobConfigurationException e) { log.error(e.getMessage()); 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 deleteJobConfigurationTest() { final Long jobConfigurationId = 1L; when(this.properties.getApplicationName()).thenReturn(APPLICATION_NAME); final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration( "0 0/5 * * * ?", null, null, JobSchedulerType.CRON); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); jobConfiguration.setJobConfigurationId(jobConfigurationId); try { when(this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, APPLICATION_NAME)).thenReturn(jobConfiguration); } catch (final NoSuchJobConfigurationException e) { fail(e.getMessage()); } try { this.defaultAdminService.deleteJobConfiguration(jobConfigurationId); } catch (final SpringBatchLightminApplicationException e) { fail(e.getMessage()); } }
@Test public void deleteJobConfigurationWithListenerTest() { final Long jobConfigurationId = 1L; when(this.properties.getApplicationName()).thenReturn(APPLICATION_NAME); final JobListenerConfiguration jobListenerConfiguration = DomainTestHelper.createJobListenerConfiguration ("src/test/", "*.txt", JobListenerType.LOCAL_FOLDER_LISTENER); jobListenerConfiguration.setBeanName("testBean"); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobListenerConfiguration); jobConfiguration.setJobConfigurationId(jobConfigurationId); try { when(this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, APPLICATION_NAME)).thenReturn(jobConfiguration); } catch (final NoSuchJobConfigurationException e) { fail(e.getMessage()); } try { this.defaultAdminService.deleteJobConfiguration(jobConfigurationId); } catch (final SpringBatchLightminApplicationException e) { fail(e.getMessage()); } }
@Test(expected = SpringBatchLightminApplicationException.class) public void deleteJobConfigurationErrorTest() { final Long jobConfigurationId = 1L; when(this.properties.getApplicationName()).thenReturn(APPLICATION_NAME); final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration( "0 0/5 * * * ?", null, null, JobSchedulerType.CRON); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration); jobConfiguration.setJobConfigurationId(jobConfigurationId); try { when(this.jobConfigurationRepository.getJobConfiguration(jobConfigurationId, APPLICATION_NAME)).thenReturn(jobConfiguration); doThrow(NoSuchJobConfigurationException.class).when(this.jobConfigurationRepository).delete(jobConfiguration, APPLICATION_NAME); } catch (final NoSuchJobConfigurationException e) { fail(e.getMessage()); } this.defaultAdminService.deleteJobConfiguration(jobConfigurationId); }