/** * Public setter for the {@link JobRepository} that is needed to manage the * state of the batch meta domain (jobs, steps, executions) during the life * of a job. * * @param jobRepository repository to use during the job execution */ public void setJobRepository(JobRepository jobRepository) { this.jobRepository = jobRepository; stepHandler = new SimpleStepHandler(jobRepository); }
/** * Create a new validator with the required and optional job parameter keys * provided. * * @see DefaultJobParametersValidator#setOptionalKeys(String[]) * @see DefaultJobParametersValidator#setRequiredKeys(String[]) * * @param requiredKeys the required keys * @param optionalKeys the optional keys */ public DefaultJobParametersValidator(String[] requiredKeys, String[] optionalKeys) { super(); setRequiredKeys(requiredKeys); setOptionalKeys(optionalKeys); }
@Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.state(jobExplorer != null, "A JobExplorer must be provided"); }
@Test(expected = IllegalStateException.class) public void testOptionalValuesAlsoRequired() throws Exception { validator.setOptionalKeys(new String[] { "name", "value" }); validator.setRequiredKeys(new String[] { "foo", "value" }); validator.afterPropertiesSet(); }
/** * Test method for {@link SimpleStepHandler#afterPropertiesSet()}. */ @Test(expected = IllegalStateException.class) public void testAfterPropertiesSet() throws Exception { SimpleStepHandler stepHandler = new SimpleStepHandler(); stepHandler.afterPropertiesSet(); }
@Test public void testRunWithSimpleStepExecutor() throws Exception { job.setJobRepository(jobRepository); // do not set StepExecutorFactory... step1.setStartLimit(5); step2.setStartLimit(5); job.execute(jobExecution); assertEquals(2, list.size()); checkRepository(BatchStatus.COMPLETED, ExitStatus.COMPLETED); }
@Before public void setUp() throws Exception { job.setJobRepository(repository); job.setBeanName("simpleJob"); }
/** * Test method for * {@link org.springframework.batch.core.job.AbstractJob#setBeanName(java.lang.String)} * . */ @Test public void testSetBeanNameWithNullName() { job = new StubJob(null, null); assertEquals(null, job.getName()); job.setBeanName("foo"); assertEquals("foo", job.getName()); }
@Test public void testFailedWithError() throws Exception { step1.setStartLimit(5); step2.setStartLimit(5); final Error exception = new Error("Foo!"); step1.setProcessException(exception); job.execute(jobExecution); assertEquals(1, jobExecution.getAllFailureExceptions().size()); assertEquals(exception, jobExecution.getAllFailureExceptions().get(0)); assertEquals(0, list.size()); checkRepository(BatchStatus.FAILED, ExitStatus.FAILED); }
@Test public void testRunNormally() throws Exception { step1.setStartLimit(5); step2.setStartLimit(5); job.execute(jobExecution); assertEquals(2, list.size()); checkRepository(BatchStatus.COMPLETED); assertNotNull(jobExecution.getEndTime()); assertNotNull(jobExecution.getStartTime()); assertTrue(step1.passedInJobContext.isEmpty()); assertFalse(step2.passedInJobContext.isEmpty()); }
public JobParametersValidator getJobParametersValidator() { return new DefaultJobParametersValidator(); }
@Test(expected=IllegalArgumentException.class) public void testValidatorsCanNotBeNull() throws Exception{ compositeJobParametersValidator.setValidators(null); compositeJobParametersValidator.afterPropertiesSet(); }
/** * Test method for * {@link SimpleStepHandler#handleStep(org.springframework.batch.core.Step, org.springframework.batch.core.JobExecution)} * . */ @Test public void testHandleStep() throws Exception { StepExecution stepExecution = stepHandler.handleStep(new StubStep("step"), jobExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof JobSupport) { ((JobSupport) bean).setName("bar"); } return bean; }
private void checkRepository(BatchStatus status) { checkRepository(status, null); }
/** * @param name * @param jobRepository */ private StubJob(String name, JobRepository jobRepository) { super(name); try { setJobRepository(jobRepository); } catch (Exception e) { throw new IllegalStateException(e); } }
@Test(expected = JobParametersInvalidException.class) public void testValidateNull() throws Exception { validator.validate(null); }
@Before public void setUp(){ compositeJobParametersValidator = new CompositeJobParametersValidator(); }