KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbunit > dataset > AbstractTest


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 package org.dbunit.dataset;
22
23 import junit.framework.TestCase;
24
25 import java.util.Arrays JavaDoc;
26 import java.util.List JavaDoc;
27
28 /**
29  * @author Manuel Laflamme
30  * @since Apr 6, 2003
31  * @version $Revision: 1.4 $
32  */

33 public class AbstractTest extends TestCase
34 {
35     private static final String JavaDoc[] TABLE_NAMES = {
36         "TEST_TABLE",
37         "SECOND_TABLE",
38         "EMPTY_TABLE",
39         "PK_TABLE",
40         "ONLY_PK_TABLE",
41         "EMPTY_MULTITYPE_TABLE",
42     };
43     private static final String JavaDoc[] DUPLICATE_TABLE_NAMES = {
44         "DUPLICATE_TABLE",
45         "EMPTY_TABLE",
46         "DUPLICATE_TABLE",
47     };
48     private static final String JavaDoc EXTRA_TABLE_NAME = "EXTRA_TABLE";
49
50     public AbstractTest(String JavaDoc s)
51     {
52         super(s);
53     }
54
55     protected String JavaDoc[] getExpectedNames() throws Exception JavaDoc
56     {
57         return (String JavaDoc[])AbstractTest.TABLE_NAMES.clone();
58     }
59
60     protected String JavaDoc[] getExpectedLowerNames() throws Exception JavaDoc
61     {
62         String JavaDoc[] names = (String JavaDoc[])AbstractTest.TABLE_NAMES.clone();
63         for (int i = 0; i < names.length; i++)
64         {
65             names[i] = names[i].toLowerCase();
66         }
67
68         return names;
69     }
70
71     protected String JavaDoc[] getExpectedDuplicateNames()
72     {
73         return (String JavaDoc[])AbstractTest.DUPLICATE_TABLE_NAMES.clone();
74     }
75
76     protected String JavaDoc getDuplicateTableName()
77     {
78         return "DUPLICATE_TABLE";
79     }
80
81     public String JavaDoc getExtraTableName()
82     {
83         return AbstractTest.EXTRA_TABLE_NAME;
84     }
85
86     public void assertEqualsIgnoreCase(String JavaDoc message, String JavaDoc expected, String JavaDoc actual)
87     {
88         if (!expected.equalsIgnoreCase(actual))
89         {
90             assertEquals(message, expected, actual);
91         }
92     }
93
94     public void assertContains(String JavaDoc message, Object JavaDoc[] expected, Object JavaDoc[] actual)
95     {
96         List JavaDoc expectedList = Arrays.asList(expected);
97         List JavaDoc actualList = Arrays.asList(actual);
98
99         if (!actualList.containsAll(expectedList))
100         {
101             fail(message + " expected contains:<" + expectedList + "> but was:<"
102                     + actualList + ">");
103         }
104     }
105
106     public void assertContainsIgnoreCase(String JavaDoc message, String JavaDoc[] expected, String JavaDoc[] actual)
107     {
108         String JavaDoc[] expectedLowerCase = new String JavaDoc[expected.length];
109         for (int i = 0; i < expected.length; i++)
110         {
111             expectedLowerCase[i] = expected[i].toLowerCase();
112         }
113
114         String JavaDoc[] actualLowerCase = new String JavaDoc[actual.length];
115         for (int i = 0; i < actual.length; i++)
116         {
117             actualLowerCase[i] = actual[i].toLowerCase();
118         }
119
120         assertContains(message, expectedLowerCase, actualLowerCase);
121     }
122
123 }
124
Popular Tags