@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 testDontUseParentParameters() throws Exception { DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor(); extractor.setUseAllParentParameters(false); JobExecution jobExecution = new JobExecution(0L, new JobParametersBuilder() .addString("parentParam", "val") .toJobParameters()); StepExecution stepExecution = new StepExecution("step", jobExecution); 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 testGetEmptyJobParameters() throws Exception { JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{}", jobParameters.toString()); }
@Test public void testStoppedChild() throws Exception { DefaultJobParametersExtractor jobParametersExtractor = new DefaultJobParametersExtractor(); jobParametersExtractor.setKeys(new String[] {"foo"}); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); step.setJobParametersExtractor(jobParametersExtractor); step.setJob(new JobSupport("child") { @Override public void execute(JobExecution execution) { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.STOPPED); execution.setEndTime(new Date()); jobRepository.update(execution); } @Override public boolean isRestartable() { return true; } }); step.afterPropertiesSet(); step.execute(stepExecution); JobExecution jobExecution = stepExecution.getJobExecution(); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); assertEquals(BatchStatus.STOPPED, stepExecution.getStatus()); }
@Override public JobParameters getJobParameters(Job job, StepExecution stepExecution) { JobParameters jobParameters = super.getJobParameters(job, stepExecution); JobExecution jobExecution = stepExecution.getJobExecution(); JobParametersIncrementer jobParametersIncrementer = job.getJobParametersIncrementer(); if (jobParametersIncrementer != null) { jobParameters = jobParametersIncrementer.getNext(jobParameters); } jobParameters = addJobParametersFromContext(jobParameters, stepExecution.getExecutionContext()); jobParameters = addJobParametersFromContext(jobParameters, jobExecution.getExecutionContext()); return jobParameters; }
@Test public void testExecuteRestart() throws Exception { DefaultJobParametersExtractor jobParametersExtractor = new DefaultJobParametersExtractor(); jobParametersExtractor.setKeys(new String[] {"foo"}); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar");
@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 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 stepExecution = getStepExecution("foo(long)=11"); extractor.setKeys(new String[] {"foo(int)", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=11}", 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 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 stepExecution = getStepExecution("foo=bar"); extractor.setKeys(new String[] {"foo", "bar"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{foo=bar}", 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 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 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 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 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 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")); }
@Test public void testUseParentParameters() throws Exception { JobExecution jobExecution = new JobExecution(0L, new JobParametersBuilder() .addString("parentParam", "val") .toJobParameters()); StepExecution stepExecution = new StepExecution("step", jobExecution); stepExecution.getExecutionContext().putDouble("foo", 11.1); extractor.setKeys(new String[] {"foo(double)"}); JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); String jobParams = jobParameters.toString(); assertTrue("Job parameters must contain parentParam=val", jobParams.contains("parentParam=val")); assertTrue("Job parameters must contain foo=11.1", jobParams.contains("foo=11.1")); }