|
From: <rlo...@us...> - 2008-09-13 00:35:52
|
Revision: 805
http://dbunit.svn.sourceforge.net/dbunit/?rev=805&view=rev
Author: rlogiacco
Date: 2008-09-13 00:35:49 +0000 (Sat, 13 Sep 2008)
Log Message:
-----------
updated web site
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/site/xdoc/index.xml
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-09-10 02:28:25 UTC (rev 804)
+++ trunk/src/changes/changes.xml 2008-09-13 00:35:49 UTC (rev 805)
@@ -7,7 +7,7 @@
</properties>
<body>
- <release version="2.3.0" date="Sep 09, 2008" description="Some API changes, features added, bugfixes, performance improvements in assertions. See migration guide for additional help">
+ <release version="2.3.0" date="Sep 11, 2008" description="Some API changes, features added, bugfixes, performance improvements in assertions. See migration guide for additional help">
<action dev="slecallonnec" type="fix" issue="1968640">Trimming is now done on Excel column names to prevent NoSuchColumnException.</action>
<action dev="rlogiacco" type="fix" issue="1981449" due-to="gommma">Patch for Bug #1421590 "Problem in data import if all the columns are not populated"</action>
<action dev="slecallonnec" type="fix" issue="1975499" due-to="gommma">NoSuchColumnException now thrown when column name does not exist.</action>
Modified: trunk/src/site/xdoc/index.xml
===================================================================
--- trunk/src/site/xdoc/index.xml 2008-09-10 02:28:25 UTC (rev 804)
+++ trunk/src/site/xdoc/index.xml 2008-09-13 00:35:49 UTC (rev 805)
@@ -26,6 +26,10 @@
<section name="News">
<table border="1">
<tr>
+ <td>2008-09-11</td>
+ <td>We all are so proud to announce the 2.3.0 release is finally out! Have a look at the <a href="changes-report.html#a2.3.0">changes</a>.</td>
+ </tr>
+ <tr>
<td>2008-06-08</td>
<td>Matthias Gommeringer joined the project team. Welcome Matthias!</td>
</tr>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fel...@us...> - 2008-09-22 05:05:41
|
Revision: 810
http://dbunit.svn.sourceforge.net/dbunit/?rev=810&view=rev
Author: felipeal
Date: 2008-09-22 05:05:35 +0000 (Mon, 22 Sep 2008)
Log Message:
-----------
2122413 - Added "constants" for DatabaseOperation wrappers
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/java/org/dbunit/operation/DatabaseOperation.java
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-09-18 11:12:25 UTC (rev 809)
+++ trunk/src/changes/changes.xml 2008-09-22 05:05:35 UTC (rev 810)
@@ -7,7 +7,8 @@
</properties>
<body>
- <release version="2.4.0" date="Nov 01, 2008" description="Some API changes, bugfixes">
+ <release version="2.3.1-SNAPSHOT" date="TBD" description="Some API changes, bugfixes">
+ <action dev="felipeal" type="add" issue="2122413">Added "constants" for DatabaseOperation wrappers</action>
<action dev="gommma" type="update">ISearchAlgorithm.search returns strongly typed ListOrderedSet instead of a normal Set so that TableDependencyHelper can return tables in correct order. API change.</action>
<action dev="gommma" type="fix" issue="1628105" due-to="ozonobon">XmlWriter can't write nested CDATA sections</action>
</release>
Modified: trunk/src/java/org/dbunit/operation/DatabaseOperation.java
===================================================================
--- trunk/src/java/org/dbunit/operation/DatabaseOperation.java 2008-09-18 11:12:25 UTC (rev 809)
+++ trunk/src/java/org/dbunit/operation/DatabaseOperation.java 2008-09-22 05:05:35 UTC (rev 810)
@@ -44,7 +44,13 @@
public static final DatabaseOperation DELETE_ALL = new DeleteAllOperation();
public static final DatabaseOperation TRUNCATE_TABLE = new TruncateTableOperation();
public static final DatabaseOperation CLEAN_INSERT = new CompositeOperation(
- DELETE_ALL, INSERT);
+ DELETE_ALL, INSERT);
+ public static final DatabaseOperation TRANSACTION(DatabaseOperation operation) {
+ return new TransactionOperation(operation);
+ }
+ public static final DatabaseOperation CLOSE_CONNECTION(DatabaseOperation operation) {
+ return new CloseConnectionOperation(operation);
+ }
/**
* Executes this operation on the specified database using the specified
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rlo...@us...> - 2009-09-20 14:59:39
|
Revision: 1039
http://dbunit.svn.sourceforge.net/dbunit/?rev=1039&view=rev
Author: rlogiacco
Date: 2009-09-20 14:59:30 +0000 (Sun, 20 Sep 2009)
Log Message:
-----------
changelog and front pages updated
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/site/xdoc/index.xml
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2009-09-20 14:55:56 UTC (rev 1038)
+++ trunk/src/changes/changes.xml 2009-09-20 14:59:30 UTC (rev 1039)
@@ -10,7 +10,9 @@
</properties>
<body>
- <release version="2.4.6-SNAPSHOT" date="TBD" description="(no description)">
+ <release version="2.4.7-SNAPSHOT" date="TBD" description="(no description)">
+ </release>
+ <release version="2.4.6" date="Sep 20, 2009" description="Bugfixes and some database specific additions">
<action dev="rlogiacco" type="add" issue="284432" due-to="JamesR">Add support for interval type on postgres</action>
<action dev="felipeal" type="update">Changed some verbose logging statements from INFO to DEBUG level</action>
<action dev="gommma" type="fix" issue="2797698" due-to="mkienenb">DefaultDataSet is incompatible w/ AbstractDataSet's IDataSet</action>
Modified: trunk/src/site/xdoc/index.xml
===================================================================
--- trunk/src/site/xdoc/index.xml 2009-09-20 14:55:56 UTC (rev 1038)
+++ trunk/src/site/xdoc/index.xml 2009-09-20 14:59:30 UTC (rev 1039)
@@ -26,6 +26,10 @@
<section name="News">
<table border="1">
<tr>
+ <td>2009-09-20</td>
+ <td>Your contributions has led us to cut a new release: DbUnit 2.4.5 is out. Here a detailed <a href="changes-report.html#a2.4.6">changes</a> report.</td>
+ </tr>
+ <tr>
<td>2009-05-23</td>
<td>Another bugfixing release has been cut: DbUnit 2.4.5 is out. Here a detailed <a href="changes-report.html#a2.4.5">changes</a> report.</td>
</tr>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fel...@us...> - 2008-10-26 21:57:04
|
Revision: 845
http://dbunit.svn.sourceforge.net/dbunit/?rev=845&view=rev
Author: felipeal
Date: 2008-10-26 21:57:00 +0000 (Sun, 26 Oct 2008)
Log Message:
-----------
2198914 - When comparing empty tables, column info should be ignored
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/java/org/dbunit/Assertion.java
trunk/src/test/org/dbunit/AssertionTest.java
Added Paths:
-----------
trunk/src/xml/assertionTest-empty1.xml
trunk/src/xml/assertionTest-empty2.xml
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-10-26 12:45:22 UTC (rev 844)
+++ trunk/src/changes/changes.xml 2008-10-26 21:57:00 UTC (rev 845)
@@ -8,6 +8,7 @@
<body>
<release version="2.4-SNAPSHOT" date="TBD" description="Some API changes, features added, bugfixes">
+ <action dev="felipeal" type="fix" issue="2198914">When comparing empty tables, column info should be ignored</action>
<action dev="felipeal" type="add" issue="2122413">Added "constants" for DatabaseOperation wrappers</action>
<action dev="gommma" type="update">ISearchAlgorithm.search returns strongly typed ListOrderedSet instead of a normal Set so that TableDependencyHelper can return tables in correct order. API change.</action>
<action dev="gommma" type="fix" issue="1628105" due-to="ozonobon">XmlWriter can't write nested CDATA sections</action>
Modified: trunk/src/java/org/dbunit/Assertion.java
===================================================================
--- trunk/src/java/org/dbunit/Assertion.java 2008-10-26 12:45:22 UTC (rev 844)
+++ trunk/src/java/org/dbunit/Assertion.java 2008-10-26 21:57:00 UTC (rev 845)
@@ -243,7 +243,24 @@
ITableMetaData expectedMetaData = expectedTable.getTableMetaData();
ITableMetaData actualMetaData = actualTable.getTableMetaData();
+ String expectedTableName = expectedMetaData.getTableName();
+ // Verify row count
+ int expectedRowsCount = expectedTable.getRowCount();
+ int actualRowsCount = actualTable.getRowCount();
+ if(expectedRowsCount != actualRowsCount)
+ {
+ throw new ComparisonFailure("row count (table=" + expectedTableName + ")",
+ String.valueOf(expectedRowsCount), String.valueOf(actualRowsCount) );
+ }
+ // if both tables are empty, it is not necessary to compare columns, as such comparison
+ // can fail if column metadata is different (which could occurs when comparing empty tables)
+ if (expectedRowsCount==0 && actualRowsCount==0)
+ {
+ logger.debug("Tables are empty, hence equals.");
+ return;
+ }
+
// Put the columns into the same order
Column[] expectedColumns = Columns.getSortedColumns(expectedMetaData);
Column[] actualColumns = Columns.getSortedColumns(actualMetaData);
@@ -257,14 +274,6 @@
Columns.getColumnNamesAsString(expectedColumns),
Columns.getColumnNamesAsString(actualColumns) );
}
-
- String expectedTableName = expectedMetaData.getTableName();
- // Verify row count
- if(expectedTable.getRowCount() != actualTable.getRowCount())
- {
- throw new ComparisonFailure("row count (table=" + expectedTableName + ")",
- String.valueOf(expectedTable.getRowCount()), String.valueOf(actualTable.getRowCount()) );
- }
// Get the datatypes to be used for comparing the sorted columns
ComparisonColumn[] comparisonCols = getComparisonColumns(expectedTableName, expectedColumns, actualColumns);
Modified: trunk/src/test/org/dbunit/AssertionTest.java
===================================================================
--- trunk/src/test/org/dbunit/AssertionTest.java 2008-10-26 12:45:22 UTC (rev 844)
+++ trunk/src/test/org/dbunit/AssertionTest.java 2008-10-26 21:57:00 UTC (rev 845)
@@ -41,6 +41,7 @@
import org.dbunit.dataset.ITableMetaData;
import org.dbunit.dataset.datatype.DataType;
import org.dbunit.dataset.xml.FlatXmlDataSet;
+import org.dbunit.dataset.xml.XmlDataSet;
import org.dbunit.operation.DatabaseOperation;
/**
@@ -71,6 +72,14 @@
dataSet.getTable("TEST_TABLE_WITH_SAME_VALUE"),
new Column[] {new Column("COLUMN0", DataType.VARCHAR)} );
}
+
+ public void testAssertTablesEmtpyEquals() throws Exception
+ {
+ IDataSet empty1 = new XmlDataSet(new FileReader("src/xml/assertionTest-empty1.xml"));
+ IDataSet empty2 = new FlatXmlDataSet(new FileReader("src/xml/assertionTest-empty2.xml"));
+ Assertion.assertEquals(empty1, empty2);
+ }
+
public void testAssertTablesEqualsColumnNamesCaseInsensitive() throws Exception
{
Added: trunk/src/xml/assertionTest-empty1.xml
===================================================================
--- trunk/src/xml/assertionTest-empty1.xml (rev 0)
+++ trunk/src/xml/assertionTest-empty1.xml 2008-10-26 21:57:00 UTC (rev 845)
@@ -0,0 +1,6 @@
+<dataset>
+ <table name="EMPTY_TABLE">
+ <column>A_COLUMN</column>
+ </table>
+</dataset>
+
Added: trunk/src/xml/assertionTest-empty2.xml
===================================================================
--- trunk/src/xml/assertionTest-empty2.xml (rev 0)
+++ trunk/src/xml/assertionTest-empty2.xml 2008-10-26 21:57:00 UTC (rev 845)
@@ -0,0 +1,6 @@
+<dataset>
+ <EMPTY_TABLE/>
+</dataset>
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fel...@us...> - 2008-11-07 19:48:22
|
Revision: 868
http://dbunit.svn.sourceforge.net/dbunit/?rev=868&view=rev
Author: felipeal
Date: 2008-11-07 19:48:16 +0000 (Fri, 07 Nov 2008)
Log Message:
-----------
2235876 - refactor Assertion, so now it relies on a DbUnitAssert class to do its job
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/java/org/dbunit/Assertion.java
trunk/src/test/org/dbunit/AssertionTest.java
Added Paths:
-----------
trunk/src/java/org/dbunit/assertion/DbUnitAssert.java
trunk/src/java/org/dbunit/assertion/DefaultDbUnitAssert.java
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-11-07 17:35:28 UTC (rev 867)
+++ trunk/src/changes/changes.xml 2008-11-07 19:48:16 UTC (rev 868)
@@ -8,6 +8,7 @@
<body>
<release version="2.4-SNAPSHOT" date="TBD" description="Some API changes, features added, bugfixes">
+ <action dev="felipeal" type="add" issue="2235876">Refactor Assertion class</action>
<action dev="felipeal" type="fix" issue="2198914">When comparing empty tables, column info should be ignored</action>
<action dev="felipeal" type="add" issue="2122413">Added "constants" for DatabaseOperation wrappers</action>
<action dev="gommma" type="update">ISearchAlgorithm.search returns strongly typed ListOrderedSet instead of a normal Set so that TableDependencyHelper can return tables in correct order. API change.</action>
Modified: trunk/src/java/org/dbunit/Assertion.java
===================================================================
--- trunk/src/java/org/dbunit/Assertion.java 2008-11-07 17:35:28 UTC (rev 867)
+++ trunk/src/java/org/dbunit/Assertion.java 2008-11-07 19:48:16 UTC (rev 868)
@@ -22,562 +22,239 @@
package org.dbunit;
import java.sql.SQLException;
-import java.util.Arrays;
+import org.dbunit.assertion.DbUnitAssert;
+import org.dbunit.assertion.DefaultDbUnitAssert;
import org.dbunit.assertion.FailureHandler;
-import org.dbunit.assertion.JUnitFailureHandler;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.Column;
-import org.dbunit.dataset.Columns;
-import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
-import org.dbunit.dataset.ITableMetaData;
-import org.dbunit.dataset.datatype.DataType;
-import org.dbunit.dataset.datatype.UnknownDataType;
-import org.dbunit.dataset.filter.DefaultColumnFilter;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
- * Provides assertions for the most common dbunit test cases.
+ * Provides static methods for the most common DbUnit assertion needs.
*
+ * Although the methods are static, they rely on a DbUnitAssert instance to do
+ * the work. So, if you need to customize this class behavior, you can create
+ * your own DbUnitAssert (typically extending DefaultDbUnitAssert), override the
+ * desired methods, then call setInstance() with the new object.
+ *
* @author Manuel Laflamme
+ * @author Felipe Leme <db...@fe...>
* @version $Revision$
* @since Mar 22, 2002
*/
-public class Assertion
-{
+public class Assertion {
- /**
- * Logger for this class
- */
- private static final Logger logger = LoggerFactory.getLogger(Assertion.class);
-
+ /**
+ * Object that will effectively do the assertions.
+ */
+ private static DbUnitAssert instance = new DefaultDbUnitAssert();
- private Assertion()
- {
- }
+ private Assertion() {
+ throw new UnsupportedOperationException(
+ "this class has only static methods");
+ }
- /**
- * Compare one table present in two datasets ignoring specified columns.
- *
- * @param expectedDataset First dataset.
- * @param actualDataset Second dataset.
- * @param tableName Table name of the table to be compared.
- * @param ignoreCols Columns to be ignored in comparison.
- * @throws org.dbunit.DatabaseUnitException If an error occurs.
- */
- public static void assertEqualsIgnoreCols(final IDataSet expectedDataset, final IDataSet actualDataset,
- final String tableName, final String[] ignoreCols) throws DatabaseUnitException
- {
- if(logger.isDebugEnabled())
- logger.debug("assertEqualsIgnoreCols(expectedDataset={}, actualDataset={}, tableName={}, ignoreCols={}) - start",
- new Object[] {expectedDataset, actualDataset, tableName, Arrays.asList(ignoreCols)} );
-
- Assertion.assertEqualsIgnoreCols(
- expectedDataset.getTable(tableName),
- actualDataset.getTable(tableName),
- ignoreCols);
- }
-
- /**
- * Compare the given tables ignoring specified columns.
- *
- * @param expectedTable First table.
- * @param actualTable Second table.
- * @param ignoreCols Columns to be ignored in comparison.
- * @throws org.dbunit.DatabaseUnitException If an error occurs.
- */
- public static void assertEqualsIgnoreCols(final ITable expectedTable, final ITable actualTable,
- final String[] ignoreCols) throws DatabaseUnitException
- {
- if(logger.isDebugEnabled())
- logger.debug("assertEqualsIgnoreCols(expectedTable={}, actualTable={}, ignoreCols={}) - start",
- new Object[] {expectedTable, actualTable, Arrays.asList(ignoreCols)} );
-
- final ITable expectedTableFiltered = DefaultColumnFilter.excludedColumnsTable(expectedTable, ignoreCols);
- final ITable actualTableFiltered = DefaultColumnFilter.excludedColumnsTable(actualTable, ignoreCols);
- Assertion.assertEquals(expectedTableFiltered, actualTableFiltered);
- }
-
- /**
- * Compare a table from a dataset with a table generated from an sql query.
- *
- * @param expectedDataset Dataset to retrieve the first table from.
- * @param connection Connection to use for the SQL statement.
- * @param sqlQuery SQL query that will build the data in returned second table rows.
- * @param tableName Table name of the table to compare
- * @param ignoreCols Columns to be ignored in comparison.
- * @throws DatabaseUnitException If an error occurs while performing the comparison.
- * @throws java.sql.SQLException If an SQL error occurs.
- */
- public static void assertEqualsByQuery(final IDataSet expectedDataset,
- final IDatabaseConnection connection, final String sqlQuery,
- final String tableName, final String[] ignoreCols)
- throws DatabaseUnitException, SQLException
- {
- if(logger.isDebugEnabled())
- logger.debug("assertEqualsByQuery(expectedDataset={}, connection={}, tableName={}, sqlQuery={}, ignoreCols={}) - start",
- new Object[] {expectedDataset, connection, tableName, sqlQuery, ignoreCols} );
-
- ITable expectedTable = expectedDataset.getTable(tableName);
- Assertion.assertEqualsByQuery(expectedTable, connection, tableName, sqlQuery, ignoreCols);
+ /**
+ * This method can be used to customize the behavior of the static methods, as
+ * they will delegate the work to this instance.
+ *
+ * @param instance
+ * new instance to be used by static methods.
+ */
+ public static void setInstance(DbUnitAssert instance) {
+ if (instance == null) {
+ throw new IllegalArgumentException("instance cannot be null");
}
-
- /**
- * Compare a table with a table generated from an sql query.
- *
- * @param expectedTable Table containing all expected results.
- * @param connection Connection to use for the SQL statement.
- * @param tableName The name of the table to query from the database
- * @param sqlQuery SQL query that will build the data in returned second table rows.
- * @param ignoreCols Columns to be ignored in comparison.
- * @throws DatabaseUnitException If an error occurs while performing the comparison.
- * @throws java.sql.SQLException If an SQL error occurs.
- */
- public static void assertEqualsByQuery(final ITable expectedTable,
- final IDatabaseConnection connection, final String tableName, final String sqlQuery,
- final String[] ignoreCols)
- throws DatabaseUnitException, SQLException
- {
- if(logger.isDebugEnabled())
- logger.debug("assertEqualsByQuery(expectedTable={}, connection={}, tableName={}, sqlQuery={}, ignoreCols={}) - start",
- new Object[] {expectedTable, connection, tableName, sqlQuery, ignoreCols} );
+ Assertion.instance = instance;
+ }
- ITable expected = DefaultColumnFilter.excludedColumnsTable(expectedTable, ignoreCols);
- ITable queriedTable = connection.createQueryTable(tableName, sqlQuery);
- ITable actual = DefaultColumnFilter.excludedColumnsTable(queriedTable, ignoreCols);
- Assertion.assertEquals(expected, actual);
- }
-
- /**
- * Asserts that the two specified dataset are equals. This method ignore
- * the tables order.
- */
- public static void assertEquals(IDataSet expectedDataSet,
- IDataSet actualDataSet) throws DatabaseUnitException
- {
- logger.debug("assertEquals(expectedDataSet={}, actualDataSet={}) - start", expectedDataSet, actualDataSet);
- assertEquals(expectedDataSet, actualDataSet, null);
- }
-
- /**
- * Asserts that the two specified dataset are equals. This method ignore
- * the tables order.
- * @since 2.4
- */
- public static void assertEquals(IDataSet expectedDataSet,
- IDataSet actualDataSet, FailureHandler failureHandler) throws DatabaseUnitException
- {
- if(logger.isDebugEnabled())
- logger.debug("assertEquals(expectedDataSet={}, actualDataSet={}, failureHandler={}) - start",
- new Object[] {expectedDataSet, actualDataSet, failureHandler} );
+ /**
+ * Compare one table present in two datasets ignoring specified columns.
+ *
+ * @param expectedDataset
+ * First dataset.
+ * @param actualDataset
+ * Second dataset.
+ * @param tableName
+ * Table name of the table to be compared.
+ * @param ignoreCols
+ * Columns to be ignored in comparison.
+ * @throws org.dbunit.DatabaseUnitException
+ * If an error occurs.
+ */
+ public static void assertEqualsIgnoreCols(final IDataSet expectedDataset,
+ final IDataSet actualDataset, final String tableName,
+ final String[] ignoreCols) throws DatabaseUnitException {
+ instance.assertEqualsIgnoreCols(expectedDataset, actualDataset, tableName,
+ ignoreCols);
+ }
- // do not continue if same instance
- if (expectedDataSet == actualDataSet)
- {
- return;
- }
+ /**
+ * Compare the given tables ignoring specified columns.
+ *
+ * @param expectedTable
+ * First table.
+ * @param actualTable
+ * Second table.
+ * @param ignoreCols
+ * Columns to be ignored in comparison.
+ * @throws org.dbunit.DatabaseUnitException
+ * If an error occurs.
+ */
+ public static void assertEqualsIgnoreCols(final ITable expectedTable,
+ final ITable actualTable, final String[] ignoreCols)
+ throws DatabaseUnitException {
+ instance.assertEqualsIgnoreCols(expectedTable, actualTable, ignoreCols);
+ }
- if(failureHandler == null)
- {
- logger.debug("FailureHandler is null. Using default implementation");
- failureHandler = getDefaultFailureHandler();
- }
+ /**
+ * Compare a table from a dataset with a table generated from an sql query.
+ *
+ * @param expectedDataset
+ * Dataset to retrieve the first table from.
+ * @param connection
+ * Connection to use for the SQL statement.
+ * @param sqlQuery
+ * SQL query that will build the data in returned second table rows.
+ * @param tableName
+ * Table name of the table to compare
+ * @param ignoreCols
+ * Columns to be ignored in comparison.
+ * @throws DatabaseUnitException
+ * If an error occurs while performing the comparison.
+ * @throws java.sql.SQLException
+ * If an SQL error occurs.
+ */
+ public static void assertEqualsByQuery(final IDataSet expectedDataset,
+ final IDatabaseConnection connection, final String sqlQuery,
+ final String tableName, final String[] ignoreCols)
+ throws DatabaseUnitException, SQLException {
+ instance.assertEqualsByQuery(expectedDataset, connection, sqlQuery,
+ tableName, ignoreCols);
+ }
- String[] expectedNames = getSortedUpperTableNames(expectedDataSet);
- String[] actualNames = getSortedUpperTableNames(actualDataSet);
+ /**
+ * Compare a table with a table generated from an sql query.
+ *
+ * @param expectedTable
+ * Table containing all expected results.
+ * @param connection
+ * Connection to use for the SQL statement.
+ * @param tableName
+ * The name of the table to query from the database
+ * @param sqlQuery
+ * SQL query that will build the data in returned second table rows.
+ * @param ignoreCols
+ * Columns to be ignored in comparison.
+ * @throws DatabaseUnitException
+ * If an error occurs while performing the comparison.
+ * @throws java.sql.SQLException
+ * If an SQL error occurs.
+ */
+ public static void assertEqualsByQuery(final ITable expectedTable,
+ final IDatabaseConnection connection, final String tableName,
+ final String sqlQuery, final String[] ignoreCols)
+ throws DatabaseUnitException, SQLException {
+ instance.assertEqualsByQuery(expectedTable, connection, tableName,
+ sqlQuery, ignoreCols);
+ }
- // tables count
- if(expectedNames.length != actualNames.length)
- {
- throw failureHandler.createFailure("table count", String.valueOf(expectedNames.length), String.valueOf(actualNames.length) );
- }
+ /**
+ * Asserts that the two specified dataset are equals. This method ignore the
+ * tables order.
+ */
+ public static void assertEquals(IDataSet expectedDataSet,
+ IDataSet actualDataSet) throws DatabaseUnitException {
+ instance.assertEquals(expectedDataSet, actualDataSet);
+ }
- // table names in no specific order
- for (int i = 0; i < expectedNames.length; i++)
- {
- if (!actualNames[i].equals(expectedNames[i]))
- {
- throw failureHandler.createFailure("tables", Arrays.asList(expectedNames).toString(), Arrays.asList(actualNames).toString());
- }
+ /**
+ * Asserts that the two specified dataset are equals. This method ignore the
+ * tables order.
+ *
+ * @since 2.4
+ */
+ public static void assertEquals(IDataSet expectedDataSet,
+ IDataSet actualDataSet, FailureHandler failureHandler)
+ throws DatabaseUnitException {
+ instance.assertEquals(expectedDataSet, actualDataSet, failureHandler);
+ }
- }
+ /**
+ * Asserts that the two specified tables are equals. This method ignores the
+ * table names, the columns order, the columns data type and which columns are
+ * composing the primary keys.
+ *
+ * @param expectedTable
+ * Table containing all expected results.
+ * @param actualTable
+ * Table containing all actual results.
+ * @throws DatabaseUnitException
+ */
+ public static void assertEquals(ITable expectedTable, ITable actualTable)
+ throws DatabaseUnitException {
+ instance.assertEquals(expectedTable, actualTable);
+ }
- // tables
- for (int i = 0; i < expectedNames.length; i++)
- {
- String name = expectedNames[i];
- assertEquals(expectedDataSet.getTable(name),
- actualDataSet.getTable(name));
- }
+ /**
+ * Asserts that the two specified tables are equals. This method ignores the
+ * table names, the columns order, the columns data type and which columns are
+ * composing the primary keys. <br />
+ * Example: <code><pre>
+ * ITable actualTable = ...;
+ * ITable expectedTable = ...;
+ * ITableMetaData metaData = actualTable.getTableMetaData();
+ * Column[] additionalInfoCols = Columns.getColumns(new String[] {"MY_PK_COLUMN"}, metaData.getColumns());
+ * Assertion.assertEquals(expectedTable, actualTable, additionalInfoCols);
+ * </pre></code>
+ *
+ * @param expectedTable
+ * Table containing all expected results.
+ * @param actualTable
+ * Table containing all actual results.
+ * @param additionalColumnInfo
+ * The columns to be printed out if the assert fails because of a
+ * data mismatch. Provides some additional column values that may be
+ * useful to quickly identify the columns for which the mismatch
+ * occurred (for example a primary key column). Can be
+ * <code>null</code>
+ * @throws DatabaseUnitException
+ */
+ public static void assertEquals(ITable expectedTable, ITable actualTable,
+ Column[] additionalColumnInfo) throws DatabaseUnitException {
+ instance.assertEquals(expectedTable, actualTable, additionalColumnInfo);
+ }
- }
+ /**
+ * Asserts that the two specified tables are equals. This method ignores the
+ * table names, the columns order, the columns data type and which columns are
+ * composing the primary keys. <br />
+ * Example: <code><pre>
+ * ITable actualTable = ...;
+ * ITable expectedTable = ...;
+ * ITableMetaData metaData = actualTable.getTableMetaData();
+ * Column[] additionalInfoCols = Columns.getColumns(new String[] {"MY_PK_COLUMN"}, metaData.getColumns());
+ * Assertion.assertEquals(expectedTable, actualTable, additionalInfoCols);
+ * </pre></code>
+ *
+ * @param expectedTable
+ * Table containing all expected results.
+ * @param actualTable
+ * Table containing all actual results.
+ * @param failureHandler
+ * The failure handler used if the assert fails because of a data
+ * mismatch. Provides some additional information that may be useful
+ * to quickly identify the rows for which the mismatch occurred (for
+ * example by printing an additional primary key column). Can be
+ * <code>null</code>
+ * @throws DatabaseUnitException
+ * @since 2.4
+ */
+ public static void assertEquals(ITable expectedTable, ITable actualTable,
+ FailureHandler failureHandler) throws DatabaseUnitException {
+ instance.assertEquals(expectedTable, actualTable, failureHandler);
+ }
-
- /**
- * Asserts that the two specified tables are equals. This method ignores the
- * table names, the columns order, the columns data type and which columns
- * are composing the primary keys.
- * @param expectedTable Table containing all expected results.
- * @param actualTable Table containing all actual results.
- * @throws DatabaseUnitException
- */
- public static void assertEquals(ITable expectedTable, ITable actualTable)
- throws DatabaseUnitException
- {
- logger.debug("assertEquals(expectedTable={}, actualTable={}) - start", expectedTable, actualTable);
- assertEquals(expectedTable, actualTable, (Column[])null);
- }
-
- /**
- * Asserts that the two specified tables are equals. This method ignores the
- * table names, the columns order, the columns data type and which columns
- * are composing the primary keys.
- * <br />
- * Example:
- * <code><pre>
- * ITable actualTable = ...;
- * ITable expectedTable = ...;
- * ITableMetaData metaData = actualTable.getTableMetaData();
- * Column[] additionalInfoCols = Columns.getColumns(new String[] {"MY_PK_COLUMN"}, metaData.getColumns());
- * Assertion.assertEquals(expectedTable, actualTable, additionalInfoCols);
- * </pre></code>
- * @param expectedTable Table containing all expected results.
- * @param actualTable Table containing all actual results.
- * @param additionalColumnInfo The columns to be printed out if the assert fails because of a data mismatch.
- * Provides some additional column values that may be useful to quickly identify the columns for which the mismatch
- * occurred (for example a primary key column). Can be <code>null</code>
- * @throws DatabaseUnitException
- */
- public static void assertEquals(ITable expectedTable, ITable actualTable, Column[] additionalColumnInfo)
- throws DatabaseUnitException
- {
- logger.debug("assertEquals(expectedTable={}, actualTable={}, additionalColumnInfo={}) - start",
- new Object[] {expectedTable, actualTable, additionalColumnInfo} );
-
- FailureHandler failureHandler = null;
- if(additionalColumnInfo != null)
- failureHandler = getDefaultFailureHandler(additionalColumnInfo);
-
- Assertion.assertEquals(expectedTable, actualTable, failureHandler);
- }
-
-
- /**
- * Asserts that the two specified tables are equals. This method ignores the
- * table names, the columns order, the columns data type and which columns
- * are composing the primary keys.
- * <br />
- * Example:
- * <code><pre>
- * ITable actualTable = ...;
- * ITable expectedTable = ...;
- * ITableMetaData metaData = actualTable.getTableMetaData();
- * Column[] additionalInfoCols = Columns.getColumns(new String[] {"MY_PK_COLUMN"}, metaData.getColumns());
- * Assertion.assertEquals(expectedTable, actualTable, additionalInfoCols);
- * </pre></code>
- * @param expectedTable Table containing all expected results.
- * @param actualTable Table containing all actual results.
- * @param failureHandler The failure handler used if the assert fails because of a data mismatch.
- * Provides some additional information that may be useful to quickly identify the rows for which the mismatch
- * occurred (for example by printing an additional primary key column). Can be <code>null</code>
- * @throws DatabaseUnitException
- * @since 2.4
- */
- public static void assertEquals(ITable expectedTable, ITable actualTable, FailureHandler failureHandler)
- throws DatabaseUnitException
- {
- logger.debug("assertEquals(expectedTable={}, actualTable={}, failureHandler={}) - start",
- new Object[] {expectedTable, actualTable, failureHandler} );
-
- // Do not continue if same instance
- if (expectedTable == actualTable)
- {
- logger.debug("The given tables reference the same object. Will return immediately. (Table={})", expectedTable);
- return;
- }
-
- if(failureHandler == null)
- {
- logger.debug("FailureHandler is null. Using default implementation");
- failureHandler = getDefaultFailureHandler();
- }
-
-
- ITableMetaData expectedMetaData = expectedTable.getTableMetaData();
- ITableMetaData actualMetaData = actualTable.getTableMetaData();
- String expectedTableName = expectedMetaData.getTableName();
-
- // Verify row count
- int expectedRowsCount = expectedTable.getRowCount();
- int actualRowsCount = actualTable.getRowCount();
- if(expectedRowsCount != actualRowsCount)
- {
- String msg = "row count (table=" + expectedTableName + ")";
- throw failureHandler.createFailure(msg, String.valueOf(expectedRowsCount), String.valueOf(actualRowsCount));
- }
- // if both tables are empty, it is not necessary to compare columns, as such comparison
- // can fail if column metadata is different (which could occurs when comparing empty tables)
- if (expectedRowsCount==0 && actualRowsCount==0)
- {
- logger.debug("Tables are empty, hence equals.");
- return;
- }
-
- // Put the columns into the same order
- Column[] expectedColumns = Columns.getSortedColumns(expectedMetaData);
- Column[] actualColumns = Columns.getSortedColumns(actualMetaData);
-
- // Verify columns
- Columns.ColumnDiff columnDiff = Columns.getColumnDiff(expectedMetaData, actualMetaData);
- if(columnDiff.hasDifference())
- {
- String message = columnDiff.getMessage();
- throw failureHandler.createFailure(
- message,
- Columns.getColumnNamesAsString(expectedColumns),
- Columns.getColumnNamesAsString(actualColumns) );
- }
-
- // Get the datatypes to be used for comparing the sorted columns
- ComparisonColumn[] comparisonCols = getComparisonColumns(
- expectedTableName, expectedColumns, actualColumns, failureHandler);
-
- // Finally compare the data
- compareData(expectedTable, actualTable, comparisonCols, failureHandler);
- }
-
-
- /**
- * @return The default failure handler
- * @since 2.4
- */
- private static FailureHandler getDefaultFailureHandler()
- {
- // For backwards compatibility use the JUnitFailureHandler by default
- return getDefaultFailureHandler(null);
- }
-
- /**
- * @return The default failure handler
- * @since 2.4
- */
- private static FailureHandler getDefaultFailureHandler(
- Column[] additionalColumnInfo)
- {
- // For backwards compatibility use the JUnitFailureHandler by default
- return new JUnitFailureHandler(additionalColumnInfo);
- }
-
- /**
- * @param expectedTable Table containing all expected results.
- * @param actualTable Table containing all actual results.
- * @param comparisonCols The columns to be compared, also including the correct {@link DataType}s for comparison
- * @param failureHandler The failure handler used if the assert fails because of a data mismatch.
- * Provides some additional information that may be useful to quickly identify the rows for which the mismatch
- * occurred (for example by printing an additional primary key column). Must not be <code>null</code> at this stage
- * @throws DataSetException
- * @since 2.4
- */
- private static void compareData(ITable expectedTable, ITable actualTable,
- ComparisonColumn[] comparisonCols, FailureHandler failureHandler)
- throws DataSetException
- {
- logger.debug("assertEquals(expectedTable={}, actualTable={}, " +
- "comparisonCols={}, failureHandler={}) - start",
- new Object[] {expectedTable, actualTable, comparisonCols, failureHandler} );
-
- if (expectedTable == null) {
- throw new NullPointerException(
- "The parameter 'expectedTable' must not be null");
- }
- if (actualTable == null) {
- throw new NullPointerException(
- "The parameter 'actualTable' must not be null");
- }
- if (comparisonCols == null) {
- throw new NullPointerException(
- "The parameter 'comparisonCols' must not be null");
- }
- if (failureHandler == null) {
- throw new NullPointerException(
- "The parameter 'failureHandler' must not be null");
- }
-
-
- // values as strings
- for (int i = 0; i < expectedTable.getRowCount(); i++)
- {
- for (int j = 0; j < comparisonCols.length; j++)
- {
- ComparisonColumn compareColumn = comparisonCols[j];
-
- String columnName = compareColumn.getColumnName();
- DataType dataType = compareColumn.getDataType();
-
- Object expectedValue = expectedTable.getValue(i, columnName);
- Object actualValue = actualTable.getValue(i, columnName);
-
- if (dataType.compare(expectedValue, actualValue) != 0)
- {
- String additionalInfo = failureHandler.getAdditionalInfo(expectedTable, actualTable, i, columnName);
-
- String expectedTableName = expectedTable.getTableMetaData().getTableName();
- // example message: "value (table=MYTAB, row=232, column=MYCOL, Additional row info: (column=MyIdCol, expected=444, actual=555)): expected:<123> but was:<1234>"
- String msg = "value (table=" + expectedTableName + ", row=" + i + ", col=" + columnName;
- if(additionalInfo!=null && !additionalInfo.trim().equals(""))
- msg += ", " + additionalInfo;
- msg += ")";
- throw failureHandler.createFailure(msg, String.valueOf(expectedValue), String.valueOf(actualValue));
- }
-
- }
- }
-
- }
-
-
- /**
- * @param expectedTableName
- * @param expectedColumns
- * @param actualColumns
- * @param failureHandler The {@link FailureHandler} to be used when no datatype
- * can be determined
- * @return The columns to be used for the assertion, including the correct datatype
- * @since 2.4
- */
- private static ComparisonColumn[] getComparisonColumns(String expectedTableName,
- Column[] expectedColumns, Column[] actualColumns, FailureHandler failureHandler)
- {
- ComparisonColumn[] result = new ComparisonColumn[expectedColumns.length];
-
- for (int j = 0; j < expectedColumns.length; j++)
- {
- Column expectedColumn = expectedColumns[j];
- Column actualColumn = actualColumns[j];
- result[j] = new ComparisonColumn(expectedTableName, expectedColumn, actualColumn, failureHandler);
- }
- return result;
- }
-
-
- private static String[] getSortedUpperTableNames(IDataSet dataSet)
- throws DataSetException
- {
- logger.debug("getSortedUpperTableNames(dataSet={}) - start", dataSet);
-
- String[] names = dataSet.getTableNames();
- for (int i = 0; i < names.length; i++)
- {
- names[i] = names[i].toUpperCase();
- }
- Arrays.sort(names);
- return names;
- }
-
- /**
- * Represents a single column to be used...
[truncated message content] |
|
From: <rlo...@us...> - 2008-11-27 19:37:10
|
Revision: 888
http://dbunit.svn.sourceforge.net/dbunit/?rev=888&view=rev
Author: rlogiacco
Date: 2008-11-27 19:37:05 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
committing release related updates
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/site/xdoc/index.xml
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-11-24 19:45:28 UTC (rev 887)
+++ trunk/src/changes/changes.xml 2008-11-27 19:37:05 UTC (rev 888)
@@ -7,7 +7,7 @@
</properties>
<body>
- <release version="2.4-SNAPSHOT" date="TBD" description="Some API changes, features added, bugfixes">
+ <release version="2.4.0" date="Nov 27, 2008" description="Some API changes, features added, bugfixes">
<action dev="felipeal" type="add" issue="2235876">Refactor Assertion class</action>
<action dev="felipeal" type="fix" issue="2198914">When comparing empty tables, column info should be ignored</action>
<action dev="felipeal" type="add" issue="2122413">Added "constants" for DatabaseOperation wrappers</action>
Modified: trunk/src/site/xdoc/index.xml
===================================================================
--- trunk/src/site/xdoc/index.xml 2008-11-24 19:45:28 UTC (rev 887)
+++ trunk/src/site/xdoc/index.xml 2008-11-27 19:37:05 UTC (rev 888)
@@ -26,6 +26,10 @@
<section name="News">
<table border="1">
<tr>
+ <td>2008-11-27</td>
+ <td>DbUnit development is very active and is proud to announce the 2.4.0 release! Here the <a href="changes-report.html#a2.4.0">changes</a>.</td>
+ </tr>
+ <tr>
<td>2008-09-11</td>
<td>We all are so proud to announce the 2.3.0 release is finally out! Have a look at the <a href="changes-report.html#a2.3.0">changes</a>.</td>
</tr>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rlo...@us...> - 2008-12-08 21:15:57
|
Revision: 919
http://dbunit.svn.sourceforge.net/dbunit/?rev=919&view=rev
Author: rlogiacco
Date: 2008-12-08 21:15:54 +0000 (Mon, 08 Dec 2008)
Log Message:
-----------
preparing for next release
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/site/xdoc/index.xml
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-12-08 20:41:02 UTC (rev 918)
+++ trunk/src/changes/changes.xml 2008-12-08 21:15:54 UTC (rev 919)
@@ -8,7 +8,7 @@
</properties>
<body>
- <release version="2.4.2" date="TBD" description="Bugfixes, some small additions">
+ <release version="2.4.2" date="Dec 08, 2008" description="Bugfixes, some small additions">
<action dev="gommma" type="fix" issue="2356800" due-to="jeremy_finney">Cannot extract contents of table with a column named "AS"</action>
<action dev="gommma" type="fix" issue="2382766" due-to="dacota">MySQL case sensitive problem in dataset creation</action>
<action dev="gommma" type="add" issue="2390557" due-to="gommma">Add StringIgnoreCase DataType</action>
Modified: trunk/src/site/xdoc/index.xml
===================================================================
--- trunk/src/site/xdoc/index.xml 2008-12-08 20:41:02 UTC (rev 918)
+++ trunk/src/site/xdoc/index.xml 2008-12-08 21:15:54 UTC (rev 919)
@@ -26,6 +26,10 @@
<section name="News">
<table border="1">
<tr>
+ <td>2008-12-08</td>
+ <td>Some other fixes and a additions have been released. Here a detailed <a href="changes-report.html#a2.4.2">changes</a> report.</td>
+ </tr>
+ <tr>
<td>2008-12-03</td>
<td>Previous version introduced a bug on Oracle-based tests, so we are proud to announce a quick new version (2.4.1) that fixes it. More information in the <a href="changes-report.html#a2.4.1">changes</a>.</td>
</tr>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rlo...@us...> - 2008-12-21 11:26:17
|
Revision: 925
http://dbunit.svn.sourceforge.net/dbunit/?rev=925&view=rev
Author: rlogiacco
Date: 2008-12-21 11:26:11 +0000 (Sun, 21 Dec 2008)
Log Message:
-----------
updated site upon release
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/site/xdoc/index.xml
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2008-12-17 22:01:38 UTC (rev 924)
+++ trunk/src/changes/changes.xml 2008-12-21 11:26:11 UTC (rev 925)
@@ -8,7 +8,7 @@
</properties>
<body>
- <release version="2.4.2" date="Dec 08, 2008" description="Bugfixes, some small additions">
+ <release version="2.4.2" date="Dec 17, 2008" description="Bugfixes, some small additions">
<action dev="gommma" type="fix" issue="2356800" due-to="jeremy_finney">Cannot extract contents of table with a column named "AS"</action>
<action dev="gommma" type="fix" issue="2382766" due-to="dacota">MySQL case sensitive problem in dataset creation</action>
<action dev="gommma" type="add" issue="2390557" due-to="gommma">Add StringIgnoreCase DataType</action>
Modified: trunk/src/site/xdoc/index.xml
===================================================================
--- trunk/src/site/xdoc/index.xml 2008-12-17 22:01:38 UTC (rev 924)
+++ trunk/src/site/xdoc/index.xml 2008-12-21 11:26:11 UTC (rev 925)
@@ -26,10 +26,14 @@
<section name="News">
<table border="1">
<tr>
- <td>2008-12-08</td>
+ <td>2008-12-17</td>
<td>Some other fixes and a additions have been released. Here a detailed <a href="changes-report.html#a2.4.2">changes</a> report.</td>
</tr>
<tr>
+ <td>2008-12-15</td>
+ <td>Another Open Source project named <a href="http://jailer.sourceforge.net">Jailer</a> has added support for the DbUnit flat XML dataset file format. The integration provided by the Jailer project allows easy data sharing between the two projects. Well done Ralf!</td>
+ </tr>
+ <tr>
<td>2008-12-03</td>
<td>Previous version introduced a bug on Oracle-based tests, so we are proud to announce a quick new version (2.4.1) that fixes it. More information in the <a href="changes-report.html#a2.4.1">changes</a>.</td>
</tr>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <rlo...@us...> - 2009-08-25 16:58:47
|
Revision: 1028
http://dbunit.svn.sourceforge.net/dbunit/?rev=1028&view=rev
Author: rlogiacco
Date: 2009-08-25 16:58:33 +0000 (Tue, 25 Aug 2009)
Log Message:
-----------
[284432] Add support for interval type on postgres
Submitted by: JamesR
Modified Paths:
--------------
trunk/src/changes/changes.xml
trunk/src/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java
trunk/src/test/org/dbunit/ext/postgresql/PostgresqlDataTypeFactoryTest.java
Added Paths:
-----------
trunk/src/java/org/dbunit/ext/postgresql/IntervalType.java
Modified: trunk/src/changes/changes.xml
===================================================================
--- trunk/src/changes/changes.xml 2009-08-19 20:07:23 UTC (rev 1027)
+++ trunk/src/changes/changes.xml 2009-08-25 16:58:33 UTC (rev 1028)
@@ -11,6 +11,7 @@
<body>
<release version="2.4.6-SNAPSHOT" date="TBD" description="(no description)">
+ <action dev="rlogiacco" type="add" issue="284432" due-to="JamesR">Add support for interval type on postgres</action>
<action dev="felipeal" type="update">Changed some verbose logging statements from INFO to DEBUG level</action>
<action dev="gommma" type="fix" issue="2797698" due-to="mkienenb">DefaultDataSet is incompatible w/ AbstractDataSet's IDataSet</action>
<action dev="gommma" type="fix" issue="2818981" due-to="verreckenk">XlsTable - empty excel columns cause problem</action>
Added: trunk/src/java/org/dbunit/ext/postgresql/IntervalType.java
===================================================================
--- trunk/src/java/org/dbunit/ext/postgresql/IntervalType.java (rev 0)
+++ trunk/src/java/org/dbunit/ext/postgresql/IntervalType.java 2009-08-25 16:58:33 UTC (rev 1028)
@@ -0,0 +1,93 @@
+/*
+ *
+ * The DbUnit Database Testing Framework
+ * Copyright (C)2002-2004, DbUnit.org
+ *
+ * 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.ext.postgresql;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.dbunit.dataset.datatype.AbstractDataType;
+import org.dbunit.dataset.datatype.TypeCastException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Adapter to handle conversion between Postgresql
+ * native Interval type and strings.
+ *
+ * @author James A. Russo (jr...@ha...)
+ * @since 2.4.6 (Aug 25, 2009)
+ */
+public class IntervalType
+ extends AbstractDataType {
+
+ /**
+ * Logger for this class
+ */
+ private static final Logger logger = LoggerFactory.getLogger(IntervalType.class);
+
+
+ public IntervalType() {
+ super("interval", Types.OTHER, String.class, false);
+ }
+
+ public Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException {
+ return resultSet.getString(column);
+ }
+
+ public void setSqlValue(Object interval, int column,
+ PreparedStatement statement) throws SQLException, TypeCastException {
+ statement.setObject(column, getInterval(interval, statement.getConnection()));
+ }
+
+ public Object typeCast(Object arg0) throws TypeCastException {
+ return arg0.toString();
+ }
+
+ private Object getInterval(Object value, Connection connection) throws TypeCastException {
+ logger.debug("getInterval(value={}, connection={}) - start", value, connection);
+
+ Object tempInterval = null;
+
+ try {
+ Class aPGIntervalClass = super.loadClass("org.postgresql.util.PGInterval", connection);
+ Constructor ct = aPGIntervalClass.getConstructor(null);
+ tempInterval = ct.newInstance(new Object[]{value});
+ } catch (ClassNotFoundException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (InvocationTargetException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (NoSuchMethodException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (IllegalAccessException e) {
+ throw new TypeCastException(value, this, e);
+ } catch (InstantiationException e) {
+ throw new TypeCastException(value, this, e);
+ }
+
+ return tempInterval;
+ }
+}
Property changes on: trunk/src/java/org/dbunit/ext/postgresql/IntervalType.java
___________________________________________________________________
Added: svn:executable
+ *
Modified: trunk/src/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java
===================================================================
--- trunk/src/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java 2009-08-19 20:07:23 UTC (rev 1027)
+++ trunk/src/java/org/dbunit/ext/postgresql/PostgresqlDataTypeFactory.java 2009-08-25 16:58:33 UTC (rev 1028)
@@ -53,6 +53,9 @@
// Treat Postgresql UUID types as VARCHARS
if ("uuid".equals(sqlTypeName))
return new UuidType();
+ // Intervals are custom types
+ else if ("interval".equals(sqlTypeName))
+ return new IntervalType();
else if ("inet".equals(sqlTypeName))
return new InetType();
else
Modified: trunk/src/test/org/dbunit/ext/postgresql/PostgresqlDataTypeFactoryTest.java
===================================================================
--- trunk/src/test/org/dbunit/ext/postgresql/PostgresqlDataTypeFactoryTest.java 2009-08-19 20:07:23 UTC (rev 1027)
+++ trunk/src/test/org/dbunit/ext/postgresql/PostgresqlDataTypeFactoryTest.java 2009-08-25 16:58:33 UTC (rev 1028)
@@ -28,6 +28,7 @@
/**
*
* @author Jarvis Cochrane (ja...@co...)
+ * @author Roberto Lo Giacco (rlo...@us...)
* @since 2.4.5 (Apr 27, 2009)
*/
public class PostgresqlDataTypeFactoryTest extends TestCase {
@@ -50,7 +51,19 @@
DataType result = instance.createDataType(sqlType, sqlTypeName);
assertTrue(result instanceof UuidType);
}
+
+ public void testCreateIntervalType() throws Exception {
+ PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
+
+ // Test interval type created properly
+ int sqlType = Types.OTHER;
+ String sqlTypeName = "interval";
+
+ DataType result = instance.createDataType(sqlType, sqlTypeName);
+ assertTrue(result instanceof IntervalType);
+ }
+
public void testCreateInetType() throws Exception {
PostgresqlDataTypeFactory instance = new PostgresqlDataTypeFactory();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|