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;
23  
24  import java.sql.SQLException;
25  
26  import org.dbunit.assertion.DbUnitAssert;
27  import org.dbunit.assertion.FailureHandler;
28  import org.dbunit.database.IDatabaseConnection;
29  import org.dbunit.dataset.Column;
30  import org.dbunit.dataset.IDataSet;
31  import org.dbunit.dataset.ITable;
32  
33  /**
34   * Provides static methods for the most common DbUnit assertion needs.
35   * 
36   * Although the methods are static, they rely on a {@link DbUnitAssert} instance 
37   * to do the work. So, if you need to customize this class behavior, you can create
38   * your own {@link DbUnitAssert} extension.
39   * 
40   * @author Manuel Laflamme
41   * @author Felipe Leme (dbunit@felipeal.net)
42   * @author Last changed by: $Author$
43   * @version $Revision$ $Date$
44   * @since 1.3 (Mar 22, 2002)
45   */
46  public class Assertion {
47  
48      /**
49       * Object that will effectively do the assertions.
50       */
51      private static final DbUnitAssert INSTANCE = new DbUnitAssert();
52  
53      private Assertion() {
54          throw new UnsupportedOperationException(
55          "this class has only static methods");
56      }
57  
58      /**
59       * @see DbUnitAssert#assertEqualsIgnoreCols(IDataSet, IDataSet, String, String[])
60       */
61      public static void assertEqualsIgnoreCols(final IDataSet expectedDataset,
62              final IDataSet actualDataset, final String tableName,
63              final String[] ignoreCols) throws DatabaseUnitException {
64          INSTANCE.assertEqualsIgnoreCols(expectedDataset, actualDataset, tableName,
65                  ignoreCols);
66      }
67  
68      /**
69       * @see DbUnitAssert#assertEqualsIgnoreCols(ITable, ITable, String[])
70       */
71      public static void assertEqualsIgnoreCols(final ITable expectedTable,
72              final ITable actualTable, final String[] ignoreCols)
73      throws DatabaseUnitException {
74          INSTANCE.assertEqualsIgnoreCols(expectedTable, actualTable, ignoreCols);
75      }
76  
77      /**
78       * @see DbUnitAssert#assertEqualsByQuery(IDataSet, IDatabaseConnection, String, String, String[])
79       */
80      public static void assertEqualsByQuery(final IDataSet expectedDataset,
81              final IDatabaseConnection connection, final String sqlQuery,
82              final String tableName, final String[] ignoreCols)
83      throws DatabaseUnitException, SQLException {
84          INSTANCE.assertEqualsByQuery(expectedDataset, connection, sqlQuery,
85                  tableName, ignoreCols);
86      }
87  
88      /**
89       * @see DbUnitAssert#assertEqualsByQuery(ITable, IDatabaseConnection, String, String, String[])
90       */
91      public static void assertEqualsByQuery(final ITable expectedTable,
92              final IDatabaseConnection connection, final String tableName,
93              final String sqlQuery, final String[] ignoreCols)
94      throws DatabaseUnitException, SQLException {
95          INSTANCE.assertEqualsByQuery(expectedTable, connection, tableName,
96                  sqlQuery, ignoreCols);
97      }
98  
99      /**
100      * @see DbUnitAssert#assertEquals(IDataSet, IDataSet)
101      */
102     public static void assertEquals(IDataSet expectedDataSet,
103             IDataSet actualDataSet) throws DatabaseUnitException {
104         INSTANCE.assertEquals(expectedDataSet, actualDataSet);
105     }
106 
107     /**
108      * @see DbUnitAssert#assertEquals(IDataSet, IDataSet, FailureHandler)
109      * @since 2.4
110      */
111     public static void assertEquals(IDataSet expectedDataSet,
112             IDataSet actualDataSet, FailureHandler failureHandler)
113     throws DatabaseUnitException {
114         INSTANCE.assertEquals(expectedDataSet, actualDataSet, failureHandler);
115     }
116 
117     /**
118      * @see DbUnitAssert#assertEquals(ITable, ITable)
119      */
120     public static void assertEquals(ITable expectedTable, ITable actualTable)
121     throws DatabaseUnitException {
122         INSTANCE.assertEquals(expectedTable, actualTable);
123     }
124 
125     /**
126      * @see DbUnitAssert#assertEquals(ITable, ITable, Column[])
127      */
128     public static void assertEquals(ITable expectedTable, ITable actualTable,
129             Column[] additionalColumnInfo) throws DatabaseUnitException {
130         INSTANCE.assertEquals(expectedTable, actualTable, additionalColumnInfo);
131     }
132 
133     /**
134      * @see DbUnitAssert#assertEquals(ITable, ITable, FailureHandler)
135      * @since 2.4
136      */
137     public static void assertEquals(ITable expectedTable, ITable actualTable,
138             FailureHandler failureHandler) throws DatabaseUnitException {
139         INSTANCE.assertEquals(expectedTable, actualTable, failureHandler);
140     }
141 
142 }