@Test public void testDestroyCallback() throws Throwable { String[] args = new String[] { jobPath, jobName }; CommandLineJobRunner.main(args); assertTrue(StubJobLauncher.destroyed); }
@Test public void testJobAlreadyRunning() throws Throwable { StubJobLauncher.throwExecutionRunningException = true; CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); }
@Test public void testStopFailedAndRestarted() throws Throwable { String[] args = new String[] { jobPath, "-stop", jobName }; StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(5L, jobName)); CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); }
@Test public void testStop() throws Throwable { String[] args = new String[] { jobPath, "-stop", jobName }; StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(3L, jobName)); CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); }
@Test public void testStopRestarted() throws Throwable { String[] args = new String[] { jobPath, "-stop", jobName }; JobInstance jobInstance = new JobInstance(3L, jobName); StubJobExplorer.jobInstances = Arrays.asList(jobInstance); CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); }
@Test public void testAbandon() throws Throwable { String[] args = new String[] { jobPath, "-abandon", jobName }; StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobName)); CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); }
@Test public void testWrongJobName() throws Exception { String[] args = new String[] { jobPath, "no-such-job" }; CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); String errorMessage = CommandLineJobRunner.getErrorMessage(); assertTrue("Wrong error message: " + errorMessage, (errorMessage .contains("No bean named 'no-such-job' is defined") || (errorMessage .contains("No bean named 'no-such-job' available")))); }
@Test public void testAbandonAbandoned() throws Throwable { String[] args = new String[] { jobPath, "-abandon", jobName }; StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(4L, jobName)); CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); }
@Test public void testRestartNotFailed() throws Throwable { String[] args = new String[] { jobPath, "-restart", jobName }; StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(123L, jobName)); CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); String errorMessage = CommandLineJobRunner.getErrorMessage(); assertTrue("Wrong error message: " + errorMessage, errorMessage .contains("No failed or stopped execution found")); }
@Test public void testMain() throws Exception { CommandLineJobRunner.main(args); assertTrue("Injected JobParametersConverter not used instead of default", StubJobParametersConverter.called); assertEquals(0, StubSystemExiter.getStatus()); }
@Test public void testWithNoParameters() throws Throwable { String[] args = new String[] { jobPath, jobName }; CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); assertEquals(new JobParameters(), StubJobLauncher.jobParameters); }
@Test public void testNextFirstInSequence() throws Throwable { String[] args = new String[] { jobPath, "-next", jobName }; StubJobExplorer.jobInstances = new ArrayList<>(); CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); JobParameters jobParameters = new JobParametersBuilder().addString("foo", "spam").toJobParameters(); assertEquals(jobParameters, StubJobLauncher.jobParameters); }
@Test public void testInvalidArgs() throws Exception { String[] args = new String[] {}; CommandLineJobRunner.presetSystemExiter(new StubSystemExiter()); CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); String errorMessage = CommandLineJobRunner.getErrorMessage(); assertTrue("Wrong error message: " + errorMessage, errorMessage.contains("At least 2 arguments are required: JobPath/JobClass and jobIdentifier.")); }
@Test public void testJavaConfig() throws Exception { String[] args = new String[] { "org.springframework.batch.core.launch.support.CommandLineJobRunnerTests$Configuration1", "invalidJobName"}; CommandLineJobRunner.presetSystemExiter(new StubSystemExiter()); CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); String errorMessage = CommandLineJobRunner.getErrorMessage(); assertTrue("Wrong error message: " + errorMessage, errorMessage.contains("A JobLauncher must be provided. Please add one to the configuration.")); }
@Test public void testNextWithNoParameters() throws Exception { jobPath = ClassUtils.addResourcePathToPackagePath(CommandLineJobRunnerTests.class, "launcher-with-locator.xml"); CommandLineJobRunner.main(new String[] { jobPath, "-next", "test-job2", jobKey }); assertEquals(1, StubSystemExiter.getStatus()); String errorMessage = CommandLineJobRunner.getErrorMessage(); assertTrue("Wrong error message: " + errorMessage, errorMessage .contains(" No job parameters incrementer found")); }
@Test public void testWithJobLocator() throws Exception { jobPath = ClassUtils.addResourcePathToPackagePath(CommandLineJobRunnerTests.class, "launcher-with-locator.xml"); CommandLineJobRunner.main(new String[] { jobPath, jobName, jobKey }); assertTrue("Injected JobParametersConverter not used instead of default", StubJobParametersConverter.called); assertEquals(0, StubSystemExiter.getStatus()); }
@Test public void testRestart() throws Throwable { String[] args = new String[] { jobPath, "-restart", jobName }; JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters(); JobInstance jobInstance = new JobInstance(0L, jobName); StubJobExplorer.jobInstances = Arrays.asList(jobInstance); StubJobExplorer.jobParameters = jobParameters; CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); assertEquals(jobParameters, StubJobLauncher.jobParameters); StubJobExplorer.jobParameters = new JobParameters(); }
@Test public void testNext() throws Throwable { String[] args = new String[] { jobPath, "-next", jobName, "bar=foo" }; JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo") .toJobParameters(); StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobName)); CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); jobParameters = new JobParametersBuilder().addString("foo", "spam").addString("bar", "foo").toJobParameters(); assertEquals(jobParameters, StubJobLauncher.jobParameters); }
@Test public void testRestartExecution() throws Throwable { String[] args = new String[] { jobPath, "-restart", "11" }; JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters(); JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobName), 11L, jobParameters, null); jobExecution.setStatus(BatchStatus.FAILED); StubJobExplorer.jobExecution = jobExecution; CommandLineJobRunner.main(args); assertEquals(0, StubSystemExiter.status); assertEquals(jobParameters, StubJobLauncher.jobParameters); }
@Test public void testRestartExecutionNotFailed() throws Throwable { String[] args = new String[] { jobPath, "-restart", "11" }; JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters(); JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobName), 11L, jobParameters, null); jobExecution.setStatus(BatchStatus.COMPLETED); StubJobExplorer.jobExecution = jobExecution; CommandLineJobRunner.main(args); assertEquals(1, StubSystemExiter.status); assertEquals(null, StubJobLauncher.jobParameters); }