RESOLVED - issue BATCH-788: Remove flush/clear from ItemWriter

Done
This commit is contained in:
dsyer
2008-08-20 09:59:51 +00:00
parent 9e1d35a546
commit 42a9b97d1f
40 changed files with 94 additions and 244 deletions

View File

@@ -103,12 +103,6 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
}
}
/**
* Test method for
* {@link org.springframework.batch.item.database.BatchSqlUpdateItemWriter#flush()}
* .
* @throws Exception
*/
public void testWriteAndFlush() throws Exception {
ps.addBatch();
expectLastCall();
@@ -119,12 +113,6 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
assertTrue(list.contains("SQL"));
}
/**
* Test method for
* {@link org.springframework.batch.item.database.BatchSqlUpdateItemWriter#flush()}
* .
* @throws Exception
*/
public void testWriteAndFlushWithEmptyUpdate() throws Exception {
ps.addBatch();
expectLastCall();

View File

@@ -21,7 +21,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.item.support.AbstractItemWriter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateTemplate;
@@ -42,7 +42,7 @@ public class HibernateAwareItemWriterTests extends TestCase {
};
}
private class StubItemWriter extends AbstractItemWriter<Object> {
private class StubItemWriter implements ItemWriter<Object> {
public void write(List<? extends Object> items) {
list.addAll(items);
}

View File

@@ -16,6 +16,11 @@
package org.springframework.batch.item.file;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@@ -24,14 +29,14 @@ import java.nio.charset.UnsupportedCharsetException;
import java.util.Arrays;
import java.util.Collections;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.file.transform.LineAggregator;
import org.springframework.batch.item.file.transform.PassThroughLineAggregator;
import org.springframework.core.io.FileSystemResource;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -44,7 +49,7 @@ import org.springframework.util.ClassUtils;
* @author Dave Syer
*
*/
public class FlatFileItemWriterTests extends TestCase {
public class FlatFileItemWriterTests {
// object under test
private FlatFileItemWriter<String> writer = new FlatFileItemWriter<String>();
@@ -64,7 +69,8 @@ public class FlatFileItemWriterTests extends TestCase {
* Create temporary output file, define mock behaviour, set dependencies and
* initialize the object under test
*/
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
outputFile = File.createTempFile("flatfile-test-output-", ".tmp");
@@ -78,7 +84,8 @@ public class FlatFileItemWriterTests extends TestCase {
/**
* Release resources and delete the temporary output file
*/
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
if (reader != null) {
reader.close();
}
@@ -100,6 +107,7 @@ public class FlatFileItemWriterTests extends TestCase {
return reader.readLine();
}
@Test
public void testWriteWithMultipleOpen() throws Exception {
writer.open(executionContext);
@@ -110,6 +118,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals("test2", readLine());
}
@Test
public void testOpenTwice() {
// opening the writer twice should cause no issues
writer.open(executionContext);
@@ -121,6 +130,7 @@ public class FlatFileItemWriterTests extends TestCase {
*
* @throws Exception
*/
@Test
public void testWriteString() throws Exception {
writer.open(executionContext);
writer.write(Collections.singletonList(TEST_STRING));
@@ -135,6 +145,7 @@ public class FlatFileItemWriterTests extends TestCase {
*
* @throws Exception
*/
@Test
public void testWriteWithConverter() throws Exception {
writer.setLineAggregator(new LineAggregator<String>() {
public String aggregate(String item) {
@@ -154,6 +165,7 @@ public class FlatFileItemWriterTests extends TestCase {
*
* @throws Exception
*/
@Test
public void testWriteWithConverterAndString() throws Exception {
writer.setLineAggregator(new LineAggregator<String>() {
public String aggregate(String item) {
@@ -171,6 +183,7 @@ public class FlatFileItemWriterTests extends TestCase {
*
* @throws Exception
*/
@Test
public void testWriteRecord() throws Exception {
writer.open(executionContext);
writer.write(Collections.singletonList("1"));
@@ -178,6 +191,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals("1", lineFromFile);
}
@Test
public void testWriteRecordWithrecordSeparator() throws Exception {
writer.setLineSeparator("|");
writer.open(executionContext);
@@ -186,6 +200,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals("1|2|", lineFromFile);
}
@Test
public void testRestart() throws Exception {
writer.open(executionContext);
@@ -217,6 +232,7 @@ public class FlatFileItemWriterTests extends TestCase {
}
@Test
public void testOpenWithNonWritableFile() throws Exception {
writer = new FlatFileItemWriter<String>();
writer.setLineAggregator(new PassThroughLineAggregator<String>());
@@ -237,6 +253,7 @@ public class FlatFileItemWriterTests extends TestCase {
}
}
@Test
public void testAfterPropertiesSetChecksMandatory() throws Exception {
writer = new FlatFileItemWriter<String>();
try {
@@ -248,6 +265,7 @@ public class FlatFileItemWriterTests extends TestCase {
}
}
@Test
public void testDefaultStreamContext() throws Exception {
writer = new FlatFileItemWriter<String>();
writer.setResource(new FileSystemResource(outputFile));
@@ -261,6 +279,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals(0, executionContext.getLong(ClassUtils.getShortName(FlatFileItemWriter.class) + ".current.count"));
}
@Test
public void testWriteStringWithBogusEncoding() throws Exception {
writer.setEncoding("BOGUS");
try {
@@ -273,6 +292,7 @@ public class FlatFileItemWriterTests extends TestCase {
writer.close(null);
}
@Test
public void testWriteStringWithEncodingAfterClose() throws Exception {
testWriteStringWithBogusEncoding();
writer.setEncoding("UTF-8");
@@ -283,6 +303,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals(TEST_STRING, lineFromFile);
}
@Test
public void testWriteHeader() throws Exception {
writer.setHeaderLines(new String[] { "a", "b" });
writer.open(executionContext);
@@ -296,6 +317,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals(TEST_STRING, lineFromFile);
}
@Test
public void testWriteHeaderAfterRestartOnFirstChunk() throws Exception {
writer.setHeaderLines(new String[] { "a", "b" });
writer.open(executionContext);
@@ -314,6 +336,7 @@ public class FlatFileItemWriterTests extends TestCase {
assertEquals(null, lineFromFile);
}
@Test
public void testWriteHeaderAfterRestartOnSecondChunk() throws Exception {
writer.setHeaderLines(new String[] { "a", "b" });
writer.open(executionContext);

View File

@@ -110,7 +110,6 @@ public class StaxEventItemWriterTests {
writer.setHeaderItems(new Object[] {header1, header2});
writer.open(executionContext);
writer.write(items);
writer.flush();
String content = outputFileContent();
assertTrue("Wrong content: "+content, content.contains(("<!--" + header1 + "-->")));
assertTrue("Wrong content: "+content, content.contains(("<!--" + header2 + "-->")));

View File

@@ -21,10 +21,10 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.mapping.FieldSet;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.support.AbstractItemWriter;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -67,7 +67,7 @@ public abstract class AbstractTradeBatchTests extends TestCase {
}
}
protected static class TradeWriter extends AbstractItemWriter<Trade> {
protected static class TradeWriter implements ItemWriter<Trade> {
int count = 0;
// This has to be synchronized because we are going to test the state