Source:
<code>public void testInitialLaunch() throws Exception { JobInstance jobInstance = new JobInstance(3l, "masterFoo"); JobExecution jobExecution = new JobExecution(5l); jobExecution.setJobInstance(jobInstance); StepExecution stepExecution = new StepExecution("masterFoo", jobExecution, 7l); final StepContribution stepContribution = new StepContribution(stepExecution); final ChunkContext chunkContext = new ChunkContext(new StepContext(stepExecution)); JobDefinition jobDefinition = new JobDefinition("foo", "foo"); when(jobDefinitionRepository.findOne("foo")).thenReturn(jobDefinition); when(instanceRepository.findOne("foo")).thenReturn(jobDefinition); doReturn(true).when(launchingChannel).send(any(Message.class)); FutureTask<RepeatStatus> result = new FutureTask<RepeatStatus>(new Callable<RepeatStatus>() { @Override public RepeatStatus call() throws Exception { return tasklet.execute(stepContribution, chunkContext); } }); taskExecutor.execute(result); <START> JobParameters jobParameters = new JobParametersBuilder().addString("xd_orchestration_id", "3").toJobParameters(); <END> JobExecution slaveExecution = new JobExecution(9l, jobParameters); slaveExecution.setStatus(BatchStatus.COMPLETED); slaveExecution.setEndTime(new Date()); Thread.sleep(1000l); tasklet.handleMessage(MessageBuilder.withPayload(slaveExecution).build()); assertEquals(result.get(5, TimeUnit.SECONDS), RepeatStatus.FINISHED); assertEquals(stepExecution.getExecutionContext().get("xd_orchestration_id"), "3"); verify(bus).bindPubSubConsumer(eq("tap:job:foo.job"), any(PublishSubscribeAmqpChannel.class), (Properties) isNull()); }</code><technical_language>if constant XD_ORCHESTRATION_ID instead of plain strings</technical_language>

Target:
public void testInitialLaunch() throws Exception { JobInstance jobInstance = new JobInstance(3l, "masterFoo"); JobExecution jobExecution = new JobExecution(5l); jobExecution.setJobInstance(jobInstance); StepExecution stepExecution = new StepExecution("masterFoo", jobExecution, 7l); final StepContribution stepContribution = new StepContribution(stepExecution); final ChunkContext chunkContext = new ChunkContext(new StepContext(stepExecution)); JobDefinition jobDefinition = new JobDefinition("foo", "foo"); when(jobDefinitionRepository.findOne("foo")).thenReturn(jobDefinition); when(instanceRepository.findOne("foo")).thenReturn(jobDefinition); doReturn(true).when(launchingChannel).send(any(Message.class)); FutureTask<RepeatStatus> result = new FutureTask<RepeatStatus>(new Callable<RepeatStatus>() { @Override public RepeatStatus call() throws Exception { return tasklet.execute(stepContribution, chunkContext); } }); taskExecutor.execute(result); JobParameters jobParameters = new JobParametersBuilder().addString(JobLaunchingTasklet.XD_ORCHESTRATION_ID, "3").toJobParameters(); JobExecution slaveExecution = new JobExecution(9l, jobParameters); slaveExecution.setStatus(BatchStatus.COMPLETED); slaveExecution.setEndTime(new Date()); Thread.sleep(1000l); tasklet.handleMessage(MessageBuilder.withPayload(slaveExecution).build()); assertEquals(result.get(5, TimeUnit.SECONDS), RepeatStatus.FINISHED); assertEquals(stepExecution.getExecutionContext().get(JobLaunchingTasklet.XD_ORCHESTRATION_ID), "3"); verify(bus).bindPubSubConsumer(eq("tap:job:foo.job"), any(PublishSubscribeAmqpChannel.class), (Properties) isNull()); }