IN PROGRESS - issue BATCH-340: Refactor JobRepository for greater clarity and consistency.
http://jira.springframework.org/browse/BATCH-340 JobInstance now has not-null Job as required constructor argument - repository no longer requires a separate Job setter
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.batch.core.domain;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -36,14 +38,11 @@ public class JobInstance extends Entity {
|
||||
private int jobExecutionCount;
|
||||
|
||||
private JobExecution lastExecution;
|
||||
|
||||
public JobInstance(Long id, JobParameters jobParameters) {
|
||||
super(id);
|
||||
this.jobParameters = jobParameters==null ? new JobParameters() : jobParameters;
|
||||
}
|
||||
|
||||
public JobInstance(Long id, JobParameters jobParameters, Job job){
|
||||
this(id, jobParameters);
|
||||
super(id);
|
||||
Assert.notNull(job);
|
||||
this.jobParameters = jobParameters==null ? new JobParameters() : jobParameters;
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
@@ -92,7 +91,4 @@ public class JobInstance extends Entity {
|
||||
return job;
|
||||
}
|
||||
|
||||
public void setJob(Job job) {
|
||||
this.job = job;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class JobExecutionTests extends TestCase {
|
||||
*/
|
||||
public void testGetJobId() {
|
||||
assertEquals(11, execution.getJobId().longValue());
|
||||
execution = new JobExecution(new JobInstance(new Long(23), new JobParameters()), null);
|
||||
execution = new JobExecution(new JobInstance(new Long(23), new JobParameters(), new JobSupport("testJob")), null);
|
||||
assertEquals(23, execution.getJobId().longValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,6 @@ public class JobInstanceTests extends TestCase {
|
||||
|
||||
public void testGetJob(){
|
||||
assertEquals("job", instance.getJob().getName());
|
||||
instance.setJob(null);
|
||||
assertEquals(null, instance.getJob());
|
||||
}
|
||||
|
||||
public void testCreateJobExecution(){
|
||||
@@ -62,8 +60,15 @@ public class JobInstanceTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testCreateWithNulls(){
|
||||
instance = new JobInstance(null, null);
|
||||
assertEquals(null, instance.getJobName());
|
||||
try {
|
||||
new JobInstance(null, null, null);
|
||||
fail("job instance can't exist without job specified");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
instance = new JobInstance(null, null, new JobSupport("testJob"));
|
||||
assertEquals("testJob", instance.getJobName());
|
||||
assertEquals(0, instance.getJobParameters().getParameters().size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public class StepExecutionTests extends TestCase {
|
||||
}
|
||||
|
||||
private StepExecution newStepExecution(String stepName, Long long2) {
|
||||
JobInstance job = new JobInstance(new Long(3), new JobParameters());
|
||||
JobInstance job = new JobInstance(new Long(3), new JobParameters(), new JobSupport("testJob"));
|
||||
StepExecution execution = new StepExecution(stepName, new JobExecution(job, long2), new Long(4));
|
||||
return execution;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user