1 /*
2 *
3 * The DbUnit Database Testing Framework
4 * Copyright (C)2002-2008, 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 package org.dbunit.assertion;
22
23 import java.util.List;
24
25 import junit.framework.TestCase;
26
27 import org.dbunit.dataset.IDataSet;
28 import org.dbunit.dataset.xml.FlatXmlDataSet;
29 import org.dbunit.testutil.TestUtils;
30
31 /**
32 * @author gommma (gommma AT users.sourceforge.net)
33 * @author Last changed by: $Author: jbhurst $
34 * @version $Revision: 1162 $ $Date: 2010-02-12 00:29:37 +0100 (ven, 12 feb 2010) $
35 * @since 2.4.0
36 */
37 public class DiffCollectingFailureHandlerTest extends TestCase
38 {
39 private DbUnitAssert assertion = new DbUnitAssert();
40
41 public DiffCollectingFailureHandlerTest(String s)
42 {
43 super(s);
44 }
45
46 private IDataSet getDataSet() throws Exception
47 {
48 return new FlatXmlDataSet(TestUtils.getFileReader(DbUnitAssertIT.FILE_PATH));
49 }
50
51 public void testAssertTablesWithDifferentValues() throws Exception
52 {
53 IDataSet dataSet = getDataSet();
54
55 DiffCollectingFailureHandler myHandler = new DiffCollectingFailureHandler();
56
57 assertion.assertEquals(dataSet.getTable("TEST_TABLE"),
58 dataSet.getTable("TEST_TABLE_WITH_WRONG_VALUE"),
59 myHandler);
60
61 List diffList = myHandler.getDiffList();
62 assertEquals(1, diffList.size());
63 Difference diff = (Difference)diffList.get(0);
64 assertEquals("COLUMN2", diff.getColumnName());
65 assertEquals("row 1 col 2", diff.getExpectedValue());
66 assertEquals("wrong value", diff.getActualValue());
67 }
68
69 }