@Test public void testGetEmptyJobParameters() throws Exception { JobParameters jobParameters = extractor.getJobParameters(null, stepExecution); assertEquals("{}", 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 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 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 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 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 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 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 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 testStartStopResumeJob() throws Exception { String params = new JobParametersBuilder().addLong("jobOperatorTestParam", 7L).toJobParameters().toString(); long executionId = operator.start(job.getName(), params); assertEquals(params, operator.getParameters(executionId)); stopAndCheckStatus(executionId); long resumedExecutionId = operator.restart(executionId); assertEquals(params, operator.getParameters(resumedExecutionId)); stopAndCheckStatus(resumedExecutionId); List<Long> instances = operator.getJobInstances(job.getName(), 0, 1); assertEquals(1, instances.size()); long instanceId = instances.get(0); List<Long> executions = operator.getExecutions(instanceId); assertEquals(2, executions.size()); // latest execution is the first in the returned list assertEquals(resumedExecutionId, executions.get(0).longValue()); assertEquals(executionId, executions.get(1).longValue()); }
@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")); }
@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()); } }