1 21 package org.dbunit.dataset.filter; 22 23 import org.dbunit.dataset.*; 24 25 import java.util.Arrays ; 26 27 32 public class ExcludeTableFilterTest extends AbstractTableFilterTest 33 { 34 static final String MATCHING_NAME = "aBcDe"; 35 static final String [] MATCHING_PATTERNS = 36 IncludeTableFilterTest.MATCHING_PATTERNS; 37 static final String [] NONMATCHING_PATTERNS = 38 IncludeTableFilterTest.NONMATCHING_PATTERNS; 39 40 public ExcludeTableFilterTest(String s) 41 { 42 super(s); 43 } 44 45 public void testAccept() throws Exception 46 { 47 String [] validNames = getExpectedNames(); 48 ExcludeTableFilter filter = new ExcludeTableFilter(); 49 filter.excludeTable(getExtraTableName()); 50 51 for (int i = 0; i < validNames.length; i++) 52 { 53 String validName = validNames[i]; 54 assertEquals(validName, true, filter.accept(validName)); 55 } 56 } 57 58 public void testIsCaseInsensitiveValidName() throws Exception 59 { 60 String [] validNames = getExpectedNames(); 61 ExcludeTableFilter filter = new ExcludeTableFilter(); 62 filter.excludeTable(getExtraTableName()); 63 64 for (int i = 0; i < validNames.length; i++) 65 { 66 String validName = validNames[i]; 67 assertEquals(validName, true, filter.accept(validName)); 68 } 69 } 70 71 public void testIsValidNameAndInvalid() throws Exception 72 { 73 String [] invalidNames = new String [] { 74 "INVALID_TABLE", 75 "UNKNOWN_TABLE", 76 }; 77 ITableFilter filter = new ExcludeTableFilter(invalidNames); 78 79 for (int i = 0; i < invalidNames.length; i++) 80 { 81 String invalidName = invalidNames[i]; 82 assertEquals(invalidName, false, filter.accept(invalidName)); 83 } 84 } 85 86 public void testGetTableNames() throws Exception 87 { 88 String [] expectedNames = getExpectedNames(); 89 ExcludeTableFilter filter = new ExcludeTableFilter(); 90 filter.excludeTable(getExtraTableName()); 91 92 IDataSet dataSet = createDataSet(); 93 assertTrue("dataset names count", 94 dataSet.getTableNames().length > expectedNames.length); 95 96 String [] actualNames = filter.getTableNames(dataSet); 97 assertEquals("name count", expectedNames.length, actualNames.length); 98 assertEquals("names", 99 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 100 } 101 102 public void testGetTableNamesAndTableNotInDecoratedDataSet() throws Exception 103 { 104 String [] expectedNames = getExpectedNames(); 105 ExcludeTableFilter filter = new ExcludeTableFilter(); 106 filter.excludeTable(getExtraTableName()); 107 filter.excludeTable("UNKNOWN_TABLE"); 108 109 IDataSet dataSet = createDataSet(); 110 assertTrue("dataset names count", 111 dataSet.getTableNames().length > expectedNames.length); 112 113 String [] actualNames = filter.getTableNames(dataSet); 114 assertEquals("name count", expectedNames.length, actualNames.length); 115 assertEquals("names", 116 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 117 } 118 119 public void testGetDuplicateTableNames() throws Exception 120 { 121 String [] expectedNames = getExpectedDuplicateNames(); 122 ExcludeTableFilter filter = new ExcludeTableFilter(); 123 filter.excludeTable(getExtraTableName()); 124 125 IDataSet dataSet = createDuplicateDataSet(); 126 assertTrue("dataset names count", 127 dataSet.getTableNames().length > expectedNames.length); 128 129 String [] actualNames = filter.getTableNames(dataSet); 130 assertEquals("name count", expectedNames.length, actualNames.length); 131 assertEquals("names", 132 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 133 } 134 135 public void testGetCaseInsensitiveTableNames() throws Exception 136 { 137 ExcludeTableFilter filter = new ExcludeTableFilter(); 138 filter.excludeTable(getExtraTableName()); 139 140 String [] expectedNames = getExpectedLowerNames(); 141 IDataSet dataSet = new LowerCaseDataSet(createDataSet()); 142 assertTrue("dataset names count", 143 dataSet.getTableNames().length > expectedNames.length); 144 145 String [] actualNames = filter.getTableNames(dataSet); 146 assertEquals("name count", expectedNames.length, actualNames.length); 147 assertEquals("names", 148 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 149 } 150 151 public void testGetReverseTableNames() throws Exception 152 { 153 } 155 156 public void testIterator() throws Exception 157 { 158 String [] expectedNames = getExpectedNames(); 159 ExcludeTableFilter filter = new ExcludeTableFilter(); 160 filter.excludeTable(getExtraTableName()); 161 162 IDataSet dataSet = createDataSet(); 163 assertTrue("dataset names count", 164 dataSet.getTableNames().length > expectedNames.length); 165 166 ITable[] actualTables = DataSetUtils.getTables( 167 filter.iterator(dataSet, false)); 168 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 169 assertEquals("table count", expectedNames.length, actualTables.length); 170 assertEquals("table names", 171 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 172 } 173 174 public void testIteratorWithDuplicateTables() throws Exception 175 { 176 String [] expectedNames = getExpectedDuplicateNames(); 177 ExcludeTableFilter filter = new ExcludeTableFilter(); 178 filter.excludeTable(getExtraTableName()); 179 180 IDataSet dataSet = createDuplicateDataSet(); 181 assertTrue("dataset names count", 182 dataSet.getTableNames().length > expectedNames.length); 183 184 ITable[] actualTables = DataSetUtils.getTables( 185 filter.iterator(dataSet, false)); 186 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 187 assertEquals("table count", expectedNames.length, actualTables.length); 188 assertEquals("table names", 189 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 190 } 191 192 public void testCaseInsensitiveIterator() throws Exception 193 { 194 ExcludeTableFilter filter = new ExcludeTableFilter(); 195 filter.excludeTable(getExtraTableName()); 196 197 String [] expectedNames = getExpectedLowerNames(); 198 IDataSet dataSet = new LowerCaseDataSet(createDataSet()); 199 assertTrue("dataset names count", 200 dataSet.getTableNames().length > expectedNames.length); 201 202 ITable[] actualTables = DataSetUtils.getTables( 203 filter.iterator(dataSet, false)); 204 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 205 assertEquals("table count", expectedNames.length, actualTables.length); 206 assertEquals("table names", 207 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 208 } 209 210 public void testReverseIterator() throws Exception 211 { 212 } 214 215 public void testIteratorAndTableNotInDecoratedDataSet() throws Exception 216 { 217 String [] expectedNames = getExpectedNames(); 218 ExcludeTableFilter filter = new ExcludeTableFilter(); 219 filter.excludeTable(getExtraTableName()); 220 filter.excludeTable("UNKNOWN_TABLE"); 221 222 IDataSet dataSet = createDataSet(); 223 assertTrue("dataset names count", 224 dataSet.getTableNames().length > expectedNames.length); 225 226 ITable[] actualTables = DataSetUtils.getTables( 227 filter.iterator(dataSet, false)); 228 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 229 assertEquals("table count", expectedNames.length, actualTables.length); 230 assertEquals("table names", 231 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 232 } 233 234 236 public void testIsValidNameWithPatterns() throws Exception 237 { 238 String validName = MATCHING_NAME; 239 240 String [] patterns = NONMATCHING_PATTERNS; 241 for (int i = 0; i < patterns.length; i++) 242 { 243 String pattern = patterns[i]; 244 ExcludeTableFilter filter = new ExcludeTableFilter(); 245 filter.excludeTable(pattern); 246 assertEquals(pattern, true, filter.accept(validName)); 247 } 248 } 249 250 public void testIsValidNameInvalidWithPatterns() throws Exception 251 { 252 String validName = MATCHING_NAME; 253 254 String [] patterns = MATCHING_PATTERNS; 255 for (int i = 0; i < patterns.length; i++) 256 { 257 String pattern = patterns[i]; 258 ExcludeTableFilter filter = new ExcludeTableFilter(); 259 filter.excludeTable(pattern); 260 assertEquals(pattern, false, filter.accept(validName)); 261 } 262 } 263 264 public void testGetTableNamesWithPatterns() throws Exception 265 { 266 String nonMatchingName = "toto titi tata"; 267 String [] expectedNames = new String [] {nonMatchingName}; 268 IDataSet dataSet = new DefaultDataSet(new ITable[] { 269 new DefaultTable(MATCHING_NAME), 270 new DefaultTable(nonMatchingName), 271 }); 272 assertTrue("dataset names count", 273 dataSet.getTableNames().length > expectedNames.length); 274 275 String [] patterns = MATCHING_PATTERNS; 276 for (int i = 0; i < patterns.length; i++) 277 { 278 String pattern = patterns[i]; 279 ExcludeTableFilter filter = new ExcludeTableFilter(); 280 filter.excludeTable(pattern); 281 282 if (pattern.equals("*")) 284 { 285 String [] actualNames = filter.getTableNames(dataSet); 286 assertEquals("name count - " + pattern, 287 0, actualNames.length); 288 } 289 else 290 { 291 String [] actualNames = filter.getTableNames(dataSet); 292 assertEquals("name count - " + pattern, 293 expectedNames.length, actualNames.length); 294 assertEquals("names - " + pattern, 295 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 296 } 297 } 298 } 299 300 public void testGetTableNamesWithNonMatchingPatterns() throws Exception 301 { 302 String [] expectedNames = new String [] {MATCHING_NAME}; 303 IDataSet dataSet = new DefaultDataSet(new ITable[] { 304 new DefaultTable(MATCHING_NAME), 305 }); 306 307 String [] patterns = NONMATCHING_PATTERNS; 308 for (int i = 0; i < patterns.length; i++) 309 { 310 String pattern = patterns[i]; 311 ExcludeTableFilter filter = new ExcludeTableFilter(); 312 filter.excludeTable(pattern); 313 314 String [] actualNames = filter.getTableNames(dataSet); 315 assertEquals("name count - " + pattern, 316 expectedNames.length, actualNames.length); 317 assertEquals("names - " + pattern, 318 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 319 } 320 } 321 322 public void testGetTablesWithPatterns() throws Exception 323 { 324 String nonMatchingName = "toto titi tata"; 325 String [] expectedNames = new String [] {nonMatchingName}; 326 IDataSet dataSet = new DefaultDataSet(new ITable[] { 327 new DefaultTable(MATCHING_NAME), 328 new DefaultTable(nonMatchingName), 329 }); 330 assertTrue("dataset names count", 331 dataSet.getTableNames().length > expectedNames.length); 332 333 String [] patterns = MATCHING_PATTERNS; 334 for (int i = 0; i < patterns.length; i++) 335 { 336 String pattern = patterns[i]; 337 ExcludeTableFilter filter = new ExcludeTableFilter(); 338 filter.excludeTable(pattern); 339 340 if (pattern.equals("*")) 342 { 343 ITable[] actualTables = DataSetUtils.getTables( 344 filter.iterator(dataSet, false)); 345 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 346 assertEquals("table count - " + pattern, 347 0, actualNames.length); 348 } 349 else 350 { 351 ITable[] actualTables = DataSetUtils.getTables( 352 filter.iterator(dataSet, false)); 353 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 354 assertEquals("table count - " + pattern, 355 expectedNames.length, actualTables.length); 356 assertEquals("table names - " + pattern, 357 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 358 } 359 } 360 } 361 362 public void testGetTablesWithNonMatchingPatterns() throws Exception 363 { 364 String [] expectedNames = new String [] {MATCHING_NAME}; 365 IDataSet dataSet = new DefaultDataSet(new ITable[] { 366 new DefaultTable(MATCHING_NAME), 367 }); 368 assertTrue("dataset names count", 369 dataSet.getTableNames().length > 0); 370 371 String [] patterns = NONMATCHING_PATTERNS; 372 for (int i = 0; i < patterns.length; i++) 373 { 374 String pattern = patterns[i]; 375 ExcludeTableFilter filter = new ExcludeTableFilter(); 376 filter.excludeTable(pattern); 377 378 ITable[] actualTables = DataSetUtils.getTables( 379 filter.iterator(dataSet, false)); 380 String [] actualNames = new DefaultDataSet(actualTables).getTableNames(); 381 assertEquals("table count - " + pattern, 382 expectedNames.length, actualTables.length); 383 assertEquals("table names - " + pattern, 384 Arrays.asList(expectedNames), Arrays.asList(actualNames)); 385 } 386 } 387 388 } 389 | Popular Tags |