KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > csv > CsvDataSetWriterTest


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 JavaDoc;
10
11 /**
12  * Created By: fede
13  * Date: 10-mar-2004
14  * Time: 17.21.34
15  *
16  * Last Checkin: $Author: fspinazzi $
17  * Date: $Date: 2004/04/06 06:51:53 $
18  * Revision: $Revision: 1.3 $
19  */

20 public class CsvDataSetWriterTest extends TestCase {
21     private static final String JavaDoc DEST = "target/csv/orders-out";
22     private static final String JavaDoc SOURCE = "src/csv/orders";
23
24     public void testProduceAndWriteBackToDisk () throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc source, String JavaDoc dest) throws DataSetException {
40         CsvProducer producer = new CsvProducer(source);
41         new File JavaDoc(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