1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.dataset;
22
23 import junit.framework.TestCase;
24
25 import java.util.Arrays;
26 import java.util.List;
27
28
29
30
31
32
33 public class AbstractTest extends TestCase
34 {
35 private static final String[] 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[] DUPLICATE_TABLE_NAMES = {
44 "DUPLICATE_TABLE",
45 "EMPTY_TABLE",
46 "DUPLICATE_TABLE",
47 };
48 private static final String EXTRA_TABLE_NAME = "EXTRA_TABLE";
49
50 public AbstractTest(String s)
51 {
52 super(s);
53 }
54
55
56
57
58
59
60
61
62
63 protected String convertString(String str) throws Exception
64 {
65 return str;
66 }
67
68 protected String[] getExpectedNames() throws Exception
69 {
70 return (String[])AbstractTest.TABLE_NAMES.clone();
71 }
72
73 protected String[] getExpectedLowerNames() throws Exception
74 {
75 String[] names = (String[])AbstractTest.TABLE_NAMES.clone();
76 for (int i = 0; i < names.length; i++)
77 {
78 names[i] = names[i].toLowerCase();
79 }
80
81 return names;
82 }
83
84 protected String[] getExpectedDuplicateNames()
85 {
86 return (String[])AbstractTest.DUPLICATE_TABLE_NAMES.clone();
87 }
88
89 protected String getDuplicateTableName()
90 {
91 return "DUPLICATE_TABLE";
92 }
93
94 public String getExtraTableName()
95 {
96 return AbstractTest.EXTRA_TABLE_NAME;
97 }
98
99 public void assertEqualsIgnoreCase(String message, String expected, String actual)
100 {
101 if (!expected.equalsIgnoreCase(actual))
102 {
103 assertEquals(message, expected, actual);
104 }
105 }
106
107 public void assertContains(String message, Object[] expected, Object[] actual)
108 {
109 List expectedList = Arrays.asList(expected);
110 List actualList = Arrays.asList(actual);
111
112 if (!actualList.containsAll(expectedList))
113 {
114 fail(message + " expected contains:<" + expectedList + "> but was:<"
115 + actualList + ">");
116 }
117 }
118
119 public void assertContainsIgnoreCase(String message, String[] expected, String[] actual)
120 {
121 String[] expectedLowerCase = new String[expected.length];
122 for (int i = 0; i < expected.length; i++)
123 {
124 expectedLowerCase[i] = expected[i].toLowerCase();
125 }
126
127 String[] actualLowerCase = new String[actual.length];
128 for (int i = 0; i < actual.length; i++)
129 {
130 actualLowerCase[i] = actual[i].toLowerCase();
131 }
132
133 assertContains(message, expectedLowerCase, actualLowerCase);
134 }
135
136 }