@Test public void testInterruptWithListener() throws Exception { step1.setProcessException(new JobInterruptedException("job interrupted!")); JobExecutionListener listener = mock(JobExecutionListener.class); listener.beforeJob(jobExecution); listener.afterJob(jobExecution); job.setJobExecutionListeners(new JobExecutionListener[] { listener }); job.execute(jobExecution); assertEquals(BatchStatus.STOPPED, jobExecution.getStatus()); }
/** * Call the registered listeners in reverse order, respecting and * prioritising those that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) */ @Override public void afterJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.afterJob(jobExecution); } }
/** * Call the registered listeners in order, respecting and prioritising those * that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) */ @Override public void beforeJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.iterator(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.beforeJob(jobExecution); } }
@Test public void testEmptySignatureNamedMethod() { AbstractTestComponent delegate = new AbstractTestComponent() { @SuppressWarnings("unused") public void aMethod() { executed = true; } }; factoryBean.setDelegate(delegate); Map<String, String> metaDataMap = new HashMap<>(); metaDataMap.put(AFTER_JOB.getPropertyName(), "aMethod"); factoryBean.setMetaDataMap(metaDataMap); JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject(); listener.afterJob(new JobExecution(1L)); assertTrue(delegate.isExecuted()); }
/** * Call the registered listeners in order, respecting and prioritising those * that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) */ @Override public void beforeJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.iterator(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.beforeJob(jobExecution); } }
@Test public void testWithInterface() throws Exception { JobListenerWithInterface delegate = new JobListenerWithInterface(); factoryBean.setDelegate(delegate); JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject(); JobExecution jobExecution = new JobExecution(11L); listener.beforeJob(jobExecution); listener.afterJob(jobExecution); assertTrue(delegate.beforeJobCalled); assertTrue(delegate.afterJobCalled); }
@Test public void testRightSignatureNamedMethod() { AbstractTestComponent delegate = new AbstractTestComponent() { @SuppressWarnings("unused") public void aMethod(JobExecution jobExecution) { executed = true; assertEquals(new Long(25), jobExecution.getId()); } }; factoryBean.setDelegate(delegate); Map<String, String> metaDataMap = new HashMap<>(); metaDataMap.put(AFTER_JOB.getPropertyName(), "aMethod"); factoryBean.setMetaDataMap(metaDataMap); JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject(); listener.afterJob(new JobExecution(25L)); assertTrue(delegate.isExecuted()); }
/** * Call the registered listeners in order, respecting and prioritising those * that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) */ @Override public void beforeJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.iterator(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.beforeJob(jobExecution); } }
@Test public void testWithAnnotations() throws Exception { AnnotatedTestClass delegate = new AnnotatedTestClass(); factoryBean.setDelegate(delegate); JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject(); JobExecution jobExecution = new JobExecution(11L); listener.beforeJob(jobExecution); listener.afterJob(jobExecution); assertTrue(delegate.beforeJobCalled); assertTrue(delegate.afterJobCalled); }
@Test public void testFactoryMethod() throws Exception { JobListenerWithInterface delegate = new JobListenerWithInterface(); Object listener = JobListenerFactoryBean.getListener(delegate); assertTrue(listener instanceof JobExecutionListener); ((JobExecutionListener) listener).afterJob(new JobExecution(11L)); assertTrue(delegate.afterJobCalled); }
/** * Call the registered listeners in order, respecting and prioritising those * that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) */ public void beforeJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.iterator(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.beforeJob(jobExecution); } }
@Test public void testEmptySignatureAnnotation() { AbstractTestComponent delegate = new AbstractTestComponent() { @AfterJob public void aMethod() { executed = true; } }; factoryBean.setDelegate(delegate); JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject(); listener.afterJob(new JobExecution(1L)); assertTrue(delegate.isExecuted()); }
/** * Call the registered listeners in order, respecting and prioritising those * that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#beforeJob(org.springframework.batch.core.JobExecution) */ @Override public void beforeJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.iterator(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.beforeJob(jobExecution); } }
@Test public void testRightSignatureAnnotation() { AbstractTestComponent delegate = new AbstractTestComponent() { @AfterJob public void aMethod(JobExecution jobExecution) { executed = true; assertEquals(new Long(25), jobExecution.getId()); } }; factoryBean.setDelegate(delegate); JobExecutionListener listener = (JobExecutionListener) factoryBean.getObject(); listener.afterJob(new JobExecution(25L)); assertTrue(delegate.isExecuted()); }
/** * Call the registered listeners in reverse order, respecting and * prioritising those that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) */ @Override public void afterJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.afterJob(jobExecution); } }
/** * Call the registered listeners in reverse order, respecting and * prioritising those that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) */ public void afterJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.afterJob(jobExecution); } }
/** * Call the registered listeners in reverse order, respecting and * prioritising those that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) */ @Override public void afterJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.afterJob(jobExecution); } }
/** * Call the registered listeners in reverse order, respecting and * prioritising those that implement {@link Ordered}. * @see org.springframework.batch.core.JobExecutionListener#afterJob(org.springframework.batch.core.JobExecution) */ @Override public void afterJob(JobExecution jobExecution) { for (Iterator<JobExecutionListener> iterator = listeners.reverse(); iterator.hasNext();) { JobExecutionListener listener = iterator.next(); listener.afterJob(jobExecution); } }