@Test
	public void testInitialLaunchWithThreeJobParameters()
			throws ExecutionException, InterruptedException, TimeoutException {
		JobParameters originalJobParameters = new JobParametersBuilder()
				.addString("string", "baz")
				.addLong("long", 5l)
				.addDate("date", new Date(1l))
				.toJobParameters();
		JobInstance jobInstance = new JobInstance(3l, "masterFoo");
		JobExecution jobExecution = new JobExecution(5l, originalJobParameters);
		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 {
				JobParameters jobParameters = chunkContext.getStepContext().getStepExecution().getJobParameters();
				assertEquals(jobParameters.getString("string"), "baz");
				assertEquals((long) jobParameters.getLong("long"), 5l);
				assertEquals(jobParameters.getDate("date"), new Date(1));

				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());

		this.listeningChannel.send(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());
	}
@author Michael Minella
@author Gary Russell
spring-xd-dirt/src/test/java/org/springframework/xd/dirt/batch/tasklet/JobLaunchingTaskletTests.java