/** * Test method for * {@link org.springframework.batch.core.step.job.JobStep#afterPropertiesSet()} * . */ @Test(expected = IllegalStateException.class) public void testAfterPropertiesSetWithNoLauncher() throws Exception { step.setJob(new JobSupport("child")); step.setJobLauncher(null); step.afterPropertiesSet(); }
@Test public void testGetNamedIntJobParameters() throws Exception { StepExecution stepExecution = getStepExecution("foo(long)=11"); extractor.setKeys(new String[] {"foo(int)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
/** * Test method for * {@link org.springframework.batch.core.step.job.JobStep#afterPropertiesSet()} * . */ @Test(expected = IllegalStateException.class) public void testAfterPropertiesSet() throws Exception { step.afterPropertiesSet(); }
@Test public void testExecuteFailure() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.FAILED); execution.setEndTime(new Date()); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); }
@Before public void setUp() throws Exception { step.setName("step"); MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean(); jobRepository = factory.getObject(); step.setJobRepository(jobRepository); JobExecution jobExecution = jobRepository.createJobExecution("job", new JobParameters()); stepExecution = jobExecution.createStepExecution("step"); jobRepository.add(stepExecution); SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); jobLauncher.setJobRepository(jobRepository); jobLauncher.afterPropertiesSet(); step.setJobLauncher(jobLauncher); }
@Test public void testGetNamedDateJobParameters() throws Exception { Date date = new Date(); stepExecution.getExecutionContext().put("foo",date); extractor.setKeys(new String[] {"foo(date)"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo="+date.getTime()+"}", jobParameters.toString()); }
@Test public void testGetEmptyJobParameters() throws Exception { JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{}", jobParameters.toString()); }
@Test public void testStepExecutionExitStatus() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { execution.setStatus(BatchStatus.COMPLETED); execution.setExitStatus(new ExitStatus("CUSTOM")); execution.setEndTime(new Date()); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals("CUSTOM", stepExecution.getExitStatus().getExitCode()); } }
@Test public void testGetNamedJobParameters() throws Exception { StepExecution stepExecution = getStepExecution("foo=bar"); extractor.setKeys(new String[] {"foo", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=bar}", jobParameters.toString()); }
@Test public void testGetNamedLongStringParameters() throws Exception { stepExecution.getExecutionContext().putString("foo","bar"); extractor.setKeys(new String[] {"foo(string)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=bar}", jobParameters.toString()); }
@Test public void testExecuteException() throws Exception { step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { throw new RuntimeException("FOO"); } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals(BatchStatus.FAILED, stepExecution.getStatus()); assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage()); }
@Test public void testGetNamedLongStringParameters() throws Exception { StepExecution stepExecution = getStepExecution("foo=bar"); extractor.setKeys(new String[] {"foo(string)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=bar}", jobParameters.toString()); }
@Test public void testGetNamedIntJobParameters() throws Exception { stepExecution.getExecutionContext().putInt("foo",11); extractor.setKeys(new String[] {"foo(int)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
@Test public void testGetNamedDoubleJobParameters() throws Exception { StepExecution stepExecution = getStepExecution("foo(double)=11.1"); extractor.setKeys(new String[] {"foo(double)"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11.1}", jobParameters.toString()); }
@Test public void testGetNamedJobParameters() throws Exception { stepExecution.getExecutionContext().put("foo", "bar"); extractor.setKeys(new String[] {"foo", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=bar}", jobParameters.toString()); }
@Test public void testGetNamedLongJobParameters() throws Exception { StepExecution stepExecution = getStepExecution("foo(long)=11"); extractor.setKeys(new String[] {"foo(long)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
@Test public void testGetNamedDoubleJobParameters() throws Exception { stepExecution.getExecutionContext().putDouble("foo",11.1); extractor.setKeys(new String[] {"foo(double)"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11.1}", jobParameters.toString()); }
@Test public void testGetNamedDateJobParameters() throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Date date = dateFormat.parse(dateFormat.format(new Date())); StepExecution stepExecution = getStepExecution("foo(date)="+dateFormat.format(date)); extractor.setKeys(new String[] {"foo(date)"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo="+date.getTime()+"}", jobParameters.toString()); }
@Test public void testGetNamedLongJobParameters() throws Exception { stepExecution.getExecutionContext().putLong("foo",11L); extractor.setKeys(new String[] {"foo(long)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", jobParameters.toString()); }
@Test public void testGetAllJobParameters() throws Exception { StepExecution stepExecution = getStepExecution("foo=bar,spam=bucket"); extractor.setKeys(new String[] {"foo", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("bar", jobParameters.getString("foo")); assertEquals("bucket", jobParameters.getString("spam")); }