1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.dbunit.util;
23
24 import java.sql.Connection;
25 import java.sql.DatabaseMetaData;
26 import java.sql.SQLException;
27
28 import org.dbunit.AbstractHSQLTestCase;
29
30 import com.mockobjects.sql.MockDatabaseMetaData;
31
32
33
34
35
36
37 public class SQLHelperTest extends AbstractHSQLTestCase {
38
39 public SQLHelperTest( String name ) {
40 super( name, "hypersonic_dataset.sql" );
41 }
42
43 public void testGetPrimaryKeyColumn() throws SQLException {
44 String[] tables = { "A", "B", "C", "D", "E", "F", "G", "H" };
45 Connection conn = getConnection().getConnection();
46 assertNotNull( "didn't get a connection", conn );
47 for (int i = 0; i < tables.length; i++) {
48 String table = tables[i];
49 String expectedPK = "PK" + table;
50 String actualPK = SQLHelper.getPrimaryKeyColumn( conn, table );
51 assertNotNull( actualPK );
52 assertEquals( "primary key column for table " + table + " does not match", expectedPK, actualPK );
53 }
54 }
55
56 public void testGetDatabaseInfoWithException() throws Exception{
57 final String productName="Some product";
58 final String exceptionText="Dummy exception to simulate unimplemented operation exception as occurs " +
59 "in sybase 'getDatabaseMajorVersion()' (com.sybase.jdbc3.utils.UnimplementedOperationException)";
60
61 DatabaseMetaData metaData = new MockDatabaseMetaData(){
62 public String getDatabaseProductName() throws SQLException {
63 return productName;
64 }
65 public String getDatabaseProductVersion() throws SQLException{
66 return null;
67 }
68 public int getDriverMajorVersion() {
69 return -1;
70 }
71 public int getDriverMinorVersion() {
72 return -1;
73 }
74 public String getDriverName() throws SQLException {
75 return null;
76 }
77 public String getDriverVersion() throws SQLException {
78 return null;
79 }
80 public int getDatabaseMajorVersion() throws SQLException {
81 throw new SQLException(exceptionText);
82 }
83 public int getDatabaseMinorVersion() throws SQLException {
84 return -1;
85 }
86 };
87 String info = SQLHelper.getDatabaseInfo(metaData);
88 assertNotNull(info);
89 assertTrue(info.indexOf(productName)>-1);
90 assertTrue(info.indexOf(SQLHelper.ExceptionWrapper.NOT_AVAILABLE_TEXT)>-1);
91 }
92 }