protected JobLauncher createJobLauncher() throws Exception { SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.afterPropertiesSet(); return jobLauncher; }
/** * Delegate to the exiter to (possibly) exit the VM gracefully. * * @param status int exit code that should be reported. */ public void exit(int status) { systemExiter.exit(status); }
private JobExecution getLastFailedJobExecution(String jobIdentifier) { List<JobExecution> jobExecutions = getJobExecutionsWithStatusGreaterThan(jobIdentifier, BatchStatus.STOPPING); if (jobExecutions.isEmpty()) { return null; } return jobExecutions.get(0); }
@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.")); }
@Override public String getSummary(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); return jobExecution.toString(); }
public void testGetExitCodeWithDefaultCode() { assertEquals( ecm.intValue("UNDEFINED_CUSTOM_CODE"), ExitCodeMapper.JVM_EXITCODE_GENERIC_ERROR); }
public void testNullArgs() { assertEquals(new JobParameters(), factory.getJobParameters(null)); assertEquals(new Properties(), factory.getProperties(null)); }
public void testGetParametersWithBogusDate() throws Exception { String[] args = new String[] { "schedule.date=20080123" }; try { factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "=")); } catch (IllegalArgumentException e) { String message = e.getMessage(); assertTrue("Message should contain wrong date: " + message, contains(message, "20080123")); } }
public void testGetParameters() throws Exception { String jobKey = "job.key=myKey"; String scheduleDate = "schedule.date=2008/01/23"; String vendorId = "vendor.id=33243243"; String[] args = new String[] { jobKey, scheduleDate, vendorId }; JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "=")); assertNotNull(props); assertEquals("myKey", props.getString("job.key")); assertEquals("33243243", props.getString("vendor.id")); Date date = dateFormat.parse("01/23/2008"); assertEquals(date, props.getDate("schedule.date")); }
public void testGetProperties() throws Exception { JobParameters parameters = new JobParametersBuilder().addDate("schedule.date", dateFormat.parse("01/23/2008")) .addString("job.key", "myKey").addString("vendor.id", "33243243").toJobParameters(); Properties props = factory.getProperties(parameters); assertNotNull(props); assertEquals("myKey", props.getProperty("job.key")); assertEquals("33243243", props.getProperty("vendor.id")); assertEquals("2008/01/23", props.getProperty("schedule.date")); }
public void testEmptyArgs() { JobParameters props = factory.getJobParameters(new Properties()); assertTrue(props.getParameters().isEmpty()); }
@AfterClass public static void cleanUp() { JobRegistryBackgroundJobRunner.stop(); }
@Override protected void setUp() throws Exception { super.setUp(); factory = new ScheduledJobParametersFactory(); }
@Test public void testInitialiseWithRepository() throws Exception { jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.afterPropertiesSet(); // no error }
@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 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()); }
public void testGetExitCodeWithCustomCode() { assertEquals(ecm.intValue("MY_CUSTOM_CODE"),3); }
public void testGetExitCodeWithPredefinedCodes() { assertEquals( ecm.intValue(ExitStatus.COMPLETED.getExitCode()), ExitCodeMapper.JVM_EXITCODE_COMPLETED); assertEquals( ecm.intValue(ExitStatus.FAILED.getExitCode()), ExitCodeMapper.JVM_EXITCODE_GENERIC_ERROR); assertEquals( ecm.intValue(ExitCodeMapper.JOB_NOT_PROVIDED), ExitCodeMapper.JVM_EXITCODE_JOB_ERROR); assertEquals( ecm.intValue(ExitCodeMapper.NO_SUCH_JOB), ExitCodeMapper.JVM_EXITCODE_JOB_ERROR); }
public void testGetExitCodeWithPredefinedCodesOverridden() { System.out.println(ecm2.intValue(ExitStatus.COMPLETED.getExitCode())); assertEquals( ecm2.intValue(ExitStatus.COMPLETED.getExitCode()), -1); assertEquals( ecm2.intValue(ExitStatus.FAILED.getExitCode()), -2); assertEquals( ecm2.intValue(ExitCodeMapper.JOB_NOT_PROVIDED), -3); assertEquals( ecm2.intValue(ExitCodeMapper.NO_SUCH_JOB), -3); }