|
From: <mla...@us...> - 2003-02-15 05:42:46
|
Update of /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset
In directory sc8-pr-cvs1:/tmp/cvs-serv29584/dbunit/src/test/org/dbunit/dataset
Modified Files:
CompositeDataSetTest.java AllTests.java AbstractTableTest.java
AbstractDataSetTest.java DataSetUtilsTest.java
Added Files:
LowerCaseDataSetTest.java LowerCaseTableMetaDataTest.java
Log Message:
DbUnit is now case insensitive!!!
--- NEW FILE: LowerCaseDataSetTest.java ---
/*
* CaseInsensitiveDataSetTest.java Feb 14, 2003
*
* Copyright (c)2002 Manuel Laflamme. All Rights Reserved.
*
* This software is the proprietary information of Manuel Laflamme.
* Use is subject to license terms.
*
*/
package org.dbunit.dataset;
import org.dbunit.dataset.xml.XmlDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import java.io.FileInputStream;
import java.io.FileReader;
/**
* @author Manuel Laflamme
* @version $Revision: 1.1 $
*/
public class LowerCaseDataSetTest extends AbstractDataSetTest
{
public LowerCaseDataSetTest(String s)
{
super(s);
}
protected IDataSet createDataSet() throws Exception
{
return new LowerCaseDataSet(new FlatXmlDataSet(new FileReader(
"src/xml/flatXmlDataSetTest.xml")));
}
protected IDataSet createDuplicateDataSet() throws Exception
{
return new LowerCaseDataSet(new FlatXmlDataSet(new FileReader(
"src/xml/flatXmlDataSetDuplicateTest.xml")));
}
protected String[] getExpectedNames() throws Exception
{
return getExpectedLowerNames();
}
protected String[] getExpectedDuplicateNames()
{
String[] names = super.getExpectedDuplicateNames();
for (int i = 0; i < names.length; i++)
{
names[i] = names[i].toLowerCase();
}
return names;
}
}
--- NEW FILE: LowerCaseTableMetaDataTest.java ---
/*
* DefaultTableMetaDataTest.java Feb 17, 2002
*
* 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
* @version $Revision: 1.1 $
*/
public class LowerCaseTableMetaDataTest extends TestCase
{
public LowerCaseTableMetaDataTest(String s)
{
super(s);
}
public void testGetTableName() throws Exception
{
String original = "TABLE_NAME";
String expected = original.toLowerCase();
ITableMetaData metaData = new LowerCaseTableMetaData(
new DefaultTableMetaData(original, new Column[0]));
assertEquals("table name", expected, metaData.getTableName());
}
public void testGetColumns() throws Exception
{
Column[] columns = new Column[]{
new Column("NUMBER_COLUMN", DataType.NUMERIC, "qwerty", Column.NULLABLE),
new Column("STRING_COLUMN", DataType.VARCHAR, "toto", Column.NO_NULLS),
new Column("BOOLEAN_COLUMN", DataType.BOOLEAN),
};
ITableMetaData metaData = new LowerCaseTableMetaData(
"TABLE_NAME", columns);
Column[] lowerColumns = metaData.getColumns();
assertEquals("column count", columns.length, lowerColumns.length);
for (int i = 0; i < columns.length; i++)
{
Column column = columns[i];
Column lowerColumn = lowerColumns[i];
assertEquals("name", column.getColumnName().toLowerCase(),
lowerColumn.getColumnName());
assertTrue("name not equals",
!column.getColumnName().equals(lowerColumn.getColumnName()));
assertEquals("type", column.getDataType(), lowerColumn.getDataType());
assertEquals("sql type", column.getSqlTypeName(), lowerColumn.getSqlTypeName());
assertEquals("nullable", column.getNullable(), lowerColumn.getNullable());
}
assertEquals("key count", 0, metaData.getPrimaryKeys().length);
}
public void testGetPrimaryKeys() throws Exception
{
Column[] columns = new Column[]{
new Column("NUMBER_COLUMN", DataType.NUMERIC, "qwerty", Column.NULLABLE),
new Column("STRING_COLUMN", DataType.VARCHAR, "toto", Column.NO_NULLS),
new Column("BOOLEAN_COLUMN", DataType.BOOLEAN),
};
String[] keyNames = new String[]{"Boolean_Column", "Number_Column"};
ITableMetaData metaData = new LowerCaseTableMetaData(
"TABLE_NAME", columns, keyNames);
Column[] keys = metaData.getPrimaryKeys();
assertEquals("key count", keyNames.length, keys.length);
for (int i = 0; i < keys.length; i++)
{
assertTrue("name not equals",
!keyNames[i].equals(keys[i].getColumnName()));
assertEquals("key name", keyNames[i].toLowerCase(),
keys[i].getColumnName());
}
}
}
Index: CompositeDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/CompositeDataSetTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CompositeDataSetTest.java 14 Feb 2003 03:22:00 -0000 1.7
--- CompositeDataSetTest.java 15 Feb 2003 05:42:43 -0000 1.8
***************
*** 69,72 ****
--- 69,82 ----
return new CompositeDataSet(dataSet1, dataSet2, false);
}
+
+ public void testCombineTables() throws Exception
+ {
+ IDataSet originaldataSet = createMultipleCaseDuplicateDataSet();
+ assertEquals("table count before", 3, originaldataSet.getTableNames().length);
+
+ IDataSet combinedDataSet = new CompositeDataSet(originaldataSet.getTables());
+ assertEquals("table count combined", 2, combinedDataSet.getTableNames().length);
+ }
+
}
Index: AllTests.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/AllTests.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** AllTests.java 11 Dec 2002 15:57:34 -0000 1.8
--- AllTests.java 15 Feb 2003 05:42:43 -0000 1.9
***************
*** 47,50 ****
--- 47,52 ----
suite.addTest(new TestSuite(DefaultTableTest.class));
suite.addTest(new TestSuite(FilteredDataSetTest.class));
+ suite.addTest(new TestSuite(LowerCaseDataSetTest.class));
+ suite.addTest(new TestSuite(LowerCaseTableMetaDataTest.class));
suite.addTest(new TestSuite(QueryDataSetTest.class));
Index: AbstractTableTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/AbstractTableTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** AbstractTableTest.java 13 Jun 2002 17:25:00 -0000 1.8
--- AbstractTableTest.java 15 Feb 2003 05:42:43 -0000 1.9
***************
*** 81,84 ****
--- 81,99 ----
}
+ public void testGetValueCaseInsensitive() throws Exception
+ {
+ ITable table = createTable();
+ for (int i = 0; i < ROW_COUNT; i++)
+ {
+ for (int j = 0; j < COLUMN_COUNT; j++)
+ {
+ String columnName = "CoLUmN" + j;
+ String expected = "row " + i + " col " + j;
+ Object value = table.getValue(i, columnName);
+ assertEquals("value", expected, value);
+ }
+ }
+ }
+
public abstract void testGetMissingValue() throws Exception;
Index: AbstractDataSetTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/AbstractDataSetTest.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** AbstractDataSetTest.java 13 Feb 2003 04:32:42 -0000 1.17
--- AbstractDataSetTest.java 15 Feb 2003 05:42:43 -0000 1.18
***************
*** 24,28 ****
import org.dbunit.database.AmbiguousTableNameException;
- import org.dbunit.*;
import java.util.*;
--- 24,27 ----
***************
*** 58,67 ****
}
! protected static String[] getExpectedNames() throws Exception
{
return (String[])TABLE_NAMES.clone();
}
! protected static String[] getExpectedLowerNames() throws Exception
{
String[] names = (String[])TABLE_NAMES.clone();
--- 57,66 ----
}
! protected String[] getExpectedNames() throws Exception
{
return (String[])TABLE_NAMES.clone();
}
! protected String[] getExpectedLowerNames() throws Exception
{
String[] names = (String[])TABLE_NAMES.clone();
Index: DataSetUtilsTest.java
===================================================================
RCS file: /cvsroot/dbunit/dbunit/src/test/org/dbunit/dataset/DataSetUtilsTest.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** DataSetUtilsTest.java 4 Aug 2002 01:07:13 -0000 1.12
--- DataSetUtilsTest.java 15 Feb 2003 05:42:43 -0000 1.13
***************
*** 79,83 ****
}
-
public void testGetColumn() throws Exception
{
--- 79,82 ----
***************
*** 87,90 ****
--- 86,106 ----
new Column("c2", DataType.UNKNOWN),
new Column("c3", DataType.UNKNOWN),
+ new Column("c4", DataType.UNKNOWN),
+ };
+
+ for (int i = 0; i < columns.length; i++)
+ {
+ assertEquals("find column same", columns[i],
+ DataSetUtils.getColumn("c" + i, columns));
+ }
+ }
+
+ public void testGetColumnCaseInsensitive() throws Exception
+ {
+ Column[] columns = new Column[]{
+ new Column("c0", DataType.UNKNOWN),
+ new Column("C1", DataType.UNKNOWN),
+ new Column("c2", DataType.UNKNOWN),
+ new Column("C3", DataType.UNKNOWN),
new Column("c4", DataType.UNKNOWN),
};
|