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  import java.util.Map;
26  
27  import org.dbunit.assertion.DbUnitAssert;
28  import org.dbunit.assertion.DbUnitValueComparerAssert;
29  import org.dbunit.assertion.FailureHandler;
30  import org.dbunit.assertion.comparer.value.ValueComparer;
31  import org.dbunit.database.IDatabaseConnection;
32  import org.dbunit.dataset.Column;
33  import org.dbunit.dataset.IDataSet;
34  import org.dbunit.dataset.ITable;
35  
36  /**
37   * Provides static methods for the most common DbUnit assertion needs.
38   *
39   * Although the methods are static, they rely on a {@link DbUnitAssert} instance
40   * to do the work. So, if you need to customize this class behavior, you can
41   * create your own {@link DbUnitAssert} extension.
42   *
43   * @author Manuel Laflamme
44   * @author Felipe Leme (dbunit@felipeal.net)
45   * @author Last changed by: $Author$
46   * @version $Revision$ $Date$
47   * @since 1.3 (Mar 22, 2002)
48   */
49  public class Assertion
50  {
51      /** Assert using equals comparisons. */
52      private static final DbUnitAssert EQUALS_INSTANCE = new DbUnitAssert();
53  
54      /** Assert using compare comparisons. @since 2.6.0 */
55      private static final DbUnitValueComparerAssert VALUE_COMPARE_INSTANCE =
56              new DbUnitValueComparerAssert();
57  
58      private Assertion()
59      {
60          throw new UnsupportedOperationException(
61                  "this class has only static methods");
62      }
63  
64      /**
65       * @see DbUnitAssert#assertEqualsIgnoreCols(IDataSet, IDataSet, String,
66       *      String[])
67       */
68      public static void assertEqualsIgnoreCols(final IDataSet expectedDataset,
69              final IDataSet actualDataset, final String tableName,
70              final String[] ignoreCols) throws DatabaseUnitException
71      {
72          EQUALS_INSTANCE.assertEqualsIgnoreCols(expectedDataset, actualDataset,
73                  tableName, ignoreCols);
74      }
75  
76      /**
77       * @see DbUnitAssert#assertEqualsIgnoreCols(ITable, ITable, String[])
78       */
79      public static void assertEqualsIgnoreCols(final ITable expectedTable,
80              final ITable actualTable, final String[] ignoreCols)
81              throws DatabaseUnitException
82      {
83          EQUALS_INSTANCE.assertEqualsIgnoreCols(expectedTable, actualTable,
84                  ignoreCols);
85      }
86  
87      /**
88       * @see DbUnitAssert#assertEqualsByQuery(IDataSet, IDatabaseConnection,
89       *      String, String, String[])
90       */
91      public static void assertEqualsByQuery(final IDataSet expectedDataset,
92              final IDatabaseConnection connection, final String sqlQuery,
93              final String tableName, final String[] ignoreCols)
94              throws DatabaseUnitException, SQLException
95      {
96          EQUALS_INSTANCE.assertEqualsByQuery(expectedDataset, connection,
97                  sqlQuery, tableName, ignoreCols);
98      }
99  
100     /**
101      * @see DbUnitAssert#assertEqualsByQuery(ITable, IDatabaseConnection,
102      *      String, String, String[])
103      */
104     public static void assertEqualsByQuery(final ITable expectedTable,
105             final IDatabaseConnection connection, final String tableName,
106             final String sqlQuery, final String[] ignoreCols)
107             throws DatabaseUnitException, SQLException
108     {
109         EQUALS_INSTANCE.assertEqualsByQuery(expectedTable, connection,
110                 tableName, sqlQuery, ignoreCols);
111     }
112 
113     /**
114      * @see DbUnitAssert#assertEquals(IDataSet, IDataSet)
115      */
116     public static void assertEquals(final IDataSet expectedDataSet,
117             final IDataSet actualDataSet) throws DatabaseUnitException
118     {
119         EQUALS_INSTANCE.assertEquals(expectedDataSet, actualDataSet);
120     }
121 
122     /**
123      * @see DbUnitAssert#assertEquals(IDataSet, IDataSet, FailureHandler)
124      * @since 2.4
125      */
126     public static void assertEquals(final IDataSet expectedDataSet,
127             final IDataSet actualDataSet, final FailureHandler failureHandler)
128             throws DatabaseUnitException
129     {
130         EQUALS_INSTANCE.assertEquals(expectedDataSet, actualDataSet,
131                 failureHandler);
132     }
133 
134     /**
135      * @see DbUnitAssert#assertEquals(ITable, ITable)
136      */
137     public static void assertEquals(final ITable expectedTable,
138             final ITable actualTable) throws DatabaseUnitException
139     {
140         EQUALS_INSTANCE.assertEquals(expectedTable, actualTable);
141     }
142 
143     /**
144      * @see DbUnitAssert#assertEquals(ITable, ITable, Column[])
145      */
146     public static void assertEquals(final ITable expectedTable,
147             final ITable actualTable, final Column[] additionalColumnInfo)
148             throws DatabaseUnitException
149     {
150         EQUALS_INSTANCE.assertEquals(expectedTable, actualTable,
151                 additionalColumnInfo);
152     }
153 
154     /**
155      * @see DbUnitAssert#assertEquals(ITable, ITable, FailureHandler)
156      * @since 2.4
157      */
158     public static void assertEquals(final ITable expectedTable,
159             final ITable actualTable, final FailureHandler failureHandler)
160             throws DatabaseUnitException
161     {
162         EQUALS_INSTANCE.assertEquals(expectedTable, actualTable,
163                 failureHandler);
164     }
165 
166     /**
167      * @see DbUnitValueComparerAssert#assertWithValueComparer(IDataSet,
168      *      IDataSet, ValueComparer, Map)
169      * @since 2.6.0
170      */
171     public static void assertWithValueComparer(final IDataSet expectedDataSet,
172             final IDataSet actualDataSet,
173             final ValueComparer defaultValueComparer,
174             final Map<String, Map<String, ValueComparer>> tableColumnValueComparers)
175             throws DatabaseUnitException
176     {
177         VALUE_COMPARE_INSTANCE.assertWithValueComparer(expectedDataSet,
178                 actualDataSet, defaultValueComparer, tableColumnValueComparers);
179     }
180 
181     /**
182      * @see DbUnitValueComparerAssert#assertWithValueComparer(ITable, ITable,
183      *      ValueComparer, Map)
184      * @since 2.6.0
185      */
186     public static void assertWithValueComparer(final ITable expectedTable,
187             final ITable actualTable, final ValueComparer defaultValueComparer,
188             final Map<String, ValueComparer> columnValueComparers)
189             throws DatabaseUnitException
190     {
191         VALUE_COMPARE_INSTANCE.assertWithValueComparer(expectedTable,
192                 actualTable, defaultValueComparer, columnValueComparers);
193     }
194 
195     /**
196      * @see DbUnitValueComparerAssert#assertWithValueComparer(IDataSet,
197      *      IDataSet, FailureHandler, ValueComparer, Map)
198      * @since 2.6.0
199      */
200     public static void assertWithValueComparer(final IDataSet expectedDataSet,
201             final IDataSet actualDataSet, final FailureHandler failureHandler,
202             final ValueComparer defaultValueComparer,
203             final Map<String, Map<String, ValueComparer>> tableColumnValueComparers)
204             throws DatabaseUnitException
205     {
206         VALUE_COMPARE_INSTANCE.assertWithValueComparer(expectedDataSet,
207                 actualDataSet, failureHandler, defaultValueComparer,
208                 tableColumnValueComparers);
209     }
210 
211     /**
212      * @see DbUnitValueComparerAssert#assertWithValueComparer(ITable, ITable,
213      *      Column[], ValueComparer, Map)
214      * @since 2.6.0
215      */
216     public static void assertWithValueComparer(final ITable expectedTable,
217             final ITable actualTable, final Column[] additionalColumnInfo,
218             final ValueComparer defaultValueComparer,
219             final Map<String, ValueComparer> columnValueComparers)
220             throws DatabaseUnitException
221     {
222         VALUE_COMPARE_INSTANCE.assertWithValueComparer(expectedTable,
223                 actualTable, additionalColumnInfo, defaultValueComparer,
224                 columnValueComparers);
225     }
226 
227     /**
228      * @see DbUnitValueComparerAssert#assertWithValueComparer(ITable, ITable,
229      *      FailureHandler, ValueComparer, Map)
230      * @since 2.6.0
231      */
232     public static void assertWithValueComparer(final ITable expectedTable,
233             final ITable actualTable, final FailureHandler failureHandler,
234             final ValueComparer defaultValueComparer,
235             final Map<String, ValueComparer> columnValueComparers)
236             throws DatabaseUnitException
237     {
238         VALUE_COMPARE_INSTANCE.assertWithValueComparer(expectedTable,
239                 actualTable, failureHandler, defaultValueComparer,
240                 columnValueComparers);
241     }
242 }