Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset In directory sc8-pr-cvs1:/tmp/cvs-serv15860/src/test/org/dbunit/dataset Modified Files: Tag: branch-exml2sax MockDataSetConsumer.java Added Files: Tag: branch-exml2sax AbstractProducerTest.java Removed Files: Tag: branch-exml2sax AbstractDataSetProducerTest.java Log Message: * Removed dtdparser.jar. Now use SAX to parse DTD. * Added more flat XML provider tests. --- NEW FILE: AbstractProducerTest.java --- /* * * The DbUnit Database Testing Framework * Copyright (C)2002, Manuel Laflamme * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ package org.dbunit.dataset; import org.dbunit.dataset.datatype.DataType; import junit.framework.TestCase; /** * @author Manuel Laflamme * @since Apr 29, 2003 * @version $Revision: 1.1.2.1 $ */ public abstract class AbstractProducerTest extends TestCase { private static final String[] TABLE_NAMES = { "DUPLICATE_TABLE", "SECOND_TABLE", "TEST_TABLE", "DUPLICATE_TABLE", "NOT_NULL_TABLE", "EMPTY_TABLE", }; public AbstractProducerTest(String s) { super(s); } protected String[] getExpectedNames() throws Exception { return (String[])TABLE_NAMES.clone(); } protected int[] getExpectedRowCount() throws Exception { return new int[] {1, 2, 3, 2, 1, 0}; } protected String getNotNullTableName() throws Exception { return "NOT_NULL_TABLE"; } protected Column[] createExpectedColumns(Column.Nullable nullable) throws Exception { Column[] columns = new Column[4]; for (int i = 0; i < columns.length; i++) { columns[i] = new Column("COLUMN" + i, DataType.UNKNOWN, nullable); } return columns; } protected Object[] createExpectedRow(int row) throws Exception { Object[] values = new Object[4]; for (int i = 0; i < values.length; i++) { values[i] = "row " + row + " col " + i; } return values; } protected abstract IDataSetProducer createProducer() throws Exception; public void testProduce() throws Exception { // Setup consumer MockDataSetConsumer consumer = new MockDataSetConsumer(); consumer.addExpectedStartDataSet(); String[] expectedNames = getExpectedNames(); int[] rowCounts = getExpectedRowCount(); for (int i = 0; i < expectedNames.length; i++) { String expectedName = expectedNames[i]; Column.Nullable nullable = expectedName.equals(getNotNullTableName()) ? Column.NO_NULLS : Column.NULLABLE; Column[] expectedColumns = createExpectedColumns(nullable); consumer.addExpectedStartTable(expectedName, expectedColumns); for (int j = 0; j < rowCounts[i]; j++) { consumer.addExpectedRow(expectedName, createExpectedRow(j)); } consumer.addExpectedEndTable(expectedName); } consumer.addExpectedEndDataSet(); // Setup producer IDataSetProducer producer = createProducer(); producer.setConsumer(consumer); // Produce and verify consumer producer.produce(); consumer.verify(); } public void testProduceWithoutConsumer() throws Exception { IDataSetProducer producer = createProducer(); producer.produce(); } } Index: MockDataSetConsumer.java =================================================================== RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/Attic/MockDataSetConsumer.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** MockDataSetConsumer.java 30 Apr 2003 02:17:01 -0000 1.1.2.3 --- MockDataSetConsumer.java 30 Apr 2003 21:12:51 -0000 1.1.2.4 *************** *** 21,25 **** private final ExpectationList _expectedList = new ExpectationList(""); private String _actualTableName; - private int _actualTableRow = 0; public void addExpectedStartDataSet() throws Exception --- 21,24 ---- *************** *** 48,51 **** --- 47,56 ---- } + public void addExpectedEmptyTable(String tableName, Column[] columns) throws Exception + { + addExpectedStartTable(tableName, columns); + addExpectedEndTable(tableName); + } + public void addExpectedEmptyTableIgnoreColumns(String tableName) throws Exception { *************** *** 59,65 **** } ! public void addExpectedRow(String tableName, int row, Object[] values) throws Exception { ! _expectedList.addExpected(new RowEvent(tableName, row, values)); } --- 64,70 ---- } ! public void addExpectedRow(String tableName, Object[] values) throws Exception { ! _expectedList.addExpected(new RowEvent(tableName, values)); } *************** *** 89,93 **** _expectedList.addActual(new StartTableEvent(metaData, false)); _actualTableName = metaData.getTableName(); - _actualTableRow = 0; } --- 94,97 ---- *************** *** 96,100 **** _expectedList.addActual(new EndTableEvent(_actualTableName)); _actualTableName = null; - _actualTableRow = 0; } --- 100,103 ---- *************** *** 102,107 **** { _expectedList.addActual( ! new RowEvent(_actualTableName, _actualTableRow, values)); ! _actualTableRow++; } --- 105,109 ---- { _expectedList.addActual( ! new RowEvent(_actualTableName, values)); } *************** *** 237,248 **** { private final String _tableName; - private final int _row; private final Object[] _values; ! public RowEvent(String tableName, int row, Object[] values) { super("row()"); _tableName = tableName; - _row = row; _values = values; } --- 239,248 ---- { private final String _tableName; private final Object[] _values; ! public RowEvent(String tableName, Object[] values) { super("row()"); _tableName = tableName; _values = values; } *************** *** 256,260 **** final RowEvent rowItem = (RowEvent)o; - if (_row != rowItem._row) return false; if (!_tableName.equals(rowItem._tableName)) return false; // Probably incorrect - comparing Object[] arrays with Arrays.equals --- 256,259 ---- *************** *** 268,272 **** int result = super.hashCode(); result = 29 * result + _tableName.hashCode(); - result = 29 * result + _row; return result; } --- 267,270 ---- *************** *** 274,279 **** public String toString() { ! return _name + ": table=" + _tableName + ", row=" + _row + ! ", values=" + Arrays.asList(_values); } --- 272,276 ---- public String toString() { ! return _name + ": table=" + _tableName + ", values=" + Arrays.asList(_values); } --- AbstractDataSetProducerTest.java DELETED --- |