Merge pull request 143 from dturanski/BATCH-1908-JUnit
This commit is contained in:
@@ -2,10 +2,14 @@ package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
@@ -82,6 +86,49 @@ public abstract class AbstractExecutionContextDaoTests extends AbstractTransacti
|
||||
assertEquals(ctx, retrieved);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveAndFindExecutionContexts() {
|
||||
|
||||
List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
JobInstance ji = jobInstanceDao.createJobInstance("testJob" + i, new JobParameters());
|
||||
JobExecution je = new JobExecution(ji, new JobParameters());
|
||||
jobExecutionDao.saveJobExecution(je);
|
||||
StepExecution se = new StepExecution("step" + i, je);
|
||||
se.setStatus(BatchStatus.STARTED);
|
||||
se.setReadSkipCount(i);
|
||||
se.setProcessSkipCount(i);
|
||||
se.setWriteSkipCount(i);
|
||||
se.setProcessSkipCount(i);
|
||||
se.setRollbackCount(i);
|
||||
se.setLastUpdated(new Date(System.currentTimeMillis()));
|
||||
se.setReadCount(i);
|
||||
se.setFilterCount(i);
|
||||
se.setWriteCount(i);
|
||||
stepExecutions.add(se);
|
||||
}
|
||||
stepExecutionDao.saveStepExecutions(stepExecutions);
|
||||
contextDao.saveExecutionContexts(stepExecutions);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
ExecutionContext retrieved = contextDao.getExecutionContext(stepExecutions.get(i).getJobExecution());
|
||||
assertEquals(stepExecutions.get(i).getExecutionContext(), retrieved);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSaveNullExecutionContexts() {
|
||||
contextDao.saveExecutionContexts(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveEmptyExecutionContexts() {
|
||||
contextDao.saveExecutionContexts(new ArrayList<StepExecution>());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveAndFindEmptyJobContext() {
|
||||
|
||||
@@ -21,8 +21,10 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -115,6 +117,53 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveAndGetExecutions() {
|
||||
|
||||
List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
StepExecution se = new StepExecution("step" + i, jobExecution);
|
||||
se.setStatus(BatchStatus.STARTED);
|
||||
se.setReadSkipCount(i);
|
||||
se.setProcessSkipCount(i);
|
||||
se.setWriteSkipCount(i);
|
||||
se.setProcessSkipCount(i);
|
||||
se.setRollbackCount(i);
|
||||
se.setLastUpdated(new Date(System.currentTimeMillis()));
|
||||
se.setReadCount(i);
|
||||
se.setFilterCount(i);
|
||||
se.setWriteCount(i);
|
||||
stepExecutions.add(se);
|
||||
}
|
||||
|
||||
dao.saveStepExecutions(stepExecutions);
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecutions.get(i).getId());
|
||||
|
||||
assertStepExecutionsAreEqual(stepExecutions.get(i), retrieved);
|
||||
assertNotNull(retrieved.getVersion());
|
||||
assertNotNull(retrieved.getJobExecution());
|
||||
assertNotNull(retrieved.getJobExecution().getId());
|
||||
assertNotNull(retrieved.getJobExecution().getJobId());
|
||||
assertNotNull(retrieved.getJobExecution().getJobInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSaveNullCollectionThrowsException() {
|
||||
dao.saveStepExecutions(null);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveEmptyCollection() {
|
||||
dao.saveStepExecutions(new ArrayList<StepExecution>());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testSaveAndGetNonExistentExecution() {
|
||||
|
||||
@@ -16,15 +16,17 @@
|
||||
|
||||
package org.springframework.batch.core.repository.support;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -172,6 +174,24 @@ public class SimpleJobRepositoryTests {
|
||||
assertTrue(lastUpdated > (before - 1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveStepExecutions() {
|
||||
List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
StepExecution stepExecution = new StepExecution("stepName" + i, jobExecution);
|
||||
stepExecutions.add(stepExecution);
|
||||
}
|
||||
|
||||
jobRepository.addAll(stepExecutions);
|
||||
verify(stepExecutionDao).saveStepExecutions(stepExecutions);
|
||||
verify(ecDao).saveExecutionContexts(stepExecutions);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSaveNullStepExecutions() {
|
||||
jobRepository.addAll(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateStepExecutionSetsLastUpdated(){
|
||||
|
||||
|
||||
Reference in New Issue
Block a user