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;
22
23 import java.util.Arrays;
24
25 /**
26 * Defines a database table to verify (assert on data), specifying include and
27 * exclude column filters.
28 *
29 * @author Jeff Jensen jeffjensen AT users.sourceforge.net
30 * @author Last changed by: $Author$
31 * @version $Revision$ $Date$
32 * @since 2.4.8
33 */
34 public class VerifyTableDefinition {
35 /** The name of the table. */
36 private final String tableName;
37
38 /** The columns to exclude in table comparisons. */
39 private final String[] columnExclusionFilters;
40
41 /** The columns to include in table comparisons. */
42 private final String[] columnInclusionFilters;
43
44 /**
45 * Create a valid instance with no include columns specified (meaning
46 * include all columns).
47 *
48 * @param table
49 * The name of the table - required.
50 * @param excludeColumns
51 * The columns in the table to ignore (filter out) in expected vs
52 * actual comparisons; null or empty array to exclude no columns.
53 */
54 public VerifyTableDefinition(String table, String[] excludeColumns) {
55 this(table, excludeColumns, null);
56 }
57
58 /**
59 * Create a valid instance specifying exclude and include columns.
60 *
61 * @param table
62 * The name of the table.
63 * @param excludeColumns
64 * The columns in the table to ignore (filter out) in expected vs
65 * actual comparisons; null or empty array to exclude no columns.
66 * @param includeColumns
67 * The columns in the table to include in expected vs actual
68 * comparisons; null to include all columns, empty array to
69 * include no columns.
70 */
71 public VerifyTableDefinition(String table, String[] excludeColumns,
72 String[] includeColumns) {
73 if (table == null) {
74 throw new IllegalArgumentException("table is null.");
75 }
76
77 tableName = table;
78 columnExclusionFilters = excludeColumns;
79 columnInclusionFilters = includeColumns;
80 }
81
82 public String getTableName() {
83 return tableName;
84 }
85
86 public String[] getColumnExclusionFilters() {
87 return columnExclusionFilters;
88 }
89
90 public String[] getColumnInclusionFilters() {
91 return columnInclusionFilters;
92 }
93
94 /**
95 * {@inheritDoc}
96 */
97 public String toString() {
98 String exclusionString = arrayToString(columnExclusionFilters);
99 String inclusionString = arrayToString(columnInclusionFilters);
100
101 StringBuilder sb = new StringBuilder(1000);
102 sb.append("tableName='").append(tableName).append("'");
103 sb.append(", columnExclusionFilters='").append(exclusionString)
104 .append("'");
105 sb.append(", columnInclusionFilters='").append(inclusionString)
106 .append("'");
107 return sb.toString();
108 }
109
110 protected String arrayToString(String[] array) {
111 String string;
112 if (array == null) {
113 string = "";
114 } else {
115 string = Arrays.toString(array);
116 }
117 return string;
118 }
119 }