@Bean JobLauncherTestUtils jobLauncherTestUtils() { return new JobLauncherTestUtils(); }
@Test public void testJobLaunch() throws Exception { jobLauncherTestUtils.launchJob(); }
/** * Launch just the specified step in the job. An IllegalStateException is * thrown if there is no Step with the given name. * * @param stepName The name of the step to launch * @param jobParameters The JobParameters to use during the launch * @return JobExecution */ public JobExecution launchStep(String stepName, JobParameters jobParameters) { return this.launchStep(stepName, jobParameters, null); }
/** * Launch just the specified step in the job. A unique set of JobParameters * will automatically be generated. An IllegalStateException is thrown if * there is no Step with the given name. * * @param stepName The name of the step to launch * @return JobExecution */ public JobExecution launchStep(String stepName) { return this.launchStep(stepName, this.getUniqueJobParameters(), null); }
/** * Launch the entire job, including all steps. * * @return JobExecution, so that the test can validate the exit status * @throws Exception thrown if error occurs launching the job. */ public JobExecution launchJob() throws Exception { return this.launchJob(this.getUniqueJobParameters()); }
/** * Convenient method for subclasses to grab a {@link StepRunner} for running * steps by name. * * @return a {@link StepRunner} */ protected StepRunner getStepRunner() { if (this.stepRunner == null) { this.stepRunner = new StepRunner(getJobLauncher(), getJobRepository()); } return this.stepRunner; }
jobLauncherTestUtils = new JobLauncherTestUtils(); jobLauncherTestUtils.setJobLauncher(jobLauncher); jobLauncherTestUtils.setJobRepository(jobRepository); jobLauncherTestUtils.setJob(job); JobExecution jobExecution = jobLauncherTestUtils.launchJob(); Assert.assertNotNull(jobExecution); Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
@Bean public JobLauncherTestUtils testUtils() { JobLauncherTestUtils jobLauncherTestUtils = new JobLauncherTestUtils(); jobLauncherTestUtils.setJob(job()); return jobLauncherTestUtils; } }
protected JobParameters getUniqueJobParameters() { return jobLauncherTestUtils.getUniqueJobParameters(); }
/** * Launch the entire job, including all steps * * @param jobParameters instance of {@link JobParameters}. * @return JobExecution, so that the test can validate the exit status * @throws Exception thrown if error occurs launching the job. */ public JobExecution launchJob(JobParameters jobParameters) throws Exception { return getJobLauncher().run(this.job, jobParameters); }
@Test public void runTest() throws Exception { JobParameters jobParameters = jobLauncherTestUtils.getUniqueJobParameters(); JobExecution je1 = jobLauncherTestUtils.launchJob(jobParameters); assertEquals(BatchStatus.FAILED, je1.getStatus()); AssertFile.assertLineCount(10, outputResource); JobExecution je2 = jobLauncherTestUtils.launchJob(jobParameters); assertEquals(BatchStatus.COMPLETED, je2.getStatus()); AssertFile.assertLineCount(20, outputResource); }
/** * Launch just the specified step in the job. A unique set of JobParameters * will automatically be generated. An IllegalStateException is thrown if * there is no Step with the given name. * * @param stepName The name of the step to launch * @param jobExecutionContext An ExecutionContext whose values will be * loaded into the Job ExecutionContext prior to launching the step. * @return JobExecution */ public JobExecution launchStep(String stepName, ExecutionContext jobExecutionContext) { return this.launchStep(stepName, this.getUniqueJobParameters(), jobExecutionContext); }
/** * Output should be the same as input */ @Test public void testJob() throws Exception { jobLauncherTestUtils.launchJob(); AssertFile.assertFileEquals(new FileSystemResource(INPUT_FILE), new FileSystemResource(OUTPUT_FILE)); } }
@Bean public JobLauncherTestUtils utils() throws Exception { return new JobLauncherTestUtils(); }
@Test(expected = IllegalStateException.class) public void testNonExistentStep() { jobLauncherTestUtils.launchStep("nonExistent"); }
/** * Output should be the same as input */ @Test public void testJob() throws Exception { jobLauncherTestUtils.launchJob(); AssertFile.assertFileEquals(new FileSystemResource(INPUT_FILE), new FileSystemResource(OUTPUT_FILE)); } }
@Bean public JobLauncherTestUtils jobLauncherTestUtils() { return new JobLauncherTestUtils(); } }
@Test public void testStepExecutionWithJavaConfig() { ApplicationContext context = new AnnotationConfigApplicationContext(TestJobConfiguration.class); JobLauncherTestUtils testUtils = context.getBean(JobLauncherTestUtils.class); JobExecution execution = testUtils.launchStep("step1"); assertEquals(ExitStatus.COMPLETED, execution.getExitStatus()); }
@Test public void testJobLaunch() throws Exception { jobLauncherTestUtils.launchJob(); assertFileEquals(new ClassPathResource(EXPECTED), new FileSystemResource(ACTUAL)); }
@Bean public JobLauncherTestUtils jobLauncherTestUtils() { return new JobLauncherTestUtils(); } }