1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.database.search;
22
23 import java.io.File;
24 import java.sql.Connection;
25 import java.util.Set;
26
27 import junit.framework.TestCase;
28 import junitx.framework.ArrayAssert;
29
30 import org.dbunit.database.DatabaseConnection;
31 import org.dbunit.database.IDatabaseConnection;
32
33 import org.dbunit.HypersonicEnvironment;
34 import org.dbunit.testutil.TestUtils;
35 import org.dbunit.util.CollectionsHelper;
36 import org.dbunit.util.search.DepthFirstSearch;
37 import org.dbunit.util.search.ISearchCallback;
38
39
40
41
42
43
44 public abstract class AbstractMetaDataBasedSearchCallbackTestCase extends TestCase {
45
46 private final String sqlFile;
47
48 private Connection jdbcConnection;
49
50 private IDatabaseConnection connection;
51
52 public AbstractMetaDataBasedSearchCallbackTestCase(String testName, String sqlFile) {
53 super(testName );
54 this.sqlFile = sqlFile;
55 }
56
57 protected void setUp() throws Exception {
58 this.jdbcConnection = HypersonicEnvironment.createJdbcConnection("mem:tempdb");
59 HypersonicEnvironment.executeDdlFile(
60 TestUtils.getFile("sql/" + this.sqlFile),
61 this.jdbcConnection
62 );
63 this.connection = new DatabaseConnection(jdbcConnection);
64 }
65
66 protected void tearDown() throws Exception {
67 HypersonicEnvironment.shutdown(this.jdbcConnection);
68 this.jdbcConnection.close();
69
70 }
71
72 protected IDatabaseConnection getConnection() {
73 return this.connection;
74 }
75
76 protected abstract String[][] getInput();
77
78 protected abstract String[][] getExpectedOutput();
79
80 protected abstract AbstractMetaDataBasedSearchCallback getCallback(IDatabaseConnection connection2);
81
82 public void testAllInput() throws Exception {
83 IDatabaseConnection connection = getConnection();
84
85 String[][] allInput = getInput();
86 String[][] allExpectedOutput = getExpectedOutput();
87 ISearchCallback callback = getCallback(connection);
88 for (int i = 0; i < allInput.length; i++) {
89 String[] input = allInput[i];
90 String[] expectedOutput = allExpectedOutput[i];
91 DepthFirstSearch search = new DepthFirstSearch();
92 Set result = search.search( input, callback );
93 String[] actualOutput = CollectionsHelper.setToStrings( result );
94 ArrayAssert.assertEquals( "output didn't match for i=" + i, expectedOutput, actualOutput );
95 }
96 }
97
98
99
100 }