RESOLVED - BATCH-628: SimpleJob doesn't verify that the JobRepository has been set

added the check to AbstractJob, as that's where jobRepository property is set
This commit is contained in:
robokaso
2008-05-16 09:12:37 +00:00
parent 1d386ee0d2
commit cc01a835c3
3 changed files with 40 additions and 24 deletions

View File

@@ -19,6 +19,8 @@ import java.util.Collections;
import junit.framework.TestCase;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionException;
import org.springframework.batch.core.step.StepSupport;
/**
@@ -27,13 +29,21 @@ import org.springframework.batch.core.step.StepSupport;
*/
public class AbstractJobTests extends TestCase {
JobSupport job = new JobSupport("job");
AbstractJob job = new AbstractJob("job") {
public void execute(JobExecution execution) throws JobExecutionException {
throw new UnsupportedOperationException();
}
};
/**
* Test method for {@link org.springframework.batch.core.job.AbstractJob#getName()}.
*/
public void testGetName() {
job = new JobSupport();
job = new AbstractJob(){
public void execute(JobExecution execution) throws JobExecutionException {
// No-op
}
};
assertNull(job.getName());
}
@@ -49,7 +59,11 @@ public class AbstractJobTests extends TestCase {
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setBeanName(java.lang.String)}.
*/
public void testSetBeanNameWithNullName() {
job = new JobSupport(null);
job = new AbstractJob(null) {
public void execute(JobExecution execution) throws JobExecutionException {
// NO-OP
}
};
assertEquals(null, job.getName());
job.setBeanName("foo");
assertEquals("foo", job.getName());
@@ -72,15 +86,6 @@ public class AbstractJobTests extends TestCase {
assertEquals(1, job.getSteps().size());
}
/**
* Test method for {@link org.springframework.batch.core.job.JobSupport#setStartLimit(int)}.
*/
public void testSetStartLimit() {
assertEquals(Integer.MAX_VALUE, job.getStartLimit());
job.setStartLimit(10);
assertEquals(10, job.getStartLimit());
}
/**
* Test method for {@link org.springframework.batch.core.job.AbstractJob#setRestartable(boolean)}.
*/
@@ -94,18 +99,20 @@ public class AbstractJobTests extends TestCase {
String value = job.toString();
assertTrue("Should contain name: " + value, value.indexOf("name=") >= 0);
}
public void testRunNotSupported() throws Exception {
public void testAfterPropertiesSet() throws Exception {
AbstractJob job = new AbstractJob() {
public void execute(JobExecution execution) throws JobExecutionException {
}
};
job.setJobRepository(null);
try {
job.execute(null);
} catch (UnsupportedOperationException e) {
// expected
String message = e.getMessage();
assertTrue("Message should contain JobSupport: " + message, contains(message, "JobSupport"));
job.afterPropertiesSet();
fail();
}
catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("JobRepository"));
}
}
private boolean contains(String str, String searchStr) {
return str.indexOf(searchStr) != -1;
}
}