OPEN - issue BATCH-773: Refactor and extend ExportedJobLauncher to JobOperator
More thorough tests and changed parameter values to long (not Long)
This commit is contained in:
@@ -42,6 +42,8 @@ import org.springframework.batch.core.job.JobSupport;
|
||||
import org.springframework.batch.core.launch.JobInstanceAlreadyExistsException;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.batch.core.launch.NoSuchJobExecutionException;
|
||||
import org.springframework.batch.core.launch.NoSuchJobInstanceException;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||
import org.springframework.batch.core.repository.JobRestartException;
|
||||
@@ -89,9 +91,10 @@ public class SimpleJobOperatorTests {
|
||||
}
|
||||
throw new NoSuchJobException("foo");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getJobNames() {
|
||||
return Arrays.asList(new String[] {"foo", "bar"});
|
||||
return Arrays.asList(new String[] { "foo", "bar" });
|
||||
}
|
||||
});
|
||||
|
||||
@@ -214,6 +217,21 @@ public class SimpleJobOperatorTests {
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSummaryNoSuchExecution() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getJobExecution(111L);
|
||||
EasyMock.expectLastCall().andReturn(null);
|
||||
EasyMock.replay(jobExplorer);
|
||||
try {
|
||||
jobOperator.getSummary(111L);
|
||||
fail("Expected NoSuchJobExecutionException");
|
||||
} catch (NoSuchJobExecutionException e) {
|
||||
// expected
|
||||
}
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionSummariesSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
@@ -229,6 +247,21 @@ public class SimpleJobOperatorTests {
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionSummariesNoSuchExecution() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getJobExecution(111L);
|
||||
EasyMock.expectLastCall().andReturn(null);
|
||||
EasyMock.replay(jobExplorer);
|
||||
try {
|
||||
jobOperator.getStepExecutionSummaries(111L);
|
||||
fail("Expected NoSuchJobExecutionException");
|
||||
} catch (NoSuchJobExecutionException e) {
|
||||
// expected
|
||||
}
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindRunningExecutionsSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
@@ -241,6 +274,21 @@ public class SimpleJobOperatorTests {
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindRunningExecutionsNoSuchJob() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.findRunningJobExecutions("no-such-job");
|
||||
EasyMock.expectLastCall().andReturn(Collections.emptySet());
|
||||
EasyMock.replay(jobExplorer);
|
||||
try {
|
||||
jobOperator.getRunningExecutions("no-such-job");
|
||||
fail("Expected NoSuchJobException");
|
||||
} catch (NoSuchJobException e) {
|
||||
// expected
|
||||
}
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobParametersSunnyDay() throws Exception {
|
||||
final JobParameters jobParameters = new JobParameters();
|
||||
@@ -253,23 +301,53 @@ public class SimpleJobOperatorTests {
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobParametersNoSuchExecution() throws Exception {
|
||||
jobExplorer.getJobExecution(111L);
|
||||
EasyMock.expectLastCall().andReturn(null);
|
||||
EasyMock.replay(jobExplorer);
|
||||
try {
|
||||
jobOperator.getParameters(111L);
|
||||
fail("Expected NoSuchJobExecutionException");
|
||||
} catch (NoSuchJobExecutionException e) {
|
||||
// expected
|
||||
}
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLastInstancesSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getLastJobInstances("foo",2);
|
||||
jobExplorer.getLastJobInstances("foo", 2);
|
||||
JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName());
|
||||
EasyMock.expectLastCall().andReturn(Collections.singletonList(jobInstance));
|
||||
EasyMock.replay(jobExplorer);
|
||||
List<Long> value = jobOperator.getLastInstances("foo",2);
|
||||
List<Long> value = jobOperator.getLastInstances("foo", 2);
|
||||
assertEquals(123L, value.get(0).longValue());
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetLastInstancesNoSuchJob() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getLastJobInstances("no-such-job", 2);
|
||||
EasyMock.expectLastCall().andReturn(Collections.emptyList());
|
||||
EasyMock.replay(jobExplorer);
|
||||
try {
|
||||
jobOperator.getLastInstances("no-such-job", 2);
|
||||
fail("Expected NoSuchJobException");
|
||||
}
|
||||
catch (NoSuchJobException e) {
|
||||
// expected
|
||||
}
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobNames() throws Exception {
|
||||
Set<String> names = jobOperator.getJobNames();
|
||||
assertEquals(2, names.size());
|
||||
assertTrue("Wrong names: "+names, names.contains("foo"));
|
||||
assertTrue("Wrong names: " + names, names.contains("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -286,4 +364,19 @@ public class SimpleJobOperatorTests {
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExecutionsNoSuchInstance() throws Exception {
|
||||
jobExplorer.getJobInstance(123L);
|
||||
EasyMock.expectLastCall().andReturn(null);
|
||||
EasyMock.replay(jobExplorer);
|
||||
try {
|
||||
jobOperator.getExecutions(123L);
|
||||
fail("Expected NoSuchJobInstanceException");
|
||||
}
|
||||
catch (NoSuchJobInstanceException e) {
|
||||
// expected
|
||||
}
|
||||
EasyMock.verify(jobExplorer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -52,10 +52,20 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
dao.saveJobExecution(execution);
|
||||
|
||||
List<JobExecution> executions = dao.findJobExecutions(jobInstance);
|
||||
assertTrue(executions.size() == 1);
|
||||
assertEquals(1, executions.size());
|
||||
assertEquals(execution, executions.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save and find a job execution.
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testFindNonExistentExecutions() {
|
||||
List<JobExecution> executions = dao.findJobExecutions(jobInstance);
|
||||
assertEquals(0, executions.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving sets id to the entity.
|
||||
*/
|
||||
@@ -107,6 +117,16 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
assertEquals(exec2, last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetMissingLastExecution() {
|
||||
JobExecution value = dao.getLastJobExecution(jobInstance);
|
||||
assertNull(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@@ -134,6 +154,16 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
assertEquals(1, value.getStepExecutions().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testNoRunningExecutions() {
|
||||
Set<JobExecution> values = dao.findRunningJobExecutions("no-such-job");
|
||||
assertEquals(0, values.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@@ -157,4 +187,13 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional
|
||||
assertEquals(1, value.getStepExecutions().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the execution is returned
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetMissingExecution() {
|
||||
JobExecution value = dao.getJobExecution(54321L);
|
||||
assertNull(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,17 @@ public abstract class AbstractJobInstanceDaoTests extends AbstractTransactionalJ
|
||||
assertEquals(new Date(DATE), retrievedParams.getDate("dateKey"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create and retrieve a job instance.
|
||||
*/
|
||||
@Transactional @Test
|
||||
public void testGetMissingById() throws Exception {
|
||||
|
||||
JobInstance retrievedInstance = dao.getJobInstance(1111111L);
|
||||
assertNull(retrievedInstance);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Create and retrieve a job instance.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user