View Javadoc
1   package org.dbunit.dataset.stream;
2   
3   import org.dbunit.dataset.ITableMetaData;
4   import org.dbunit.dataset.MockTableMetaData;
5   import junit.framework.TestCase;
6   
7   public class BufferedConsumerTest extends TestCase {
8   
9   	public void testBufferedConsumer() throws Exception {
10  		MockDataSetConsumer wrappedConsumer = new MockDataSetConsumer();
11  
12  		ITableMetaData table1MetaData = new MockTableMetaData("TESTTABLE1", new String[] { "COLUMN1", "COLUMN2",
13  				"COLUMN3" });
14  		ITableMetaData table2MetaData = new MockTableMetaData("TESTTABLE2", new String[] { "COLUMN1", "COLUMN2",
15  				"COLUMN3" });
16  		IDataSetConsumer dataSetConsumer = new BufferedConsumer(wrappedConsumer);
17  
18  		Object[] testRow = new Object[] { "v1", "v2", "v3" };
19  
20  		// Expected result
21  		wrappedConsumer.addExpectedStartDataSet();
22  
23  		wrappedConsumer.addExpectedStartTable(table1MetaData);
24  
25  		wrappedConsumer.addExpectedRow(table1MetaData.getTableName(), testRow);
26  		wrappedConsumer.addExpectedRow(table1MetaData.getTableName(), testRow);
27  
28  		wrappedConsumer.addExpectedEndTable(table1MetaData.getTableName());
29  
30  		wrappedConsumer.addExpectedStartTable(table2MetaData);
31  
32  		wrappedConsumer.addExpectedRow(table2MetaData.getTableName(), testRow);
33  
34  		wrappedConsumer.addExpectedEndTable(table2MetaData.getTableName());
35  
36  		wrappedConsumer.addExpectedEndDataSet();
37  
38  		// Actual data
39  		dataSetConsumer.startDataSet();
40  
41  		dataSetConsumer.startTable(table1MetaData);
42  
43  		dataSetConsumer.row(testRow);
44  		dataSetConsumer.row(testRow);
45  
46  		dataSetConsumer.endTable();
47  
48  		dataSetConsumer.startTable(table2MetaData);
49  
50  		dataSetConsumer.row(testRow);
51  
52  		dataSetConsumer.endTable();
53  
54  		dataSetConsumer.endDataSet();
55  
56  		// Verification
57  		wrappedConsumer.verify();
58  	}
59  }