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  
22  package org.dbunit.assertion;
23  
24  import java.io.StringReader;
25  import java.math.BigDecimal;
26  
27  import junit.framework.ComparisonFailure;
28  import junit.framework.TestCase;
29  
30  import org.dbunit.DatabaseEnvironment;
31  import org.dbunit.database.IDatabaseConnection;
32  import org.dbunit.dataset.Column;
33  import org.dbunit.dataset.CompositeDataSet;
34  import org.dbunit.dataset.CompositeTable;
35  import org.dbunit.dataset.DataSetException;
36  import org.dbunit.dataset.DataSetUtils;
37  import org.dbunit.dataset.DefaultDataSet;
38  import org.dbunit.dataset.DefaultTable;
39  import org.dbunit.dataset.FilteredDataSet;
40  import org.dbunit.dataset.IDataSet;
41  import org.dbunit.dataset.ITable;
42  import org.dbunit.dataset.ITableMetaData;
43  import org.dbunit.dataset.datatype.DataType;
44  import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
45  import org.dbunit.dataset.xml.XmlDataSet;
46  import org.dbunit.operation.DatabaseOperation;
47  import org.dbunit.testutil.TestUtils;
48  
49  /**
50   * @author Manuel Laflamme
51   * @version $Revision$
52   * @since Mar 22, 2002
53   */
54  public class DbUnitAssertIT extends TestCase
55  {
56      public static final String FILE_PATH = "xml/assertionTest.xml";
57      
58      private DbUnitAssert assertion = new DbUnitAssert();
59      
60      
61      public DbUnitAssertIT(String s)
62      {
63          super(s);
64      }
65  
66      private IDataSet getDataSet() throws Exception
67      {
68          return new FlatXmlDataSetBuilder().build(TestUtils.getFileReader(FILE_PATH));
69      }
70  
71      ////////////////////////////////////////////////////////////////////////////
72      // Test methods
73  
74      public void testAssertTablesEquals() throws Exception
75      {
76          IDataSet dataSet = getDataSet();
77          assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
78                  dataSet.getTable("TEST_TABLE_WITH_SAME_VALUE"), 
79                  new Column[] {new Column("COLUMN0", DataType.VARCHAR)} );
80      }
81      
82      public void testAssertTablesEmtpyEquals() throws Exception
83      {
84        IDataSet empty1 = new XmlDataSet(TestUtils.getFileReader("xml/assertionTest-empty1.xml"));
85        IDataSet empty2 = new FlatXmlDataSetBuilder().build(TestUtils.getFileReader("xml/assertionTest-empty2.xml"));
86        assertion.assertEquals(empty1, empty2);
87      }
88      
89  
90  	public void testAssertTablesEqualsColumnNamesCaseInsensitive() throws Exception
91      {
92          IDataSet dataSet = getDataSet();
93          assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
94                  dataSet.getTable("TEST_TABLE_WITH_LOWER_COLUMN_NAMES"));
95      }
96  
97      public void testAssertTablesAndNamesNotEquals() throws Exception
98      {
99          IDataSet dataSet = getDataSet();
100         assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
101                 dataSet.getTable("TEST_TABLE_WITH_DIFFERENT_NAME"));
102     }
103 
104     public void testAssertTablesAndColumnCountNotEquals() throws Exception
105     {
106         IDataSet dataSet = getDataSet();
107 
108         try
109         {
110             assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
111                     dataSet.getTable("TEST_TABLE_WITH_3_COLUMNS"));
112             throw new IllegalStateException("Should throw an AssertionFailedError");
113         }
114         catch (ComparisonFailure expected)
115         {
116             assertEquals("[COLUMN0, COLUMN1, COLUMN2, COLUMN3]", expected.getExpected());
117             assertEquals("[COLUMN0, COLUMN1, COLUMN2]", expected.getActual());
118             String expectedMsg = "column count (table=TEST_TABLE, expectedColCount=4, actualColCount=3) expected:<...N0, COLUMN1, COLUMN2[, COLUMN3]]> but was:<...N0, COLUMN1, COLUMN2[]]>";
119             assertEquals(expectedMsg, expected.getMessage());
120         }
121     }
122 
123     public void testAssertTablesAndColumnSequenceNotEquals() throws Exception
124     {
125         IDataSet dataSet = getDataSet();
126 
127         assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
128                 dataSet.getTable("TEST_TABLE_WITH_DIFFERENT_COLUMN_SEQUENCE"));
129     }
130 
131     public void testAssertTablesAndColumnNamesNotEquals() throws Exception
132     {
133         IDataSet dataSet = getDataSet();
134 
135         try
136         {
137             assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
138                     dataSet.getTable("TEST_TABLE_WITH_DIFFERENT_COLUMN_NAMES"));
139             throw new IllegalStateException("Should throw an AssertionFailedError");
140         }
141         catch (ComparisonFailure expected)
142         {
143             assertEquals("[COLUMN0, COLUMN1, COLUMN2, COLUMN3]", expected.getExpected());
144             assertEquals("[COLUMN4, COLUMN5, COLUMN6, COLUMN7]", expected.getActual());
145             String expectedMsg = "column mismatch (table=TEST_TABLE) expected:<[COLUMN[0, COLUMN1, COLUMN2, COLUMN3]]> but was:<[COLUMN[4, COLUMN5, COLUMN6, COLUMN7]]>";
146             assertEquals(expectedMsg, expected.getMessage());
147         }
148     }
149 
150     public void testAssertTablesAndRowCountNotEquals() throws Exception
151     {
152         IDataSet dataSet = getDataSet();
153 
154         try
155         {
156             assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
157                     dataSet.getTable("TEST_TABLE_WITH_ONE_ROW"));
158             throw new IllegalStateException("Should throw an AssertionFailedError");
159         }
160         catch (ComparisonFailure expected)
161         {
162             assertEquals("2", expected.getExpected());
163             assertEquals("1", expected.getActual());
164             String expectedMsg = "row count (table=TEST_TABLE) expected:<[2]> but was:<[1]>";
165             assertEquals(expectedMsg, expected.getMessage());
166         }
167     }
168 
169     public void testAssertTablesAndValuesNotEquals() throws Exception
170     {
171         IDataSet dataSet = getDataSet();
172 
173         try
174         {
175             assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
176                     dataSet.getTable("TEST_TABLE_WITH_WRONG_VALUE"));
177             throw new IllegalStateException("Should throw an AssertionFailedError");
178         }
179         catch (ComparisonFailure expected)
180         {
181             assertEquals("row 1 col 2", expected.getExpected());
182             assertEquals("wrong value", expected.getActual());
183             String expectedMsg = "value (table=TEST_TABLE, row=1, col=COLUMN2) expected:<[row 1 col 2]> but was:<[wrong value]>";
184             assertEquals(expectedMsg, expected.getMessage());
185         }
186     }
187 
188     public void testAssertTablesWithColFilterAndValuesNotEqualExcluded() throws Exception
189     {
190         IDataSet dataSet = getDataSet();
191         
192         // Column2 has the wrong value, so exclude -> test should run successfully
193         String[] allColumnsThatAreNotEqual = new String[] {"COLUMN2"};
194         assertion.assertEqualsIgnoreCols(dataSet.getTable("TEST_TABLE"),
195                 dataSet.getTable("TEST_TABLE_WITH_WRONG_VALUE"),
196                 allColumnsThatAreNotEqual );
197     }
198 
199     public void testAssertTablesWithColFilterAndValuesNotEqualNotExcluded() throws Exception
200     {
201         IDataSet dataSet = getDataSet();
202         
203         // Column0 has correct value. Column2 has the wrong value but is not filtered.
204         // -> test should fail
205         String[] filteredColumns = new String[] {"COLUMN0"};
206         try {
207             assertion.assertEqualsIgnoreCols(dataSet.getTable("TEST_TABLE"),
208 	                dataSet.getTable("TEST_TABLE_WITH_WRONG_VALUE"),
209 	                filteredColumns );
210             throw new IllegalStateException("Should throw an AssertionFailedError");
211         }
212         catch (ComparisonFailure expected)
213         {
214             assertEquals("row 1 col 2", expected.getExpected());
215             assertEquals("wrong value", expected.getActual());
216         	String expectedMsg = "value (table=TEST_TABLE, row=1, col=COLUMN2) expected:<[row 1 col 2]> but was:<[wrong value]>";
217         	assertEquals(expectedMsg, expected.getMessage());
218         }
219     }
220 
221     public void testAssertTablesAndValuesNotEquals_AdditionalColumnInfo() throws Exception
222     {
223         IDataSet dataSet = getDataSet();
224 
225         try
226         {
227         	Column[] additionalColInfo = new Column[]{
228         			new Column("COLUMN0", DataType.VARCHAR)
229         	};
230         	assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
231                     dataSet.getTable("TEST_TABLE_WITH_WRONG_VALUE"),
232                     additionalColInfo);
233             throw   new IllegalStateException("Should throw an AssertionFailedError");
234         }
235         catch (ComparisonFailure expected)
236         {
237         	String expectedMsg = "junit.framework.ComparisonFailure: value (table=TEST_TABLE, row=1, col=COLUMN2, " +
238         			"Additional row info: ('COLUMN0': expected=<row 1 col 0>, actual=<row 1 col 0>)) " +
239         			"expected:<[row 1 col 2]> but was:<[wrong value]>";
240         	String actualMsg = expected.toString();
241         	assertEquals("row 1 col 2", expected.getExpected());
242         	assertEquals("wrong value", expected.getActual());
243         	assertEquals("Exception message did not match the expected one.", expectedMsg, actualMsg);
244         }
245     }
246 
247     
248     public void testAssertTablesEqualsAndIncompatibleDataType() throws Exception
249     {
250         String tableName = "TABLE_NAME";
251 
252         // Setup actual table
253         Column[] actualColumns = new Column[] {
254             new Column("BOOLEAN", DataType.BOOLEAN),
255         };
256         Object[] actualRow = new Object[] {
257             Boolean.TRUE,
258         };
259         DefaultTable actualTable = new DefaultTable(tableName,
260                 actualColumns);
261         actualTable.addRow(actualRow);
262 
263         // Setup expected table
264         Column[] expectedColumns = new Column[] {
265             new Column("BOOLEAN", DataType.VARCHAR),
266         };
267         Object[] expectedRow = new Object[] {
268             "1",
269         };
270         DefaultTable expectedTable = new DefaultTable(tableName,
271                 expectedColumns);
272         expectedTable.addRow(expectedRow);
273 
274 
275         try
276         {
277             assertion.assertEquals(expectedTable, actualTable);
278         }
279         catch (ComparisonFailure expected)
280         {
281             assertEquals("VARCHAR", expected.getExpected());
282             assertEquals("BOOLEAN", expected.getActual());
283             String expectedMsg = "Incompatible data types: (table=TABLE_NAME, col=BOOLEAN) expected:<[VARCHAR]> but was:<[BOOLEAN]>";
284             assertEquals(expectedMsg, expected.getMessage());
285         }
286     }
287 
288     public void testAssertTablesByQueryWithColFilterAndValuesNotEqualExcluded() throws Exception
289     {
290         DatabaseEnvironment env = DatabaseEnvironment.getInstance();
291         IDatabaseConnection connection = env.getConnection();
292 
293         IDataSet dataSet = env.getInitDataSet();
294     	ITable expectedTable = dataSet.getTable("TEST_TABLE");
295 
296 		ITable table = dataSet.getTable("TEST_TABLE");
297 		ITable filteredTable = new ModifyingTable(table, "COLUMN2");
298         DatabaseOperation.CLEAN_INSERT.execute(connection, new DefaultDataSet(filteredTable));
299 
300     	// Ignore COLUMN2 which has been modified by the "ModifyingTable" above and hence does not match.
301         // When we ignore this column, the assertion should work without failure
302         String[] ignoreCols = new String[] {"COLUMN2"};
303         assertion.assertEqualsByQuery(expectedTable, connection, "TEST_TABLE", "select * from TEST_TABLE order by 1", ignoreCols);
304     }
305     
306     public void testAssertTablesByQueryWithColFilterAndValuesNotEqualNotExcluded() throws Exception
307     {
308         DatabaseEnvironment env = DatabaseEnvironment.getInstance();
309         IDatabaseConnection connection = env.getConnection();
310 
311         IDataSet dataSet = env.getInitDataSet();
312     	ITable expectedTable = dataSet.getTable("TEST_TABLE");
313 
314 		ITable table = dataSet.getTable("TEST_TABLE");
315 		ITable filteredTable = new ModifyingTable(table, "COLUMN2");
316         DatabaseOperation.CLEAN_INSERT.execute(connection, new DefaultDataSet(filteredTable));
317 
318     	// Ignore COLUMN1 which has NOT been modified by the "ModifyingTable". The modified COLUMN2 does
319         // not match and is not ignored. So the assertion should fail.
320         String[] ignoreCols = new String[] {"COLUMN1"};
321         try {
322             assertion.assertEqualsByQuery(expectedTable, connection, "TEST_TABLE", "select * from TEST_TABLE order by 1", ignoreCols);
323         	fail("The assertion should not work");
324         }
325         catch (ComparisonFailure expected)
326         {
327             assertEquals("row 0 col 2", expected.getExpected());
328             assertEquals("row 0 col 2 (modified COLUMN2)", expected.getActual());
329         	String expectedMsg = "value (table=TEST_TABLE, row=0, col=COLUMN2) expected:<row 0 col 2[]> but was:<row 0 col 2[ (modified COLUMN2)]>";
330         	assertEquals(expectedMsg, expected.getMessage());
331         }
332     }
333 
334     
335     
336     public void testAssertTablesEqualsAndCompatibleDataType() throws Exception
337     {
338         String tableName = "TABLE_NAME";
339         java.sql.Timestamp now = new java.sql.Timestamp(
340                 System.currentTimeMillis());
341 
342         // Setup actual table
343         Column[] actualColumns = new Column[] {
344             new Column("BOOLEAN", DataType.BOOLEAN),
345             new Column("TIMESTAMP", DataType.TIMESTAMP),
346             new Column("STRING", DataType.CHAR),
347             new Column("NUMERIC", DataType.NUMERIC),
348         };
349         Object[] actualRow = new Object[] {
350             Boolean.TRUE,
351             now,
352             "0",
353             new BigDecimal("123.4"),
354         };
355         DefaultTable actualTable = new DefaultTable(tableName,
356                 actualColumns);
357         actualTable.addRow(actualRow);
358 
359 
360         // Setup expected table
361         Column[] expectedColumns = new Column[] {
362             new Column("BOOLEAN", DataType.UNKNOWN),
363             new Column("TIMESTAMP", DataType.UNKNOWN),
364             new Column("STRING", DataType.UNKNOWN),
365             new Column("NUMERIC", DataType.UNKNOWN),
366         };
367         Object[] expectedRow = new Object[] {
368             "1",
369             new Long(now.getTime()),
370             new Integer("0"),
371             "123.4000",
372         };
373         DefaultTable expectedTable = new DefaultTable(tableName,
374                 expectedColumns);
375         expectedTable.addRow(expectedRow);
376 
377         assertion.assertEquals(expectedTable, actualTable);
378     }
379 
380     public void testAssertDataSetsEquals() throws Exception
381     {
382         IDataSet dataSet1 = getDataSet();
383 
384         // change table names order
385         String[] names = DataSetUtils.getReverseTableNames(dataSet1);
386         IDataSet dataSet2 = new FilteredDataSet(names, dataSet1);
387 
388         assertTrue("Datasets are the same instances.", dataSet1 != dataSet2);
389         assertion.assertEquals(dataSet1, dataSet2);
390     }
391 
392     public void testAssertDataSetsEqualsTableNamesCaseInsensitive() throws Exception
393     {
394         IDataSet dataSet1 = getDataSet();
395 
396         // change table names case
397         String[] names = dataSet1.getTableNames();
398         for (int i = 0; i < names.length; i++)
399         {
400             names[i] = names[i].toLowerCase();
401         }
402         IDataSet dataSet2 = new FilteredDataSet(names, dataSet1);
403 
404         assertTrue("Datasets are the same instances.", dataSet1 != dataSet2);
405         assertion.assertEquals(dataSet1, dataSet2);
406     }
407     
408     public void testAssertDataSetsTableNamesCaseSensitiveNotEquals() throws Exception
409     {
410         IDataSet dataSet1 = new FlatXmlDataSetBuilder().setCaseSensitiveTableNames(true).build(TestUtils.getFileReader("xml/assertion_table_name_case_sensitive_1.xml"));
411         IDataSet dataSet2 = new FlatXmlDataSetBuilder().setCaseSensitiveTableNames(true).build(TestUtils.getFileReader("xml/assertion_table_name_case_sensitive_2.xml"));
412         
413         try {
414             assertion.assertEquals(dataSet1, dataSet2);
415             fail("Should throw an AssertionFailedError");
416         } catch (ComparisonFailure expected) {
417             assertEquals("Expected table name did not match.",
418                     "[TEST_TABLE_WITH_CASE_SENSITIVE_NAME]",
419                     expected.getExpected());
420             assertEquals("Actual table name did not match.",
421                     "[test_table_with_case_sensitive_name]",
422                     expected.getActual());
423         }
424     }
425     
426     public void testAssertDataSetsTableNamesCaseSensitiveWithLowerCaseEquals() throws Exception
427     {
428         IDataSet dataSet1 = new FlatXmlDataSetBuilder().setCaseSensitiveTableNames(true).build(TestUtils.getFileReader("xml/assertion_table_name_case_sensitive_with_lower_case.xml"));
429         IDataSet dataSet2 = new FlatXmlDataSetBuilder().setCaseSensitiveTableNames(true).build(TestUtils.getFileReader("xml/assertion_table_name_case_sensitive_with_lower_case.xml"));
430         assertTrue("Datasets are the same instances.", dataSet1 != dataSet2);
431         assertion.assertEquals(dataSet1, dataSet2);
432     }
433 
434     public void testAssertDataSetsAndTableCountNotEquals() throws Exception
435     {
436         IDataSet dataSet1 = getDataSet();
437 
438         // only one table
439         String[] names = new String[]{dataSet1.getTableNames()[0]};
440         IDataSet dataSet2 = new FilteredDataSet(names, dataSet1);
441 
442         assertTrue("Datasets are the same instances.", dataSet1 != dataSet2);
443 
444         try
445         {
446             assertion.assertEquals(dataSet1, dataSet2);
447             throw new IllegalStateException("Should throw an AssertionFailedError");
448         }
449         catch (ComparisonFailure expected)
450         {
451             assertEquals("9", expected.getExpected());
452             assertEquals("1", expected.getActual());
453             assertEquals("table count expected:<[9]> but was:<[1]>", expected.getMessage());
454         }
455     }
456 
457 
458     public void testAssertDataSetsAndTableNamesNotEquals() throws Exception
459     {
460         IDataSet dataSet1 = getDataSet();
461 
462         // reverse table names
463         String[] names = dataSet1.getTableNames();
464         ITable[] tables = new ITable[names.length];
465         for (int i = 0; i < names.length; i++)
466         {
467             String reversedName = new StringBuffer(names[i]).reverse().toString();
468             tables[i] = new CompositeTable(reversedName,
469                     dataSet1.getTable(names[i]));
470         }
471         IDataSet dataSet2 = new DefaultDataSet(tables);
472 
473         assertTrue("Datasets are the same instances.", dataSet1 != dataSet2);
474         assertEquals("table count", dataSet1.getTableNames().length,
475                 dataSet2.getTableNames().length);
476 
477         try
478         {
479             assertion.assertEquals(dataSet1, dataSet2);
480             throw new IllegalStateException("Should throw an AssertionFailedError");
481         }
482         catch (ComparisonFailure expected)
483         {
484         }
485     }
486 
487     public void testAssertDataSetsAndTablesNotEquals() throws Exception
488     {
489         IDataSet dataSet1 = getDataSet();
490 
491         // different row counts (double)
492         IDataSet dataSet2 = new CompositeDataSet(dataSet1, dataSet1);
493 
494         assertTrue("Datasets are the same instances.", dataSet1 != dataSet2);
495         assertEquals("table count", dataSet1.getTableNames().length,
496                 dataSet2.getTableNames().length);
497 
498         try
499         {
500             assertion.assertEquals(dataSet1, dataSet2);
501             throw new IllegalStateException("Should throw an AssertionFailedError");
502         }
503         catch (ComparisonFailure expected)
504         {
505             assertEquals("2", expected.getExpected());
506             assertEquals("4", expected.getActual());
507             assertEquals("row count (table=TEST_TABLE) expected:<[2]> but was:<[4]>", expected.getMessage());
508         }
509     }
510     
511     public void testAssertDataSetsWithFailureHandler() throws Exception
512     {
513         DiffCollectingFailureHandler fh = new DiffCollectingFailureHandler();
514         
515         String xml1 = 
516             "<dataset>\n"+
517             "<TEST_TABLE COLUMN0='row 0 col 0' COLUMN1='row 0 col 1'/>\n" +
518             "</dataset>\n";
519         IDataSet dataSet1 = new FlatXmlDataSetBuilder().build(new StringReader(xml1));
520         String xml2 = 
521             "<dataset>\n"+
522             "<TEST_TABLE COLUMN0='row 0 col somthing' COLUMN1='row 0 col something mysterious'/>\n" +
523             "</dataset>\n";
524         IDataSet dataSet2 = new FlatXmlDataSetBuilder().build(new StringReader(xml2));
525 
526         // Invoke the assertion
527         assertion.assertEquals(dataSet1, dataSet2, fh);
528         // We expect that no failure was thrown even if the dataSets were not equal.
529         // This is because our custom failureHandler
530         assertEquals(2, fh.getDiffList().size());
531     }
532 
533     
534     
535     public void testGetComparisonDataType_ExpectedTypeUnknown()
536     {
537     	Column expectedColumn = new Column("COL1", DataType.UNKNOWN);
538     	Column actualColumn = new Column("COL1", DataType.VARCHAR);
539     	DataType dataType = new DbUnitAssert.ComparisonColumn("BLABLA_TABLE_NOT_NEEDED_HERE", expectedColumn, actualColumn, assertion.getDefaultFailureHandler()).getDataType();
540     	assertEquals(DataType.VARCHAR, dataType);
541     }
542     
543     public void testGetComparisonDataType_ActualTypeUnknown()
544     {
545     	Column expectedColumn = new Column("COL1", DataType.VARCHAR);
546     	Column actualColumn = new Column("COL1", DataType.UNKNOWN);
547     	DataType dataType = new DbUnitAssert.ComparisonColumn("BLABLA_TABLE_NOT_NEEDED_HERE", expectedColumn, actualColumn, assertion.getDefaultFailureHandler()).getDataType();
548     	assertEquals(DataType.VARCHAR, dataType);
549     }
550 
551     public void testGetComparisonDataType_BothTypesSetIncompatible()
552     {
553     	Column expectedColumn = new Column("COL1", DataType.VARCHAR);
554     	Column actualColumn = new Column("COL1", DataType.NUMERIC);
555     	try {
556     	    new DbUnitAssert.ComparisonColumn("BLABLA_TABLE_NOT_NEEDED_HERE", expectedColumn, actualColumn, assertion.getDefaultFailureHandler()).getDataType();
557     		fail("Incompatible datatypes should not work");
558     	}
559     	catch(ComparisonFailure expected){
560     		assertEquals("VARCHAR", expected.getExpected());
561     		assertEquals("NUMERIC", expected.getActual());
562     		String expectedMsg = "Incompatible data types: (table=BLABLA_TABLE_NOT_NEEDED_HERE, col=COL1) expected:<[VARCHAR]> but was:<[NUMERIC]>";
563     		assertEquals(expectedMsg, expected.getMessage());
564     	}
565     }
566 
567     public void testGetComparisonDataType_BothTypesSetToSame()
568     {
569     	Column expectedColumn = new Column("COL1", DataType.VARCHAR);
570     	Column actualColumn = new Column("COL1", DataType.VARCHAR);
571     	DataType dataType = new DbUnitAssert.ComparisonColumn("BLABLA_TABLE_NOT_NEEDED_HERE", expectedColumn, actualColumn, assertion.getDefaultFailureHandler()).getDataType();
572     	assertEquals(DataType.VARCHAR, dataType);
573     }
574 
575     public void testGetComparisonDataType_BothTypesUnknown()
576     {
577     	Column expectedColumn = new Column("COL1", DataType.UNKNOWN);
578     	Column actualColumn = new Column("COL1", DataType.UNKNOWN);
579     	DataType dataType = new DbUnitAssert.ComparisonColumn("BLABLA_TABLE_NOT_NEEDED_HERE", expectedColumn, actualColumn, assertion.getDefaultFailureHandler()).getDataType();
580     	assertEquals(DataType.UNKNOWN, dataType);
581     }
582 
583     
584     
585     /**
586      * Test utility that modifies all values for a specific column arbitrarily
587      */
588     protected static class ModifyingTable implements ITable
589     {
590     	private ITable _wrappedTable;
591     	private String _columnToModify;
592     	
593     	public ModifyingTable(ITable originalTable, String columnToModify)
594     	{
595     		this._wrappedTable = originalTable;
596     		this._columnToModify = columnToModify;
597     	}
598 
599 		public int getRowCount() {
600 			return this._wrappedTable.getRowCount();
601 		}
602 
603 		public ITableMetaData getTableMetaData() {
604 			return this._wrappedTable.getTableMetaData();
605 		}
606 
607 		public Object getValue(int row, String column) throws DataSetException {
608 			Object originalValue = _wrappedTable.getValue(row, column);
609 
610 			// Modify the value if column name matches
611 			if(column.equalsIgnoreCase(this._columnToModify)) {
612 				return String.valueOf(originalValue) + " (modified "+_columnToModify +")";
613 			}
614 			return originalValue;
615 		}
616     	
617     	
618     }
619 
620 }
621 
622 
623 
624 
625