View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2004, DbUnit.org
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2.1 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   *
20   */
21  package org.dbunit.dataset.stream;
22  
23  import org.dbunit.dataset.Column;
24  import org.dbunit.dataset.DataSetException;
25  import org.dbunit.dataset.DefaultTableMetaData;
26  import org.dbunit.dataset.ITableMetaData;
27  import org.dbunit.dataset.datatype.DataType;
28  
29  /**
30   * @author Manuel Laflamme
31   * @since Jun 12, 2003
32   * @version $Revision$
33   */
34  public class MockDataSetProducer implements IDataSetProducer
35  {
36      private int _tableCount;
37      private int _columnCount;
38      private int _rowCount;
39      private IDataSetConsumer _consumer = new DefaultConsumer();
40  
41      public void setupTableCount(int tableCount)
42      {
43          _tableCount = tableCount;
44      }
45  
46      public void setupColumnCount(int columnCount)
47      {
48          _columnCount = columnCount;
49      }
50  
51      public void setupRowCount(int rowCount)
52      {
53          _rowCount = rowCount;
54      }
55  
56      ////////////////////////////////////////////////////////////////////////////
57      // IDataSetProducer interface
58  
59      public void setConsumer(IDataSetConsumer consumer) throws DataSetException
60      {
61          _consumer = consumer;
62      }
63  
64      public void produce() throws DataSetException
65      {
66          _consumer.startDataSet();
67          for (int i = 0; i < _tableCount; i++)
68          {
69              String tableName = "TABLE" + i;
70              Column[] columns = new Column[_columnCount];
71              for (int j = 0; j < columns.length; j++)
72              {
73                  columns[j] = new Column("COLUMN" + j, DataType.UNKNOWN);
74              }
75              ITableMetaData metaData = new DefaultTableMetaData(tableName, columns);
76  
77              _consumer.startTable(metaData);
78  
79              for (int j = 0; j < _rowCount; j++)
80              {
81                  Object[] values = new Object[_columnCount];
82                  for (int k = 0; k < values.length; k++)
83                  {
84                      values[k] = j + "," + k;
85                  }
86                  _consumer.row(values);
87              }
88              _consumer.endTable();
89          }
90          _consumer.endDataSet();
91      }
92  }