@SuppressWarnings("unchecked")
	@Before
	public void before() throws Exception {
		ModuleDefinition moduleJobDefinition = TestModuleDefinitions.dummy("job", ModuleType.job);
		ArrayList<ModuleDefinition> moduleDefinitions = new ArrayList<ModuleDefinition>();
		moduleDefinitions.add(moduleJobDefinition);
		when(moduleRegistry.findDefinitions("job")).thenReturn(moduleDefinitions);
		when(moduleRegistry.findDefinition("job", ModuleType.job)).thenReturn(moduleJobDefinition);
		SimpleJob job1 = new SimpleJob("job1");
		SimpleJob job2 = new SimpleJob("job2");
		job2.setRestartable(false);

		SimpleJob job3 = new SimpleJob("job3complete");
		SimpleJob job4 = new SimpleJob("job4running");
		SimpleJob job5 = new SimpleJob("job5with-null-parameters");
		Collection<String> jobNames = new ArrayList<String>();
		jobNames.add(job1.getName());
		jobNames.add(job2.getName());
		jobNames.add(job3.getName());
		jobNames.add(job4.getName());
		jobNames.add(job5.getName());
		JobInstance jobInstance1 = new JobInstance(0l, job1.getName());
		JobInstance jobInstance2 = new JobInstance(2l, job2.getName());
		JobInstance jobInstance3 = new JobInstance(3l, job3.getName());
		JobInstance jobInstance4 = new JobInstance(4l, job4.getName());
		JobInstance jobInstance5 = new JobInstance(5l, job5.getName());
		Map<String, JobParameter> parametersMap1 = new HashMap<String, JobParameter>();
		parametersMap1.put("param1", new JobParameter("test", true));
		parametersMap1.put("param2", new JobParameter(123l, false));

		DefaultJobParametersValidator jobParametersValidator = new DefaultJobParametersValidator();
		String[] requiredStrings = new String[] {"myRequiredString"};
		jobParametersValidator.setRequiredKeys(requiredStrings);
		job5.setJobParametersValidator(jobParametersValidator);

		Map<String, JobParameter> parametersMap5 = new HashMap<String, JobParameter>();
		parametersMap5.put("somthingElse", new JobParameter("test", true));


		JobParameters jobParameters1 = new JobParameters(parametersMap1);
		JobParameters jobParameters2 = new JobParameters(parametersMap1);
		JobParameters jobParameters3 = new JobParameters(parametersMap1);
		JobParameters jobParameters5 = new JobParameters(parametersMap5);
		JobExecution jobExecution1 = new JobExecution(jobInstance1, 0l, jobParameters1, null);
		JobExecution jobExecution2 = new JobExecution(jobInstance2, 3l, jobParameters2, null);
		JobExecution jobExecution3 = new JobExecution(jobInstance3, 33l, jobParameters3, null);
		JobExecution jobExecution4 = new JobExecution(jobInstance4, 4l, jobParameters3, null);
		JobExecution jobExecution5 = new JobExecution(jobInstance5, 5l, jobParameters5, null);

		BatchStatus status = BatchStatus.COMPLETED;
		jobExecution3.setStatus(status);

		jobExecution2.setEndTime(new Date());
		jobExecution3.setEndTime(new Date());
		jobExecution5.setEndTime(new Date());

		Collection<JobExecution> jobExecutions1 = new ArrayList<JobExecution>();
		Collection<JobExecution> jobExecutions2 = new ArrayList<JobExecution>();

		StepExecution step1 = new StepExecution("step1", jobExecution1);
		StepExecution step2 = new StepExecution("step2", jobExecution1);
		List<StepExecution> stepExecutions1 = new ArrayList<StepExecution>();
		stepExecutions1.add(step1);
		stepExecutions1.add(step2);
		jobExecution1.addStepExecutions(stepExecutions1);
		StepExecution step3 = new StepExecution("step3", jobExecution2);
		List<StepExecution> stepExecutions2 = new ArrayList<StepExecution>();
		stepExecutions2.add(step3);
		jobExecution2.addStepExecutions(stepExecutions2);
		jobExecution3.addStepExecutions(stepExecutions2);
		jobExecution4.addStepExecutions(stepExecutions2);
		jobExecutions1.add(jobExecution1);
		jobExecutions1.add(jobExecution2);
		jobExecutions2.add(jobExecution2);
		// all the jobs are undeployed/deleted.
		when(jobLocator.getJobNames()).thenReturn(Collections.<String>emptyList());
		when(jobLocator.isRestartable("job1")).thenReturn(true);
		when(jobService.listJobs(0, 20)).thenReturn(jobNames);
		when(jobService.countJobExecutionsForJob(job1.getName())).thenReturn(2);
		when(jobService.countJobExecutionsForJob(job2.getName())).thenReturn(1);

		when(jobService.isIncrementable(job1.getName())).thenReturn(false);
		when(jobService.isIncrementable(job2.getName())).thenReturn(true);

		when(jobService.getTopLevelJobExecutions(5, 5)).thenReturn(jobExecutions1);
		when(jobService.getTopLevelJobExecutions(0, 20)).thenReturn(jobExecutions1);
		when(jobService.listJobExecutionsForJob(job2.getName(), 0, 20)).thenReturn(jobExecutions2);
		when(jobService.getJobExecution(jobExecution1.getId())).thenReturn(jobExecution1);
		when(jobService.getJobExecution(99999L)).thenThrow(new NoSuchJobExecutionException("Not found."));

		when(jobService.stop(3l)).thenThrow(JobExecutionNotRunningException.class);
		when(jobService.stop(5l)).thenThrow(NoSuchJobExecutionException.class);
		when(jobService.getJobExecution(1234l)).thenThrow(NoSuchJobExecutionException.class);

		when(jobService.getJobExecution(2L)).thenReturn(jobExecution2);
		when(jobLocator.getJob("job2")).thenReturn(job2);

		when(jobService.getJobExecution(33L)).thenReturn(jobExecution3);
		when(jobLocator.getJob("job3complete")).thenReturn(job3);
		when(jobService.getJobExecution(4L)).thenReturn(jobExecution4);
		when(jobService.getJobExecution(5L)).thenReturn(jobExecution5);
		when(jobLocator.getJob("job5with-null-parameters")).thenReturn(job5);
		when(jobService.getJobExecution(3333L)).thenThrow(NoSuchJobExecutionException.class);

	}
Tests REST compliance of {@link BatchJobExecutionsController} endpoints.

@author Ilayaperumal Gopinathan
@author Gunnar Hillert
spring-xd-dirt/src/test/java/org/springframework/xd/dirt/rest/BatchJobExecutionsControllerIntegrationTests.java