Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset
In directory usw-pr-cvs1:/tmp/cvs-serv21203/dbunit/src/test/org/dbunit/dataset
Modified Files:
CaseInsensitiveDataSetTest.java CompositeDataSetTest.java
FilteredDataSetTest.java AbstractDataSetTest.java
DefaultDataSetTest.java
Log Message:
Feature 551925 - Allow duplicate table names in dataset.
Index: CaseInsensitiveDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/CaseInsensitiveDataSetTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CaseInsensitiveDataSetTest.java 13 Jun 2002 17:25:00 -0000 1.2
--- CaseInsensitiveDataSetTest.java 3 Aug 2002 02:26:41 -0000 1.3
***************
*** 12,15 ****
--- 12,16 ----
import org.dbunit.dataset.xml.XmlDataSet;
+ import org.dbunit.dataset.xml.FlatXmlDataSet;
import java.io.FileInputStream;
***************
*** 30,33 ****
--- 31,40 ----
return new CaseInsensitiveDataSet(new XmlDataSet(new FileInputStream(
"src/xml/caseInsensitiveDataSetTest.xml")));
+ }
+
+ protected IDataSet createDuplicateDataSet() throws Exception
+ {
+ return new CaseInsensitiveDataSet(new FlatXmlDataSet(new FileInputStream(
+ "src/xml/caseInsensitiveDataSetDuplicateTest.xml")));
}
Index: CompositeDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/CompositeDataSetTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** CompositeDataSetTest.java 13 Jun 2002 17:25:00 -0000 1.5
--- CompositeDataSetTest.java 3 Aug 2002 02:26:41 -0000 1.6
***************
*** 24,27 ****
--- 24,28 ----
import org.dbunit.dataset.xml.XmlDataSet;
+ import org.dbunit.dataset.xml.FlatXmlDataSet;
import java.io.FileInputStream;
***************
*** 51,54 ****
--- 52,70 ----
return new CompositeDataSet(dataSet1, dataSet2);
+ }
+
+ protected IDataSet createDuplicateDataSet() throws Exception
+ {
+ IDataSet dataSet1 = new FlatXmlDataSet(
+ new FileInputStream("src/xml/compositeDataSetDuplicateTest1.xml"));
+ assertTrue("count before combine (1)",
+ dataSet1.getTableNames().length < getExpectedDuplicateNames().length);
+
+ IDataSet dataSet2 = new FlatXmlDataSet(
+ new FileInputStream("src/xml/compositeDataSetDuplicateTest2.xml"));
+ assertTrue("count before combine (2)",
+ dataSet2.getTableNames().length < getExpectedDuplicateNames().length);
+
+ return new CompositeDataSet(dataSet1, dataSet2, false);
}
}
Index: FilteredDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/FilteredDataSetTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** FilteredDataSetTest.java 4 Jul 2002 21:33:42 -0000 1.6
--- FilteredDataSetTest.java 3 Aug 2002 02:26:41 -0000 1.7
***************
*** 24,27 ****
--- 24,29 ----
import org.dbunit.dataset.xml.XmlDataSet;
+ import org.dbunit.dataset.xml.FlatXmlDataSet;
+ import org.dbunit.database.AmbiguousTableNameException;
import java.io.FileInputStream;
***************
*** 51,54 ****
--- 53,69 ----
}
+ protected IDataSet createDuplicateDataSet() throws Exception
+ {
+ IDataSet dataSet1 = new XmlDataSet(
+ new FileInputStream("src/xml/xmlDataSetDuplicateTest.xml"));
+ IDataSet dataSet2 = new XmlDataSet(
+ new FileInputStream("src/xml/filteredDataSetTest.xml"));
+
+ IDataSet dataSet = new CompositeDataSet(dataSet1, dataSet2, false);
+ assertEquals("count before filter", getExpectedDuplicateNames().length + 1,
+ dataSet.getTableNames().length);
+ return new FilteredDataSet(getExpectedDuplicateNames(), dataSet);
+ }
+
public void testGetFilteredTableNames() throws Exception
{
***************
*** 121,124 ****
--- 136,151 ----
}
+ public void testGetDuplicateTables() throws Exception
+ {
+ IDataSet dataSet = createDuplicateDataSet();
+ try
+ {
+ dataSet.getTables();
+ fail("Should throw AmbiguousTableNameException");
+ }
+ catch (AmbiguousTableNameException e)
+ {
+ }
+ }
}
Index: AbstractDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/AbstractDataSetTest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** AbstractDataSetTest.java 4 Jul 2002 21:33:42 -0000 1.12
--- AbstractDataSetTest.java 3 Aug 2002 02:26:41 -0000 1.13
***************
*** 23,26 ****
--- 23,28 ----
package org.dbunit.dataset;
+ import org.dbunit.database.AmbiguousTableNameException;
+
import java.util.*;
***************
*** 42,45 ****
--- 44,53 ----
};
+ private static final String[] DUPLICATE_TABLE_NAMES = {
+ "DUPLICATE_TABLE",
+ "EMPTY_TABLE",
+ "DUPLICATE_TABLE",
+ };
+
public AbstractDataSetTest(String s)
{
***************
*** 52,55 ****
--- 60,78 ----
}
+ protected String[] getExpectedDuplicateNames()
+ {
+ return (String[])DUPLICATE_TABLE_NAMES.clone();
+ }
+
+ protected int[] getExpectedDuplicateRows()
+ {
+ return new int[] {1, 0, 2};
+ }
+
+ protected String getDuplicateTableName()
+ {
+ return "DUPLICATE_TABLE";
+ }
+
/**
* This method exclude BLOB_TABLE and CLOB_TABLE from the specified dataset
***************
*** 74,77 ****
--- 97,102 ----
protected abstract IDataSet createDataSet() throws Exception;
+ protected abstract IDataSet createDuplicateDataSet() throws Exception;
+
/**
* Many tests in this class assume a known sequence of table. For some
***************
*** 176,179 ****
--- 201,286 ----
}
+ public void testGetTables() throws Exception
+ {
+ String[] expected = getExpectedNames();
+ sort(expected);
+
+ IDataSet dataSet = createDataSet();
+ ITable[] tables = dataSet.getTables();
+ sort(tables);
+
+ assertEquals("table count", expected.length, tables.length);
+ for (int i = 0; i < expected.length; i++)
+ {
+ assertEqualsTableName("name " + i, expected[i],
+ tables[i].getTableMetaData().getTableName());
+ }
+ }
+
+ public void testGetTablesDefensiveCopy() throws Exception
+ {
+ IDataSet dataSet = createDataSet();
+ assertTrue("Should not be same intance",
+ dataSet.getTables() != dataSet.getTables());
+ }
+
+ public void testGetDuplicateTables() throws Exception
+ {
+ String[] expectedNames = getExpectedDuplicateNames();
+ int[] expectedRows = getExpectedDuplicateRows();
+ assertEquals(expectedNames.length, expectedRows.length);
+
+ IDataSet dataSet = createDuplicateDataSet();
+ ITable[] tables = dataSet.getTables();
+
+ assertEquals("table count", expectedNames.length, tables.length);
+ for (int i = 0; i < expectedNames.length; i++)
+ {
+ ITable table = tables[i];
+ String name = table.getTableMetaData().getTableName();
+ assertEqualsTableName("name " + i, expectedNames[i], name);
+ assertEquals("row count", expectedRows[i], table.getRowCount());
+ }
+ }
+
+ public void testGetDuplicateTableNames() throws Exception
+ {
+ String[] expected = getExpectedDuplicateNames();
+
+ IDataSet dataSet = createDuplicateDataSet();
+ String[] names = dataSet.getTableNames();
+
+ assertEquals("table count", expected.length, names.length);
+ for (int i = 0; i < expected.length; i++)
+ {
+ assertEqualsTableName("name " + i, expected[i], names[i]);
+ }
+ }
+
+ public void testGetDuplicateTable() throws Exception
+ {
+ IDataSet dataSet = createDuplicateDataSet();
+ try
+ {
+ dataSet.getTable(getDuplicateTableName());
+ fail("Should throw AmbiguousTableNameException");
+ }
+ catch (AmbiguousTableNameException e)
+ {
+ }
+ }
+
+ public void testGetDuplicateTableMetaData() throws Exception
+ {
+ IDataSet dataSet = createDuplicateDataSet();
+ try
+ {
+ dataSet.getTableMetaData(getDuplicateTableName());
+ fail("Should throw AmbiguousTableNameException");
+ }
+ catch (AmbiguousTableNameException e)
+ {
+ }
+ }
}
Index: DefaultDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/DefaultDataSetTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** DefaultDataSetTest.java 13 Jun 2002 17:25:00 -0000 1.5
--- DefaultDataSetTest.java 3 Aug 2002 02:26:41 -0000 1.6
***************
*** 46,49 ****
--- 46,58 ----
return new DefaultDataSet(tables);
}
+
+ protected IDataSet createDuplicateDataSet() throws Exception
+ {
+ IDataSet dataSet = new XmlDataSet(
+ new FileInputStream("src/xml/xmlDataSetDuplicateTest.xml"));
+ ITable[] tables = DataSetUtils.getTables(dataSet);
+
+ return new DefaultDataSet(tables);
+ }
}
|