DefaultListenerService implements ListenerService, InitializingBean { @Override public void activateListener(final String beanName, final Boolean forceActivation) { if (this.applicationContext.containsBean(beanName)) { final Listener listener = this.applicationContext.getBean(beanName, Listener.class); if (ListenerStatus.ACTIVE.equals(listener.getListenerStatus()) && Boolean.FALSE.equals(forceActivation)) { log.info("Listener: {} already running", beanName); } else { listener.start(); } } } DefaultListenerService(final BeanRegistrar beanRegistrar, final JobRegistry jobRegistry, final JobRepository jobRepository); @Autowired void setApplicationContext(final ApplicationContext applicationContext); @Override String registerListenerForJob(final JobConfiguration jobConfiguration); @Override void unregisterListenerForJob(final String beanName); @Override void refreshListenerForJob(final JobConfiguration jobConfiguration); @Override void activateListener(final String beanName, final Boolean forceActivation); @Override void terminateListener(final String beanName); @Override JobLauncher createLobLauncher(final TaskExecutorType taskExecutorType, final JobRepository jobRepository); @Override void afterPropertiesSet();  }
@Test public void testActivateListener() { final JobListenerConfiguration jobListenerConfiguration = DomainTestHelper.createJobListenerConfiguration ("src/test/", "*.txt", JobListenerType.LOCAL_FOLDER_LISTENER); jobListenerConfiguration.setBeanName("testBean"); jobListenerConfiguration.setListenerStatus(ListenerStatus.ACTIVE); final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobListenerConfiguration); final ListenerConstructorWrapper listenerConstructorWrapper = new ListenerConstructorWrapper(); listenerConstructorWrapper.setJobIncrementer(JobIncrementer.DATE); listenerConstructorWrapper.setJob(this.job); listenerConstructorWrapper.setJobConfiguration(jobConfiguration); listenerConstructorWrapper.setJobLauncher(this.jobLauncher); listenerConstructorWrapper.setJobParameters(new JobParametersBuilder().toJobParameters()); final FolderListener folderListener = new FolderListener(listenerConstructorWrapper); when(this.applicationContext.getBean(anyString(), any(Class.class))).thenReturn(folderListener); when(this.applicationContext.containsBean(anyString())).thenReturn(Boolean.TRUE); try { this.listenerService.activateListener("testBean", Boolean.FALSE); } catch (final Exception e) { fail(e.getMessage()); } }