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