RESOLVED - BATCH-1147:

*Fixed SimpleChunkProcessor so that the filter count is applied correctly
 *Updated SimpleChunkProcessorTests and CustomerFilterJobFunctionalTests to check the filter count.
This commit is contained in:
dhgarrette
2009-03-13 17:26:50 +00:00
parent b3ba438e1a
commit 9e35519672
4 changed files with 79 additions and 60 deletions

View File

@@ -3,6 +3,7 @@ package org.springframework.batch.core.step.item;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
@@ -12,12 +13,27 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.PassThroughItemProcessor;
public class SimpleChunkProcessorTests {
private SimpleChunkProcessor<String, String> processor;
private SimpleChunkProcessor<String, String> processor = new SimpleChunkProcessor<String, String>(
new ItemProcessor<String, String>() {
public String process(String item) throws Exception {
if (item.equals("err")) {
return null;
}
return item;
}
}, new ItemWriter<String>() {
public void write(List<? extends String> items) throws Exception {
if (items.contains("fail")) {
throw new RuntimeException("Planned failure!");
}
list.addAll(items);
}
});
private StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(
new JobInstance(123L, new JobParameters(), "job"))));
@@ -26,24 +42,19 @@ public class SimpleChunkProcessorTests {
@Before
public void setUp() {
processor = new SimpleChunkProcessor<String, String>(new PassThroughItemProcessor<String>(),
new ItemWriter<String>() {
public void write(List<? extends String> items) throws Exception {
if (items.contains("fail")) {
throw new RuntimeException("Planned failure!");
}
list.addAll(items);
}
});
list.clear();
}
@Test
public void testProcess() throws Exception {
Chunk<String> chunk = new Chunk<String>();
chunk.add("foo");
chunk.add("err");
chunk.add("bar");
processor.process(contribution, chunk);
assertEquals(2, list.size());
assertEquals(Arrays.asList("foo", "bar"), list);
assertEquals(1, contribution.getFilterCount());
assertEquals(2, contribution.getWriteCount());
}
}