package test; import junit.framework.*; import java.sql.*; import net.ivoa.SkyNode.*; public class TestTables extends TestCase { Connection db; Statement st; // Our statement to run queries with MetaTable[] tNames; public void testTables() { ncsa.nvo.skynode.Configure config = new ncsa.nvo.skynode.Configure("/Configure.xml"); String dbDriver = config.getConfigParam("JDBCDriver")[0]; // Get the db parameters String jdbcUrl = config.getConfigParam("JDBCurl")[0]; String userName = config.getConfigParam("Username")[0]; String passWord = config.getConfigParam("Password")[0]; try { Class.forName(dbDriver); } catch (ClassNotFoundException e) { System.out.println( "JDBC Driver class not found: " + dbDriver + "\n" + "Check the JDBCDriver tag in Configure.xml" ); Assert.fail("JDBC Driver not found."); } try { db = DriverManager.getConnection (jdbcUrl, userName, passWord); } catch (java.sql.SQLException e) { System.out.println( "Cannot connect to the database: " + jdbcUrl + "\n" + "Check the JDBCurl, Username and Password tags in Configure.xml" ); Assert.fail("Can't Connect to database."); } //List tables try { DatabaseMetaData dbmd = db.getMetaData(); ResultSet rs = dbmd.getTables(null, null, null, null); boolean existExclude = true; boolean existInclude = true; String[] excludeTables = config.getConfigParam("ExcludeTable"); String[] includeTables = config.getConfigParam("IncludeTable"); if (excludeTables.length == 1 && excludeTables[0].equals("")) existExclude = false; if (includeTables.length == 1 && includeTables[0].equals("")) existInclude = false; //Get Table description parameters from Config file String[] metTabName = config.getConfigParam("TableName"); String[] metTabDesc = config.getConfigParam("TableDescription"); if(existInclude) { //Find out how many tables we are returning // Should match number of includeTables int count = 0; while(rs.next()) { String temp = ""; for (int i=0;i= 0 //Find out how many tables we are returning int count = 0; while(rs.next()) { count++; } if(existExclude) { tNames = new MetaTable[count - excludeTables.length]; } else { tNames = new MetaTable[count]; } rs = dbmd.getTables(null, "public", null, null); int num = 0; while (rs.next()) { boolean includeTable = true; String temp = rs.getString(3); for (int i=0;i