BATCH-1668: added check for transaction in JobRepository

This commit is contained in:
Dave Syer
2011-01-05 15:51:51 +00:00
parent a8e16c6421
commit ff15bd0648
4 changed files with 62 additions and 40 deletions

View File

@@ -13,6 +13,7 @@ import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.job.JobSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@@ -35,8 +36,18 @@ public class SimpleJobRepositoryProxyTests {
private JobSupport job = new JobSupport("SimpleJobRepositoryProxyTestsJob");
@Transactional
@Test(expected=IllegalStateException.class)
@DirtiesContext
public void testCreateAndFindWithExistingTransaction() throws Exception {
assertFalse(advice.invoked);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
assertNotNull(jobExecution);
assertTrue(advice.invoked);
}
@Test
public void testCreateAndFind() throws Exception {
@DirtiesContext
public void testCreateAndFindNoTransaction() throws Exception {
assertFalse(advice.invoked);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
assertNotNull(jobExecution);