mardi 21 avril 2015

howto inject context execution at test time of a single spring batch step?

I would like to inject, in a single step test (so "at test time"), some context values that are provided at runtime of my sprint batch steps flow.

I have already browsed this. But it's not very clear...

Below my simple test case, enriched by what i red here. There must be an error because i see no effect of my injection even if i enter fine into the getStepExecution() :

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:launch-context.xml" })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class })   // Inject feature enablers ?
public class ImportJobOrganisationViaRouting extends DwhITest {
        
        protected static final Logger logger = LoggerFactory.getLogger(ImportJobOrganisationViaRouting.class);

        @Autowired
        protected  JobLauncher jobLauncher;

        @Autowired
        @Qualifier("myjob")
        protected  Job job;

        protected JobParameters jobParameters;
        
        private static JobExecution jobExecution;

        // Inject values in here ?...
        public StepExecution getStepExection() {
                System.out.println("!!!!!! TEST inject EXECUTION STEP !!!!!!!");
                StepExecution execution = MetaDataInstanceFactory.createStepExecution();
                execution.getExecutionContext().putLong("dateKey", 200);
                return execution;
        }

        
        @Test
        public void launch() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
                
                jobParameters = new JobParametersBuilder().addLong("currTime", System.currentTimeMillis()).toJobParameters();
                jobExecution = jobLauncher.run(job, jobParameters);
                assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

        }

How to deal with this need ?

A lttle help would be deeply appreciated.

Thx in advance, ;-)

Aucun commentaire:

Enregistrer un commentaire