View Javadoc
1   package org.dbunit;
2   
3   import java.io.File;
4   import java.sql.Connection;
5   import java.util.Set;
6   
7   import junit.framework.TestCase;
8   
9   import org.dbunit.database.DatabaseConfig;
10  import org.dbunit.database.DatabaseConnection;
11  import org.dbunit.database.IDatabaseConnection;
12  import org.dbunit.ext.hsqldb.HsqldbDataTypeFactory;
13  import org.dbunit.testutil.TestUtils;
14  import org.dbunit.util.CollectionsHelper;
15  
16  import org.slf4j.Logger;
17  import org.slf4j.LoggerFactory;
18  
19  public abstract class AbstractHSQLTestCase extends TestCase {
20    
21    public static final String A = "A";
22    public static final String B = "B";
23    public static final String C = "C";
24    public static final String D = "D";
25    public static final String E = "E";
26    public static final String F = "F";
27    public static final String G = "G";
28    public static final String H = "H";
29    
30    public static final String A1 = "A1";
31    public static final String B1 = "B1";
32    public static final String C1 = "C1";
33    public static final String D1 = "D1";
34    public static final String E1 = "E1";
35    public static final String F1 = "F1";
36    public static final String G1 = "G1";
37    public static final String H1 = "H1";
38  
39    public static final String A2 = "A2";
40    public static final String B2 = "B2";
41    public static final String C2 = "C2";
42    public static final String D2 = "D2";
43    public static final String E2 = "E2";
44    public static final String F2 = "F2";
45    public static final String G2 = "G2";
46    public static final String H2 = "H2";
47    
48    public static final String C3 = "C3";
49    public static final String E3 = "E3";
50    
51    public static final String C4 = "C4";
52    public static final String E4 = "E4";
53    
54    public static final String B3 = "B3";
55    public static final String B4 = "B4";
56    public static final String B5 = "B5";
57    public static final String B6 = "B6";
58    public static final String B7 = "B7";
59    public static final String B8 = "B8";  
60    
61    private Connection jdbcConnection;
62    private final String sqlFile;
63    private IDatabaseConnection connection;
64    
65    protected final Logger logger = LoggerFactory.getLogger(getClass());
66  
67    public AbstractHSQLTestCase(String testName, String sqlFile) {
68      super(testName);
69      this.sqlFile = sqlFile;
70    }
71  
72    protected void setUp() throws Exception {
73      super.setUp();
74  
75      this.jdbcConnection = HypersonicEnvironment.createJdbcConnection("mem:tempdb");
76      HypersonicEnvironment.executeDdlFile(TestUtils.getFile(
77          "sql/" + sqlFile), jdbcConnection);
78      this.connection = new DatabaseConnection(jdbcConnection);
79      DatabaseConfig config = connection.getConfig();
80      config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
81              new HsqldbDataTypeFactory());
82    }
83  
84    protected void tearDown() throws Exception {
85      super.tearDown();
86  
87      HypersonicEnvironment.shutdown(this.jdbcConnection);
88      this.jdbcConnection.close();
89    }
90  
91    protected IDatabaseConnection getConnection() {
92      return this.connection;
93    }
94  
95    protected static String dump(String[] parent) {
96      StringBuffer buffer = new StringBuffer("[ " + parent[0]);
97      for (int i = 1; i < parent.length; i++) {
98        buffer.append(", " + parent[i]);
99      }
100     buffer.append(" ]");
101     return buffer.toString();
102   }
103 
104   public static String dump(Set set) {
105     String[] strings= CollectionsHelper.setToStrings(set);
106     return dump(strings);
107   }
108 
109 }