BATCH-2004: Added basic wrappers for the the majority of batch artifacts.
This commit is contained in:
@@ -30,7 +30,7 @@ import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class BatchStatusTests {
|
||||
|
||||
@@ -118,4 +118,15 @@ public class BatchStatusTests {
|
||||
BatchStatus status = (BatchStatus) in.readObject();
|
||||
assertEquals(BatchStatus.COMPLETED, status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsrConversion() {
|
||||
assertEquals(javax.batch.runtime.BatchStatus.ABANDONED, BatchStatus.ABANDONED.getBatchStatus());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.COMPLETED, BatchStatus.COMPLETED.getBatchStatus());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.STARTED, BatchStatus.STARTED.getBatchStatus());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.STARTING, BatchStatus.STARTING.getBatchStatus());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.STOPPED, BatchStatus.STOPPED.getBatchStatus());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.STOPPING, BatchStatus.STOPPING.getBatchStatus());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.FAILED, BatchStatus.FAILED.getBatchStatus());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.support.SerializationUtils;
|
||||
|
||||
/**
|
||||
* @author dsyer
|
||||
*
|
||||
*/
|
||||
public class JobInstanceTests extends TestCase {
|
||||
public class JobInstanceTests {
|
||||
|
||||
private JobInstance instance = new JobInstance(new Long(11), "job");
|
||||
|
||||
@@ -31,15 +33,18 @@ public class JobInstanceTests extends TestCase {
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.JobInstance#getJobName()}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetName() {
|
||||
instance = new JobInstance(new Long(1), "foo");
|
||||
assertEquals("foo", instance.getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJob() {
|
||||
assertEquals("job", instance.getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateWithNulls() {
|
||||
try {
|
||||
new JobInstance(null, null);
|
||||
@@ -52,6 +57,7 @@ public class JobInstanceTests extends TestCase {
|
||||
assertEquals("testJob", instance.getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
instance = new JobInstance(new Long(1), "jobName");
|
||||
|
||||
@@ -59,4 +65,9 @@ public class JobInstanceTests extends TestCase {
|
||||
|
||||
assertEquals(instance, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInstanceId() {
|
||||
assertEquals(11, instance.getInstanceId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -20,6 +21,30 @@ public class JobParametersBuilderTests {
|
||||
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
|
||||
@Test
|
||||
public void testFromProperties() {
|
||||
Properties props = new Properties();
|
||||
props.put("SCHEDULE_DATE", date.toString());
|
||||
props.put("LONG", "1");
|
||||
props.put("STRING", "string value");
|
||||
|
||||
JobParametersBuilder builder = new JobParametersBuilder(props);
|
||||
JobParameters parameters = builder.toJobParameters();
|
||||
assertEquals(date.toString(), parameters.getString("SCHEDULE_DATE"));
|
||||
assertEquals("1", parameters.getString("LONG").toString());
|
||||
assertEquals("string value", parameters.getString("STRING"));
|
||||
assertFalse(parameters.getParameters().get("SCHEDULE_DATE").isIdentifying());
|
||||
assertFalse(parameters.getParameters().get("LONG").isIdentifying());
|
||||
assertFalse(parameters.getParameters().get("STRING").isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromNullProperties() {
|
||||
JobParametersBuilder builder = new JobParametersBuilder((Properties) null);
|
||||
JobParameters parameters = builder.toJobParameters();
|
||||
assertEquals(0, parameters.getParameters().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIdentifyingParameters() {
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", date, false);
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -212,4 +213,18 @@ public class JobParametersTests {
|
||||
public void testDateReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getDate("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToProperties() {
|
||||
Properties results = parameters.toProperties();
|
||||
|
||||
assertEquals(results.get("string.key1"), "value1");
|
||||
assertEquals(results.get("string.key2"), "value2");
|
||||
assertEquals(results.get("long.key1"), "1");
|
||||
assertEquals(results.get("long.key2"), "2");
|
||||
assertEquals(results.get("double.key1"), "1.1");
|
||||
assertEquals(results.get("double.key2"), "2.2");
|
||||
assertEquals(results.get("date.key1"), String.valueOf(date1.getTime()));
|
||||
assertEquals(results.get("date.key2"), String.valueOf(date2.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.job.AbstractJob;
|
||||
import org.springframework.batch.core.listener.CompositeStepExecutionListener;
|
||||
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
|
||||
@@ -446,7 +446,7 @@ public class StepParserTests {
|
||||
Map<Class<? extends Throwable>, Boolean> retryableFound = getExceptionMap(fb, "retryableExceptionClasses");
|
||||
ItemStream[] streamsFound = (ItemStream[]) ReflectionTestUtils.getField(fb, "streams");
|
||||
RetryListener[] retryListenersFound = (RetryListener[]) ReflectionTestUtils.getField(fb, "retryListeners");
|
||||
StepListener[] stepListenersFound = (StepListener[]) ReflectionTestUtils.getField(fb, "listeners");
|
||||
Set<StepExecutionListener> stepListenersFound = (Set<StepExecutionListener>) ReflectionTestUtils.getField(fb, "stepExecutionListeners");
|
||||
Collection<Class<? extends Throwable>> noRollbackFound = getExceptionList(fb, "noRollbackExceptionClasses");
|
||||
|
||||
assertSameMaps(skippable, skippableFound);
|
||||
@@ -480,7 +480,7 @@ public class StepParserTests {
|
||||
Map<Class<? extends Throwable>, Boolean> retryableFound = getExceptionMap(fb, "retryableExceptionClasses");
|
||||
ItemStream[] streamsFound = (ItemStream[]) ReflectionTestUtils.getField(fb, "streams");
|
||||
RetryListener[] retryListenersFound = (RetryListener[]) ReflectionTestUtils.getField(fb, "retryListeners");
|
||||
StepListener[] stepListenersFound = (StepListener[]) ReflectionTestUtils.getField(fb, "listeners");
|
||||
Set<StepExecutionListener> stepListenersFound = (Set<StepExecutionListener>) ReflectionTestUtils.getField(fb, "stepExecutionListeners");
|
||||
Collection<Class<? extends Throwable>> noRollbackFound = getExceptionList(fb, "noRollbackExceptionClasses");
|
||||
|
||||
assertSameMaps(skippable, skippableFound);
|
||||
@@ -491,6 +491,7 @@ public class StepParserTests {
|
||||
assertSameCollections(noRollback, noRollbackFound);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testStepWithListsOverrideWithEmpty() throws Exception {
|
||||
ApplicationContext ctx = stepParserParentAttributeTestsCtx;
|
||||
@@ -502,7 +503,7 @@ public class StepParserTests {
|
||||
assertEquals(1, getExceptionMap(fb, "retryableExceptionClasses").size());
|
||||
assertEquals(0, ((ItemStream[]) ReflectionTestUtils.getField(fb, "streams")).length);
|
||||
assertEquals(0, ((RetryListener[]) ReflectionTestUtils.getField(fb, "retryListeners")).length);
|
||||
assertEquals(0, ((StepListener[]) ReflectionTestUtils.getField(fb, "listeners")).length);
|
||||
assertEquals(0, ((Set<StepExecutionListener>) ReflectionTestUtils.getField(fb, "stepExecutionListeners")).size());
|
||||
assertEquals(0, getExceptionList(fb, "noRollbackExceptionClasses").size());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,15 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,36 +44,37 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class StepWithBasicProcessTaskJobParserTests {
|
||||
|
||||
|
||||
@Autowired
|
||||
private Job job;
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TestReader reader;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("listener")
|
||||
private TestListener listener;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TestProcessor processor;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TestWriter writer;
|
||||
|
||||
|
||||
@Autowired
|
||||
private StepParserStepFactoryBean<?,?> factory;
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testStepWithTask() throws Exception {
|
||||
assertNotNull(job);
|
||||
Object ci = ReflectionTestUtils.getField(factory, "commitInterval");
|
||||
assertEquals("wrong chunk-size:", 10, ci);
|
||||
Object listeners = ReflectionTestUtils.getField(factory, "listeners");
|
||||
assertEquals("wrong number of listeners:", 2, ((StepListener[])listeners).length);
|
||||
Object listeners = ReflectionTestUtils.getField(factory, "stepExecutionListeners");
|
||||
assertEquals("wrong number of listeners:", 2, ((Set<StepExecutionListener>)listeners).size());
|
||||
Object streams = ReflectionTestUtils.getField(factory, "streams");
|
||||
assertEquals("wrong number of streams:", 1, ((ItemStream[])streams).length);
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
|
||||
@@ -19,13 +19,15 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -40,7 +42,7 @@ import org.springframework.transaction.annotation.Propagation;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
*
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -71,6 +73,7 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
|
||||
@Autowired
|
||||
private StepParserStepFactoryBean<?, ?> factory;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testStepWithTask() throws Exception {
|
||||
assertNotNull(job);
|
||||
@@ -91,8 +94,8 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
|
||||
assertEquals("wrong reader-transactional-queue:", true, txq);
|
||||
Object te = ReflectionTestUtils.getField(factory, "taskExecutor");
|
||||
assertEquals("wrong task-executor:", ConcurrentTaskExecutor.class, te.getClass());
|
||||
Object listeners = ReflectionTestUtils.getField(factory, "listeners");
|
||||
assertEquals("wrong number of listeners:", 2, ((StepListener[]) listeners).length);
|
||||
Object listeners = ReflectionTestUtils.getField(factory, "stepExecutionListeners");
|
||||
assertEquals("wrong number of listeners:", 2, ((Set<StepExecutionListener>) listeners).size());
|
||||
Object retryListeners = ReflectionTestUtils.getField(factory, "retryListeners");
|
||||
assertEquals("wrong number of retry-listeners:", 2, ((RetryListener[]) retryListeners).length);
|
||||
Object streams = ReflectionTestUtils.getField(factory, "streams");
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.batch.api.chunk.listener.ChunkListener;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
|
||||
public class ChunkListenerAdapterTests {
|
||||
|
||||
private ChunkListenerAdapter adapter;
|
||||
@Mock
|
||||
private ChunkListener delegate;
|
||||
@Mock
|
||||
private ChunkContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
adapter = new ChunkListenerAdapter(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullDelegate() {
|
||||
adapter = new ChunkListenerAdapter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeChunk() throws Exception {
|
||||
adapter.beforeChunk(null);
|
||||
|
||||
verify(delegate).beforeChunk();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testBeforeChunkException() throws Exception {
|
||||
doThrow(new Exception("This is expected")).when(delegate).beforeChunk();
|
||||
adapter.beforeChunk(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterChunk() throws Exception {
|
||||
adapter.afterChunk(null);
|
||||
|
||||
verify(delegate).afterChunk();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterChunkException() throws Exception {
|
||||
doThrow(new Exception("This is expected")).when(delegate).afterChunk();
|
||||
adapter.afterChunk(null);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterChunkErrorNullContext() throws Exception {
|
||||
adapter.afterChunkError(null);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterChunkErrorException() throws Exception {
|
||||
doThrow(new Exception("This is expected")).when(delegate).afterChunk();
|
||||
adapter.afterChunk(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterChunkError() throws Exception {
|
||||
Exception exception = new Exception("This was expected");
|
||||
|
||||
when(context.getAttribute(org.springframework.batch.core.ChunkListener.ROLLBACK_EXCEPTION_KEY)).thenReturn(exception);
|
||||
|
||||
adapter.afterChunkError(context);
|
||||
|
||||
verify(delegate).onError(exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import javax.batch.api.chunk.listener.ItemProcessListener;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class ItemProcessListenerAdapterTests {
|
||||
|
||||
private ItemProcessListenerAdapter<String, String> adapter;
|
||||
@Mock
|
||||
private ItemProcessListener delegate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
adapter = new ItemProcessListenerAdapter<String, String>(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullCreation() {
|
||||
adapter = new ItemProcessListenerAdapter<String, String>(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeProcess() throws Exception {
|
||||
String item = "This is my item";
|
||||
|
||||
adapter.beforeProcess(item);
|
||||
|
||||
verify(delegate).beforeProcess(item);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testBeforeProcessException() throws Exception {
|
||||
Exception exception = new Exception("This should occur");
|
||||
String item = "This is the bad item";
|
||||
|
||||
doThrow(exception).when(delegate).beforeProcess(item);
|
||||
|
||||
adapter.beforeProcess(item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterProcess() throws Exception {
|
||||
String item = "This is the input";
|
||||
String result = "This is the output";
|
||||
|
||||
adapter.afterProcess(item, result);
|
||||
|
||||
verify(delegate).afterProcess(item, result);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterProcessException() throws Exception {
|
||||
String item = "This is the input";
|
||||
String result = "This is the output";
|
||||
Exception exception = new Exception("This is expected");
|
||||
|
||||
doThrow(exception).when(delegate).afterProcess(item, result);
|
||||
|
||||
adapter.afterProcess(item, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnProcessError() throws Exception {
|
||||
String item = "This is the input";
|
||||
Exception cause = new Exception("This was the cause");
|
||||
|
||||
adapter.onProcessError(item, cause);
|
||||
|
||||
verify(delegate).onProcessError(item, cause);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testOnProcessErrorException() throws Exception {
|
||||
String item = "This is the input";
|
||||
Exception cause = new Exception("This was the cause");
|
||||
Exception exception = new Exception("This is expected");
|
||||
|
||||
doThrow(exception).when(delegate).onProcessError(item, cause);
|
||||
|
||||
adapter.onProcessError(item, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import javax.batch.api.chunk.listener.ItemReadListener;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class ItemReadListenerAdapterTests {
|
||||
|
||||
private ItemReadListenerAdapter<String> adapter;
|
||||
@Mock
|
||||
private ItemReadListener delegate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
adapter = new ItemReadListenerAdapter<String>(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullDelegate() {
|
||||
adapter = new ItemReadListenerAdapter<String>(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeRead() throws Exception {
|
||||
adapter.beforeRead();
|
||||
|
||||
verify(delegate).beforeRead();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testBeforeReadException() throws Exception {
|
||||
doThrow(new Exception("Should occur")).when(delegate).beforeRead();
|
||||
|
||||
adapter.beforeRead();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterRead() throws Exception {
|
||||
String item = "item";
|
||||
|
||||
adapter.afterRead(item);
|
||||
|
||||
verify(delegate).afterRead(item);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterReadException() throws Exception {
|
||||
String item = "item";
|
||||
Exception expected = new Exception("expected");
|
||||
|
||||
doThrow(expected).when(delegate).afterRead(item);
|
||||
|
||||
adapter.afterRead(item);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnReadError() throws Exception {
|
||||
Exception cause = new Exception ("cause");
|
||||
|
||||
adapter.onReadError(cause);
|
||||
|
||||
verify(delegate).onReadError(cause);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testOnReadErrorException() throws Exception {
|
||||
Exception cause = new Exception ("cause");
|
||||
Exception result = new Exception("result");
|
||||
|
||||
doThrow(result).when(delegate).onReadError(cause);
|
||||
|
||||
adapter.onReadError(cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.batch.api.chunk.listener.ItemWriteListener;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class ItemWriteListenerAdapterTests {
|
||||
|
||||
private ItemWriteListenerAdapter<String> adapter;
|
||||
@Mock
|
||||
private ItemWriteListener delegate;
|
||||
private List items = new ArrayList();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
adapter = new ItemWriteListenerAdapter<String>(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
adapter = new ItemWriteListenerAdapter<String>(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeWrite() throws Exception {
|
||||
adapter.beforeWrite(items);
|
||||
|
||||
verify(delegate).beforeWrite(items);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testBeforeTestWriteException() throws Exception {
|
||||
doThrow(new Exception("expected")).when(delegate).beforeWrite(items);
|
||||
|
||||
adapter.beforeWrite(items);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterWrite() throws Exception {
|
||||
adapter.afterWrite(items);
|
||||
|
||||
verify(delegate).afterWrite(items);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterTestWriteException() throws Exception {
|
||||
doThrow(new Exception("expected")).when(delegate).afterWrite(items);
|
||||
|
||||
adapter.afterWrite(items);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnWriteError() throws Exception {
|
||||
Exception cause = new Exception("cause");
|
||||
|
||||
adapter.onWriteError(cause, items);
|
||||
|
||||
verify(delegate).onWriteError(items, cause);
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testOnWriteErrorException() throws Exception {
|
||||
Exception cause = new Exception("cause");
|
||||
|
||||
doThrow(new Exception("expected")).when(delegate).onWriteError(items, cause);
|
||||
|
||||
adapter.onWriteError(cause, items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
|
||||
public class JobContextTests {
|
||||
|
||||
private JobContext context;
|
||||
@Mock
|
||||
private JobExecution execution;
|
||||
@Mock
|
||||
private JobInstance instance;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
context = new JobContext(execution);
|
||||
when(execution.getJobInstance()).thenReturn(instance);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
context = new JobContext(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobName() {
|
||||
when(instance.getJobName()).thenReturn("jobName");
|
||||
|
||||
assertEquals("jobName", context.getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransientUserData() {
|
||||
context.setTransientUserData("This is my data");
|
||||
assertEquals("This is my data", context.getTransientUserData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInstanceId() {
|
||||
when(instance.getId()).thenReturn(5L);
|
||||
|
||||
assertEquals(5L, context.getInstanceId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExecutionId() {
|
||||
when(execution.getId()).thenReturn(5L);
|
||||
|
||||
assertEquals(5L, context.getExecutionId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProperties() {
|
||||
JobParameters params = new JobParametersBuilder()
|
||||
.addString("key1", "value1")
|
||||
.toJobParameters();
|
||||
|
||||
when(execution.getJobParameters()).thenReturn(params);
|
||||
|
||||
Properties props = context.getProperties();
|
||||
|
||||
assertEquals("value1", props.get("key1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBatchStatus() {
|
||||
when(execution.getStatus()).thenReturn(BatchStatus.COMPLETED);
|
||||
|
||||
assertEquals(javax.batch.runtime.BatchStatus.COMPLETED, context.getBatchStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExitStatus() {
|
||||
when(execution.getExitStatus()).thenReturn(new ExitStatus("exit"));
|
||||
|
||||
assertEquals("exit", context.getExitStatus());
|
||||
|
||||
context.setExitStatus("my exit status");
|
||||
|
||||
verify(execution).setExitStatus(new ExitStatus("my exit status"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
|
||||
public class JobExecutionTests {
|
||||
|
||||
private JobExecution adapter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
JobInstance instance = new JobInstance(2L, "job name");
|
||||
|
||||
JobParameters params = new JobParametersBuilder().addString("key1", "value1").toJobParameters();
|
||||
|
||||
org.springframework.batch.core.JobExecution execution = new org.springframework.batch.core.JobExecution(instance, params);
|
||||
|
||||
execution.setId(5L);
|
||||
execution.setCreateTime(new Date(0));
|
||||
execution.setEndTime(new Date(999999999l));
|
||||
execution.setExitStatus(new ExitStatus("exit status"));
|
||||
execution.setLastUpdated(new Date(12345));
|
||||
execution.setStartTime(new Date(98765));
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
execution.setVersion(21);
|
||||
|
||||
adapter = new JobExecution(execution);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
adapter = new JobExecution(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBasicValues() {
|
||||
assertEquals(javax.batch.runtime.BatchStatus.FAILED, adapter.getBatchStatus());
|
||||
assertEquals(new Date(0), adapter.getCreateTime());
|
||||
assertEquals(new Date(999999999l), adapter.getEndTime());
|
||||
assertEquals(5L, adapter.getExecutionId());
|
||||
assertEquals("exit status", adapter.getExitStatus());
|
||||
assertEquals("job name", adapter.getJobName());
|
||||
assertEquals(new Date(12345), adapter.getLastUpdatedTime());
|
||||
assertEquals(new Date(98765), adapter.getStartTime());
|
||||
|
||||
Properties props = adapter.getJobParameters();
|
||||
|
||||
assertEquals("value1", props.get("key1"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import javax.batch.api.listener.JobListener;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
public class JobListenerAdapterTests {
|
||||
|
||||
private JobListenerAdapter adapter;
|
||||
@Mock
|
||||
private JobListener delegate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
adapter = new JobListenerAdapter(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
adapter = new JobListenerAdapter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeJob() throws Exception {
|
||||
adapter.beforeJob(null);
|
||||
|
||||
verify(delegate).beforeJob();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testBeforeJobException() throws Exception {
|
||||
doThrow(new Exception("expected")).when(delegate).beforeJob();
|
||||
|
||||
adapter.beforeJob(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterJob() throws Exception {
|
||||
adapter.afterJob(null);
|
||||
|
||||
verify(delegate).afterJob();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterJobException() throws Exception {
|
||||
doThrow(new Exception("expected")).when(delegate).afterJob();
|
||||
|
||||
adapter.afterJob(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.batch.api.listener.StepListener;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
public class StepListenerAdapterTests {
|
||||
|
||||
private StepListenerAdapter adapter;
|
||||
@Mock
|
||||
private StepListener delegate;
|
||||
@Mock
|
||||
private StepExecution execution;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
adapter = new StepListenerAdapter(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
adapter = new StepListenerAdapter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeforeStep() throws Exception {
|
||||
adapter.beforeStep(null);
|
||||
|
||||
verify(delegate).beforeStep();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testBeforeStepException() throws Exception {
|
||||
doThrow(new Exception("expected")).when(delegate).beforeStep();
|
||||
|
||||
adapter.beforeStep(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterStep() throws Exception {
|
||||
ExitStatus exitStatus = new ExitStatus("complete");
|
||||
when(execution.getExitStatus()).thenReturn(exitStatus);
|
||||
|
||||
assertEquals(exitStatus, adapter.afterStep(execution));
|
||||
|
||||
verify(delegate).afterStep();
|
||||
}
|
||||
|
||||
@Test(expected=BatchRuntimeException.class)
|
||||
public void testAfterStepException() throws Exception {
|
||||
doThrow(new Exception("expected")).when(delegate).afterStep();
|
||||
|
||||
adapter.afterStep(null);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,76 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.configuration.annotation.DefaultBatchConfigurer;
|
||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||
import org.springframework.batch.core.configuration.xml.DummyItemProcessor;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.support.PassThroughItemProcessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
|
||||
@ContextConfiguration(value="batch.xml")
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class BatchParserTests {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("itemProcessor")
|
||||
@SuppressWarnings("rawtypes")
|
||||
private ItemProcessor itemProcessor;
|
||||
private ApplicationContext baseContext;
|
||||
|
||||
@Test
|
||||
public void testRoseyScenario() {
|
||||
assertNotNull(itemProcessor);
|
||||
assertTrue(itemProcessor instanceof PassThroughItemProcessor);
|
||||
@Before
|
||||
public void setUp() {
|
||||
baseContext = new AnnotationConfigApplicationContext(BaseConfiguration.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRoseyScenario() {
|
||||
GenericXmlApplicationContext batchContext = new GenericXmlApplicationContext();
|
||||
batchContext.setValidating(false);
|
||||
batchContext.load(new String[] {"classpath:/org/springframework/batch/core/jsr/configuration/xml/batch.xml"});
|
||||
System.out.println("baseContext = " + baseContext);
|
||||
batchContext.setParent(baseContext);
|
||||
GenericBeanDefinition bd = new GenericBeanDefinition();
|
||||
bd.setBeanClass(AutowiredAnnotationBeanPostProcessor.class);
|
||||
batchContext.registerBeanDefinition("postProcessor", bd);
|
||||
batchContext.refresh();
|
||||
|
||||
Object itemProcessor = batchContext.getBean(ItemProcessor.class);
|
||||
|
||||
assertNotNull(itemProcessor);
|
||||
assertTrue(itemProcessor instanceof PassThroughItemProcessor);
|
||||
|
||||
batchContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@SuppressWarnings({"resource", "rawtypes"})
|
||||
public void testOverrideBeansFirst() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/jsr/configuration/xml/override_batch.xml",
|
||||
@@ -43,6 +83,7 @@ public class BatchParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@SuppressWarnings({"resource", "rawtypes"})
|
||||
public void testOverrideBeansLast() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/jsr/configuration/xml/batch.xml",
|
||||
@@ -53,4 +94,17 @@ public class BatchParserTests {
|
||||
assertNotNull(processor);
|
||||
assertTrue(processor instanceof DummyItemProcessor);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableBatchProcessing
|
||||
public static class BaseConfiguration extends DefaultBatchConfigurer {
|
||||
|
||||
@Bean
|
||||
DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder().
|
||||
addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql").
|
||||
addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql").
|
||||
build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.batch.api.chunk.AbstractItemWriter;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ChunkListener;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.scope.context.ChunkContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ChunkListenerParsingTests {
|
||||
|
||||
@Autowired
|
||||
public Job job;
|
||||
|
||||
@Autowired
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
public SpringChunkListener springChunkListener;
|
||||
|
||||
@Autowired
|
||||
public JsrChunkListener jsrChunkListener;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.FAILED, execution.getStatus());
|
||||
assertEquals(3, execution.getStepExecutions().size());
|
||||
assertEquals(4, springChunkListener.beforeChunkCount);
|
||||
assertEquals(3, springChunkListener.afterChunkCount);
|
||||
assertEquals(4, jsrChunkListener.beforeChunkCount);
|
||||
assertEquals(3, jsrChunkListener.afterChunkCount);
|
||||
assertEquals(1, springChunkListener.afterChunkErrorCount);
|
||||
assertEquals(1, jsrChunkListener.afterChunkErrorCount);
|
||||
}
|
||||
|
||||
public static class SpringChunkListener implements ChunkListener {
|
||||
|
||||
protected int beforeChunkCount = 0;
|
||||
protected int afterChunkCount = 0;
|
||||
protected int afterChunkErrorCount = 0;
|
||||
|
||||
@Override
|
||||
public void beforeChunk(ChunkContext context) {
|
||||
beforeChunkCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterChunk(ChunkContext context) {
|
||||
afterChunkCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterChunkError(ChunkContext context) {
|
||||
afterChunkErrorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsrChunkListener implements javax.batch.api.chunk.listener.ChunkListener {
|
||||
|
||||
protected int beforeChunkCount = 0;
|
||||
protected int afterChunkCount = 0;
|
||||
protected int afterChunkErrorCount = 0;
|
||||
|
||||
@Override
|
||||
public void beforeChunk() throws Exception {
|
||||
beforeChunkCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) throws Exception {
|
||||
afterChunkErrorCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterChunk() throws Exception {
|
||||
afterChunkCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ErrorThrowingItemWriter extends AbstractItemWriter {
|
||||
|
||||
@Override
|
||||
public void writeItems(List<Object> items) throws Exception {
|
||||
throw new Exception("This should cause the rollback");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import javax.batch.api.chunk.ItemProcessor;
|
||||
|
||||
|
||||
public class CountingItemProcessor implements ItemProcessor {
|
||||
protected int count = 0;
|
||||
|
||||
@Override
|
||||
public Object processItem(Object item) throws Exception {
|
||||
count++;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,23 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -16,7 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"DecisionParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class DecisionParsingTests {
|
||||
|
||||
@@ -27,6 +43,7 @@ public class DecisionParsingTests {
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws Exception {
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -6,6 +21,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -19,7 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"ExceptionHandlingParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ExceptionHandlingParsingTests {
|
||||
|
||||
@@ -30,6 +46,7 @@ public class ExceptionHandlingParsingTests {
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testSkippable() throws Exception {
|
||||
JobExecution execution1 = jobLauncher.run(job, new JobParametersBuilder().addLong("run", 1l).toJobParameters());
|
||||
assertEquals(BatchStatus.FAILED, execution1.getStatus());
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ItemProcessListener;
|
||||
import org.springframework.batch.core.ItemReadListener;
|
||||
import org.springframework.batch.core.ItemWriteListener;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ItemListenerParsingTests {
|
||||
|
||||
@Autowired
|
||||
public Job job;
|
||||
|
||||
@Autowired
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
public SpringItemListener springListener;
|
||||
|
||||
@Autowired
|
||||
public JsrItemListener jsrListener;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(3, execution.getStepExecutions().size());
|
||||
assertEquals(6, springListener.beforeReadCount);
|
||||
assertEquals(4, springListener.afterReadCount);
|
||||
assertEquals(4, springListener.beforeProcessCount);
|
||||
assertEquals(4, springListener.afterProcessCount);
|
||||
assertEquals(2, springListener.beforeWriteCount);
|
||||
assertEquals(2, springListener.afterWriteCount);
|
||||
assertEquals(6, jsrListener.beforeReadCount);
|
||||
assertEquals(4, jsrListener.afterReadCount);
|
||||
assertEquals(4, jsrListener.beforeProcessCount);
|
||||
assertEquals(4, jsrListener.afterProcessCount);
|
||||
assertEquals(2, jsrListener.beforeWriteCount);
|
||||
assertEquals(2, jsrListener.afterWriteCount);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static class SpringItemListener implements ItemReadListener, ItemProcessListener, ItemWriteListener {
|
||||
|
||||
protected int beforeReadCount = 0;
|
||||
protected int afterReadCount = 0;
|
||||
protected int onReadErrorCount = 0;
|
||||
protected int beforeProcessCount = 0;
|
||||
protected int afterProcessCount = 0;
|
||||
protected int onProcessErrorCount = 0;
|
||||
protected int beforeWriteCount = 0;
|
||||
protected int afterWriteCount = 0;
|
||||
protected int onWriteErrorCount = 0;
|
||||
|
||||
@Override
|
||||
public void beforeRead() {
|
||||
beforeReadCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRead(Object item) {
|
||||
afterReadCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadError(Exception ex) {
|
||||
onReadErrorCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeWrite(List items) {
|
||||
beforeWriteCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWrite(List items) {
|
||||
afterWriteCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteError(Exception exception, List items) {
|
||||
onWriteErrorCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess(Object item) {
|
||||
beforeProcessCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(Object item, Object result) {
|
||||
afterProcessCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProcessError(Object item, Exception e) {
|
||||
onProcessErrorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsrItemListener implements javax.batch.api.chunk.listener.ItemReadListener, javax.batch.api.chunk.listener.ItemProcessListener, javax.batch.api.chunk.listener.ItemWriteListener {
|
||||
|
||||
protected int beforeReadCount = 0;
|
||||
protected int afterReadCount = 0;
|
||||
protected int onReadErrorCount = 0;
|
||||
protected int beforeProcessCount = 0;
|
||||
protected int afterProcessCount = 0;
|
||||
protected int onProcessErrorCount = 0;
|
||||
protected int beforeWriteCount = 0;
|
||||
protected int afterWriteCount = 0;
|
||||
protected int onWriteErrorCount = 0;
|
||||
|
||||
@Override
|
||||
public void beforeWrite(List<Object> items) throws Exception {
|
||||
beforeWriteCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterWrite(List<Object> items) throws Exception {
|
||||
afterWriteCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWriteError(List<Object> items, Exception ex)
|
||||
throws Exception {
|
||||
onWriteErrorCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeProcess(Object item) throws Exception {
|
||||
beforeProcessCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterProcess(Object item, Object result) throws Exception {
|
||||
afterProcessCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProcessError(Object item, Exception ex) throws Exception {
|
||||
onProcessErrorCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRead() throws Exception {
|
||||
beforeReadCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRead(Object item) throws Exception {
|
||||
afterReadCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReadError(Exception ex) throws Exception {
|
||||
onReadErrorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -5,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -23,7 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"ItemSkipParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ItemSkipParsingTests {
|
||||
|
||||
@@ -37,6 +53,7 @@ public class ItemSkipParsingTests {
|
||||
public TestSkipListener skipListener;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws Exception {
|
||||
// Read skip and fail
|
||||
JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().toJobParameters());
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.batch.api.listener.JobListener;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -15,7 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"JobListenerParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JobListenerParsingTests {
|
||||
|
||||
@@ -26,7 +43,10 @@ public class JobListenerParsingTests {
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
public JobListener listener;
|
||||
public SpringJobListener springListener;
|
||||
|
||||
@Autowired
|
||||
public JsrJobListener jsrListener;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
@@ -36,11 +56,13 @@ public class JobListenerParsingTests {
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(2, execution.getStepExecutions().size());
|
||||
assertEquals(1, listener.countAfterJob);
|
||||
assertEquals(1, listener.countBeforeJob);
|
||||
assertEquals(1, springListener.countAfterJob);
|
||||
assertEquals(1, springListener.countBeforeJob);
|
||||
assertEquals(1, jsrListener.countAfterJob);
|
||||
assertEquals(1, jsrListener.countBeforeJob);
|
||||
}
|
||||
|
||||
public static class JobListener implements JobExecutionListener {
|
||||
public static class SpringJobListener implements JobExecutionListener {
|
||||
|
||||
protected int countBeforeJob = 0;
|
||||
protected int countAfterJob = 0;
|
||||
@@ -55,4 +77,20 @@ public class JobListenerParsingTests {
|
||||
countAfterJob++;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsrJobListener implements JobListener {
|
||||
|
||||
protected int countBeforeJob = 0;
|
||||
protected int countAfterJob = 0;
|
||||
|
||||
@Override
|
||||
public void afterJob() throws Exception {
|
||||
countBeforeJob++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeJob() throws Exception {
|
||||
countAfterJob++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -11,7 +26,6 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
@@ -19,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"SimpleItemBasedJobParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SimpleItemBasedJobParsingTests {
|
||||
|
||||
@@ -52,16 +66,6 @@ public class SimpleItemBasedJobParsingTests {
|
||||
assertEquals(3, policy.counter);
|
||||
}
|
||||
|
||||
public static class CountingItemProcessor implements ItemProcessor<String, String>{
|
||||
protected int count = 0;
|
||||
|
||||
@Override
|
||||
public String process(String item) throws Exception {
|
||||
count++;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CountingCompletionPolicy implements CompletionPolicy {
|
||||
|
||||
protected int counter;
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.springframework.batch.core.jsr.configuration.xml;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.batch.api.Batchlet;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -16,7 +18,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"SimpleJobParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class SimpleJobParsingTests {
|
||||
|
||||
@@ -38,6 +40,9 @@ public class SimpleJobParsingTests {
|
||||
@Autowired
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
public Batchlet batchlet;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
assertNotNull(job);
|
||||
@@ -48,6 +53,7 @@ public class SimpleJobParsingTests {
|
||||
assertEquals("step2", step2.getName());
|
||||
assertNotNull(step3);
|
||||
assertEquals("step3", step3.getName());
|
||||
assertNotNull(batchlet);
|
||||
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
|
||||
@@ -1,9 +1,25 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -33,6 +49,7 @@ public class SplitParsingTests {
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void test() throws Exception {
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
@@ -40,6 +57,7 @@ public class SplitParsingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testOneFlowInSplit() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("/org/springframework/batch/core/jsr/configuration/xml/invalid-split-context.xml");
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.jsr.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.batch.api.listener.StepListener;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
@@ -16,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@ContextConfiguration({"StepListenerParsingTests-context.xml", "jsr-base-context.xml"})
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class StepListenerParsingTests {
|
||||
|
||||
@@ -27,18 +44,23 @@ public class StepListenerParsingTests {
|
||||
public JobLauncher jobLauncher;
|
||||
|
||||
@Autowired
|
||||
public StepListener stepListener;
|
||||
public SpringStepListener springStepListener;
|
||||
|
||||
@Autowired
|
||||
public JsrStepListener jsrStepListener;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
JobExecution execution = jobLauncher.run(job, new JobParameters());
|
||||
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
|
||||
assertEquals(2, execution.getStepExecutions().size());
|
||||
assertEquals(2, stepListener.countBeforeStep);
|
||||
assertEquals(2, stepListener.countAfterStep);
|
||||
assertEquals(3, execution.getStepExecutions().size());
|
||||
assertEquals(2, springStepListener.countBeforeStep);
|
||||
assertEquals(2, springStepListener.countAfterStep);
|
||||
assertEquals(2, jsrStepListener.countBeforeStep);
|
||||
assertEquals(2, jsrStepListener.countAfterStep);
|
||||
}
|
||||
|
||||
public static class StepListener implements StepExecutionListener {
|
||||
public static class SpringStepListener implements StepExecutionListener {
|
||||
protected int countBeforeStep = 0;
|
||||
protected int countAfterStep = 0;
|
||||
|
||||
@@ -53,4 +75,19 @@ public class StepListenerParsingTests {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsrStepListener implements StepListener {
|
||||
protected int countBeforeStep = 0;
|
||||
protected int countAfterStep = 0;
|
||||
|
||||
@Override
|
||||
public void beforeStep() throws Exception {
|
||||
countBeforeStep++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterStep() throws Exception {
|
||||
countAfterStep++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.springframework.batch.core.jsr.step.batchlet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import javax.batch.api.Batchlet;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
|
||||
public class BatchletAdapterTests {
|
||||
|
||||
private BatchletAdapter adapter;
|
||||
@Mock
|
||||
private Batchlet delegate;
|
||||
@Mock
|
||||
private StepContribution contribution;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
adapter = new BatchletAdapter(delegate);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
adapter = new BatchletAdapter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteNoExitStatus() throws Exception {
|
||||
assertEquals(RepeatStatus.FINISHED, adapter.execute(contribution, null));
|
||||
|
||||
verify(delegate).process();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteWithExitStatus() throws Exception {
|
||||
when(delegate.process()).thenReturn("my exit status");
|
||||
|
||||
assertEquals(RepeatStatus.FINISHED, adapter.execute(contribution, null));
|
||||
|
||||
verify(delegate).process();
|
||||
verify(contribution).setExitStatus(new ExitStatus("my exit status"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.springframework.batch.core.jsr.step.batchlet;
|
||||
|
||||
import javax.batch.api.Batchlet;
|
||||
|
||||
public class BatchletSupport implements Batchlet {
|
||||
|
||||
@Override
|
||||
public String process() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
// no-op
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user