1 package org.dbunit.dataset.csv; 2 3 import junit.framework.TestCase; 4 import org.dbunit.Assertion; 5 import org.dbunit.dataset.CachedDataSet; 6 import org.dbunit.dataset.DataSetException; 7 import org.dbunit.dataset.IDataSet; 8 9 import java.io.File ; 10 11 20 public class CsvDataSetWriterTest extends TestCase { 21 private static final String DEST = "target/csv/orders-out"; 22 private static final String SOURCE = "src/csv/orders"; 23 24 public void testProduceAndWriteBackToDisk () throws Exception { 25 produceToFolder (SOURCE, DEST); 26 IDataSet expected = produceToMemory (SOURCE); 27 IDataSet actual = produceToMemory(DEST); 28 Assertion.assertEquals(expected, actual); 29 } 30 31 private IDataSet produceToMemory(String source) throws DataSetException { 32 CsvProducer producer = new CsvProducer(source); 33 CachedDataSet cached = new CachedDataSet(); 34 producer.setConsumer(cached); 35 producer.produce(); 36 return cached; 37 } 38 39 private void produceToFolder(String source, String dest) throws DataSetException { 40 CsvProducer producer = new CsvProducer(source); 41 new File (dest).delete(); 42 CsvDataSetWriter writer = new CsvDataSetWriter(dest); 43 producer.setConsumer(writer); 44 producer.produce(); 45 } 46 47 public void testEscapeQuote () { 48 assertEquals("\\\"foo\\\"", CsvDataSetWriter.escape("\"foo\"")); 49 } 50 51 public void testEscapeEscape () { 52 assertEquals("\\\\foo\\\\", CsvDataSetWriter.escape("\\foo\\")); 53 } 54 55 } 56 | Popular Tags |