/*
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/*
 * @(#)dbMetaClient11.java	1.20 02/01/12
 */

package com.sun.cts.tests.jdbc.ee.dbMeta.dbMeta11;

import java.io.*;
import java.util.*;

import java.sql.*;
import javax.sql.*;

import com.sun.cts.util.*;
import com.sun.cts.porting.*;
import com.sun.cts.harness.*;

import java.rmi.RemoteException;

import javasoft.sqe.javatest.Status;
import com.sun.cts.tests.jdbc.ee.common.*;


// Merant DataSource class
//import com.merant.sequelink.jdbcx.datasource.*;

/**
 * The dbMetaClient11 class tests methods of DatabaseMetaData interface using 
 * Sun's J2EE Reference Implementation.
 * @author  
 * @version 1.7, 06/16/99
 */

public class dbMetaClient11 extends ServiceEETest implements Serializable 
{
	private static final String testName = "jdbc.ee.dbMeta.dbMeta11";

	//Naming specific member variables
	private CTSNamingContextInterface jc = null;

	//Harness requirements 

	private transient Connection conn = null;
	private transient DatabaseMetaData dbmd = null;
	private DataSource ds1 = null;
	private dbSchema dbSch=null;
	private String dbName=null,dbUser=null,drManager=null;
	private String sCatalogName=null,sSchemaName=null,sPtable=null,sFtable=null;

	/* Run test in standalone mode */
	public static void main(String[] args) 
	{
		dbMetaClient11 theTests = new dbMetaClient11();
		Status s=theTests.run(args, System.out, System.err);
		s.exit();
	}

	/* A private method to compare the Column Names & No of Columns Specific to the test */
	private boolean columnCompare( String [] sColumnNames, ResultSet rs) throws SQLException
	{
		
	  	ResultSetMetaData rsmd=null;
		boolean test_status=false;
		boolean statusColumnCount=true;
		boolean statusColumnMatch=true;
		
		int iColumnNamesLength=sColumnNames.length;
		rsmd = rs.getMetaData();				
		int iCount= rsmd.getColumnCount();				
		
		logMsg("Minimum Column Count is:" + iColumnNamesLength);					
				
		// Comparing Column Lengths
		if ( iColumnNamesLength <= iCount )
		{
			iCount=iColumnNamesLength;
			statusColumnCount=true;
		}
		else 
		{	
			statusColumnCount=false;		
		}
		
		
		logMsg("Comparing Column Names...");
						
		while( iColumnNamesLength > 0)						
		{
			if ( sColumnNames[iColumnNamesLength-1].equalsIgnoreCase(rsmd.getColumnName(iCount)) )
			{
					statusColumnMatch=true;
			}
			else
			{
					statusColumnMatch=false;
					break;
			}
			iCount--;
			iColumnNamesLength--;
		}								

		if ( (statusColumnCount==true) && (statusColumnMatch==true))
			test_status=true;

		return test_status;
	}
	
	/*  Test setup: */
	/*
	 *   @class.setup_props: Driver, the Driver name;
	 *                       db1, the database name with url;
	 *                       user1, the database user name;
	 *                       password1, the database password;
	 *                       db2, the database name with url;
	 *                       user2, the database user name;
	 *                       password2, the database password;
	 *                       DriverManager, flag for DriverManager;
	 *                       ptable, the primary table;
	 *                       ftable, the foreign table;
	 *                       cofSize, the initial size of the ptable;
	 *                       cofTypeSize, the initial size of the ftable;
	 *                       binarySize, size of binary data type;
	 *                       varbinarySize, size of varbinary data type;
	 *                       longvarbinarySize, size of longvarbinary data type;
	 *  @class.testArgs:     -ap ctssql.stmt
	 */
	public void setup(String[] args, Properties p) throws Fault 
	{
		try 
		{
			try
			{
				drManager = p.getProperty("DriverManager","");
				dbName = p.getProperty("db1","");
				dbUser = p.getProperty("user1","");
				sPtable = p.getProperty("ptable","CTSTABLE1");
				sFtable = p.getProperty("ftable","CTSTABLE2");
				if (dbName.length() == 0)
					throw new Fault("Invalid db1  Database Name");
				if (dbUser.length() == 0)
					throw new Fault("Invalid Login Id");
				if (sPtable.length() == 0)
					throw new Fault("Invalid Primary table");
				if (sFtable.length() == 0)
					throw new Fault("Invalid Foreign table");
				if (drManager.length() == 0)
					throw new Fault("Invalid DriverManager Name");

				int nLocdbname = dbName.indexOf('=');
				sSchemaName = dbUser;
				
				if(drManager.equals("yes"))
				{
					logMsg("Using DriverManager");
					DriverManagerConnection dmCon = new DriverManagerConnection();
					conn = dmCon.getConnection(p);
				}
				else 
				{
					logMsg("Using DataSource");
					DataSourceConnection dsCon = new DataSourceConnection();
					conn = dsCon.getConnection(p);
				}
				dbSch = new dbSchema();
				dbSch.createData(p,conn);
				dbmd=conn.getMetaData();
			}
			catch(SQLException ex)
			{
				logErr("SQL Exception : " + ex.getMessage());
			}
		} 
		catch ( Exception e ) 
		{
			logErr("Setup Failed!");
			TestUtil.printStackTrace(e);
		}
	}


	/*
	 * @testName:         testSupportsTransactionIsolationLevel2
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The supportsTransactionIsolationLevel(int isolevel) method must 
	 *                    return a boolean value; true if the database supports the given 
	 *                    Transaction Isolation Level isolevel and false otherwise.  The
	 *                    possible values for isolevel can be TRANSACTION_NONE,
	 *                    TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED,
	 *                    TRANSACTION_REPEATABLE_READ and TRANSACTION_SERIALIZABLE.
	 *                    (See JDK 1.2.2 API documentation) 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the supportsTransactionIsolationLevel(int isolevel) method
	 *                    on that object with the isolation level TRANSACTION_READ_COMMITTED.
	 *                    It should return a boolean value; either true or false.
	 *
	 */
	public void testSupportsTransactionIsolationLevel2() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_READ_COMMITTED)");
			//invoke supportsTransactionIsolationLevel method
			boolean retValue = dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_COMMITTED);
			if (retValue)
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_READ_COMMITTED) is supported");
			else
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_READ_COMMITTED) is not supported");
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel2 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel2 is Failed!", e);
		}
	}


	/*
	 * @testName:         testSupportsTransactionIsolationLevel3
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The supportsTransactionIsolationLevel(int isolevel) method must 
	 *                    return a boolean value; true if the database supports the given 
	 *                    Transaction Isolation Level isolevel and false otherwise.  The
	 *                    possible values for isolevel can be TRANSACTION_NONE,
	 *                    TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED,
	 *                    TRANSACTION_REPEATABLE_READ and TRANSACTION_SERIALIZABLE.
	 *                    (See JDK 1.2.2 API documentation)
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the supportsTransactionIsolationLevel(int isolevel) method
	 *                    on that object with the isolation level TRANSACTION_READ_UNCOMMITTED.
	 *                    It should return a boolean value; either true or false.
	 *
	 */
	public void testSupportsTransactionIsolationLevel3() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED)");
			//invoke supportsTransactionIsolationLevel method
			boolean retValue = dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_READ_UNCOMMITTED);
			if (retValue)
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED) is supported");
			else
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_READ_UNCOMMITTED ) is not supported");
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel3 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel3 is Failed!", e);
		}
	}


	/*
	 * @testName:         testSupportsTransactionIsolationLevel4
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The supportsTransactionIsolationLevel(int isolevel) method must 
	 *                    return a boolean value; true if the database supports the given 
	 *                    Transaction Isolation Level isolevel and false otherwise.  The
	 *                    possible values for isolevel can be TRANSACTION_NONE,
	 *                    TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED,
	 *                    TRANSACTION_REPEATABLE_READ and TRANSACTION_SERIALIZABLE.
	 *                    (See JDK 1.2.2 API documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the supportsTransactionIsolationLevel(int isolevel) method
	 *                    on that object with  isolation level TRANSACTION_REPEATABLE_READ.
	 *                    It should return a boolean value; either true or false.
	 *
	 */
	public void testSupportsTransactionIsolationLevel4() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_REPEATABLE_READ)");
			//invoke supportsTransactionIsolationLevel method
			boolean retValue = dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_REPEATABLE_READ);
			if (retValue)
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_REPEATABLE_READ) is supported");
			else
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_REPEATABLE_READ) is not supported");
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel4 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel4 is Failed!", e);
		}
	}


	/*
	 * @testName:         testSupportsTransactionIsolationLevel5
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The supportsTransactionIsolationLevel(int isolevel) method must 
	 *                    return a boolean value; true if the database supports the given 
	 *                    Transaction Isolation Level isolevel and false otherwise.  The
	 *                    possible values for isolevel can be TRANSACTION_NONE,
	 *                    TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED,
	 *                    TRANSACTION_REPEATABLE_READ and TRANSACTION_SERIALIZABLE.
	 *                    (See JDK 1.2.2 API documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the supportsTransactionIsolationLevel(int isolevel) method
	 *                    on that object with  isolation level TRANSACTION_SERIALIZABLE.
	 *                    It should return a boolean value; either true or false.
	 *
	 */
	public void testSupportsTransactionIsolationLevel5() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE)");
			//invoke supportsTransactionIsolationLevel method
			boolean retValue = dbmd.supportsTransactionIsolationLevel(Connection.TRANSACTION_SERIALIZABLE);
			if (retValue)
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE) is supported");
			else
				logMsg("supportsTransactionIsolationLevel(TRANSACTION_SERIALIZABLE) is not supported");
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel5 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to supportsTransactionIsolationLevel5 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetColumnPrivileges
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    getColumnPrivileges(String ctlg,String sch,String tab,String colpat)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column's privileges. (See JDK 1.2.2 API 
	 *                    documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getColumnPrivileges() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.
	 */
	public void testGetColumnPrivileges() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"TABLE_CAT","TABLE_SCHEM","TABLE_NAME","COLUMN_NAME","GRANTOR","GRANTEE","PRIVILEGE","IS_GRANTABLE"}; 
			boolean test_status=true;
			
			logMsg("Calling DatabaseMetaData.getColumnPrivileges");
			//invoke getColumnPrivileges method
			ResultSet oRet_ResultSet = dbmd.getColumnPrivileges(sCatalogName,sSchemaName,sFtable,"%");
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getColumnPrivileges Failed!");
			}
			
			//if necessary we can print the Columnname.privilige values
			if(oRet_ResultSet.next())
				logMsg("getColumnPrivileges returned some column names");
			else
				logMsg("getColumnPrivileges did not return any column names");
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getColumnPrivileges is Failed!", sqle);
		}
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getColumnPrivileges is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetTablePrivileges
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    getTablePrivileges(String clg,String schpat,String tabnamepat)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of the access rights for a table. (See JDK 1.2.2 
	 *                    API documentation)
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getTablePrivileges() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.	
	 */
	public void testGetTablePrivileges() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"TABLE_CAT","TABLE_SCHEM","TABLE_NAME","GRANTOR","GRANTEE","PRIVILEGE","IS_GRANTABLE"}; 
			boolean test_status=true;
			
			logMsg("Calling DatabaseMetaData.getTablePrivileges");
			//invoke getTablePrivileges method
			ResultSet oRet_ResultSet = dbmd.getTablePrivileges(sCatalogName,sSchemaName,sFtable);
			String sRetStr = new String();
			sRetStr = "";
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getTablePrivileges Failed!");
			}
			
			// Store all the privileges returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(6) + ",";
			if(sRetStr == "")
				logMsg("getTablePrivileges did not return any privileges");
			else
				logMsg("The privileges returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getTablePrivileges is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getTablePrivileges is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetBestRowIdentifier1
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetBestRowIdentifier1() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowTemporary with nullable columns");
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowTemporary,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the Columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getBestRowIdentifier with scope bestRowTemporary did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier1 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier1 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetBestRowIdentifier2
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetBestRowIdentifier2() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowTransaction with nullable columns");
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowTransaction,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the Columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getBestRowIdentifier with scope bestRowTransaction did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier2 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier2 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetBestRowIdentifier3
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetBestRowIdentifier3() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowSession with nullable columns");
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowSession,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the Columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getBestRowIdentifier with scope bestRowSession did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier3 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier3 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetBestRowIdentifier4
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetBestRowIdentifier4() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowTemporary without nullable columns");
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowTemporary,false);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the Columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getBestRowIdentifier with scope bestRowTemporary did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier4 is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier4 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetBestRowIdentifier5
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetBestRowIdentifier5() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowTransaction without nullable columns");
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowTransaction,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the Columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getBestRowIdentifier with scope bestRowTransaction did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier5 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier5 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetBestRowIdentifier6
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object
	 *
	 */
	public void testGetBestRowIdentifier6() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowSession without nullable columns");
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowSession,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the Columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getBestRowIdentifier with scope bestRowSession did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier6 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier6 is Failed!", e);
		}
	}


/*
	 * @testName:         testGetBestRowIdentifier7
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getBestRowIdentifier(Str cat, Str sch, Str tab,int scope, boo nflg)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a column that belongs to a optimal set of columns
	 *                    that uniquely identifies a row.  The possible values for scope
	 *                    are bestRowTemporary, bestRowTransaction or bestRowSession 
	 *                    (See JDK 1.2.2 API documentation)
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getBestRowIdentifier() method on that object.
	 *                    It should return a ResultSet object. 
	 *		      Validate the column names and column ordering.
	 */
	public void testGetBestRowIdentifier7() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"SCOPE","COLUMN_NAME","DATA_TYPE","TYPE_NAME","COLUMN_SIZE","BUFFER_LENGTH","DECIMAL_DIGITS","PSEUDO_COLUMN"}; 
			boolean test_status=true; 
			
			logMsg("Calling DatabaseMetaData.getBestRowIdentifier with scope bestRowSession without nullable columns");
			
			//invoke getBestRowIdentifier method
			ResultSet oRet_ResultSet = dbmd.getBestRowIdentifier(sCatalogName,sSchemaName,sFtable,DatabaseMetaData.bestRowSession,true);
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getBestRowIdentifier7 Failed!");
			}
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getBestRowIdentifier7 is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getBestRowIdentifier7 is Failed!", e);
		}
	}

	/*
	 * @testName:         testGetVersionColumns
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getVersionColumns(String calg, String sch, String tab)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a table column that is automatically updated
	 *                    whenever a value in a row is updated.  (See JDK 1.2.2 API 
	 *                    documentation)	 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getVersionColumns() method on that object.
	 *                    It should return a ResultSet object.Compare the column names
	 *		      Validate the column names and column ordering.
	 */
	public void testGetVersionColumns() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"SCOPE","COLUMN_NAME","DATA_TYPE","TYPE_NAME","COLUMN_SIZE","BUFFER_LENGTH","DECIMAL_DIGITS","PSEUDO_COLUMN"}; 
			boolean test_status=true;
			
			logMsg("Calling DatabaseMetaData.getVersionColumns");
			//invoke getVersionColumns method
			ResultSet oRet_ResultSet = dbmd.getVersionColumns(sCatalogName,sSchemaName,sFtable);
			String sRetStr = new String();
			sRetStr = "";
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getVersionColumns Failed!");
			}
			
			// Store all the columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(2) + ",";
			if(sRetStr == "")
				logMsg("getVersionColumns did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getVersionColumns is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getVersionColumns is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetPrimaryKeys
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getPrimaryKeys(String calg, String sch, String tab)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of the given table's primary key column(s).
	 *                    (See JDK 1.2.2 API documentation)	
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getPrimaryKeys() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.
	 */
	public void testGetPrimaryKeys() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"TABLE_CAT","TABLE_SCHEM","TABLE_NAME","COLUMN_NAME","KEY_SEQ","PK_NAME"}; 
			boolean test_status=true;
			
			logMsg("Calling DatabaseMetaData.getPrimaryKeys");
			//invoke getPrimaryKeys method
			ResultSet oRet_ResultSet = dbmd.getPrimaryKeys(sCatalogName,sSchemaName,sFtable);
			String sRetStr = new String();
			sRetStr = "";
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getPrimaryKeys Failed!");
			}
			// Store all the columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(4) + ",";
			if(sRetStr == "")
				logMsg("getPrimaryKeys did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		}
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getPrimaryKeys is Failed!", sqle);
		}
		catch ( Exception e ) 
		{
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getPrimaryKeys is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetImportedKeys
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getImportedKeys(String calg, String sch, String tab)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of a primary key columns that are referenced by a 
	 *                    table's foreign key columns. (See JDK 1.2.2 API documentation)		 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getImportedKeys() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.
	 */
	public void testGetImportedKeys() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"PKTABLE_CAT","PKTABLE_SCHEM","PKTABLE_NAME","PKCOLUMN_NAME","FKTABLE_CAT","FKTABLE_SCHEM","FKTABLE_NAME","FKCOLUMN_NAME","KEY_SEQ","UPDATE_RULE","DELETE_RULE","FK_NAME","PK_NAME","DEFERRABILITY"}; 
			boolean test_status=true;
			
			logMsg("Calling DatabaseMetaData.getImportedKeys");
			//invoke getImportedKeys method
			ResultSet oRet_ResultSet = dbmd.getImportedKeys(sCatalogName,sSchemaName,sFtable);
			String sRetStr = new String();
			sRetStr = "";
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getImportedKeys Failed!");
			}
			
			// Store all the columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(4) + ",";
			if(sRetStr == "")
				logMsg("getImportedKeys did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getImportedKeys is Failed!", sqle );
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getImportedKeys is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetExportedKeys
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getExportedKeys(String calg, String sch, String tab)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of a foreign key that reference a table's primary
	 *                    key columns. (See JDK 1.2.2 API documentation)		 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getExportedKeys() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.
	 */
	public void testGetExportedKeys() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"PKTABLE_CAT","PKTABLE_SCHEM","PKTABLE_NAME","PKCOLUMN_NAME","FKTABLE_CAT","FKTABLE_SCHEM","FKTABLE_NAME","FKCOLUMN_NAME","KEY_SEQ","UPDATE_RULE","DELETE_RULE","FK_NAME","PK_NAME","DEFERRABILITY"}; 
			boolean test_status=true; 
			
			logMsg("Calling DatabaseMetaData.getExportedKeys");
			//invoke getExportedKeys method
			ResultSet oRet_ResultSet = dbmd.getExportedKeys(sCatalogName,sSchemaName,sPtable);
			String sRetStr = new String();
			sRetStr = "";
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getExportedKeys Failed!");
			}
			
			// Store all the columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(8) + ",";
			if(sRetStr == "")
				logMsg("getExportedKeys did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getExportedKeys is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getExportedKeys is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetCrossReference
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getCrossReference(Str prcalg,Str prsch,Str prtab,Str foclg,Str fosch,Str fotab)
	 *                    method must return a ResultSet object with each row is a 
	 *                    description of a foreign key column in a foreign key table.
	 *                    (See JDK 1.2.2 API documentation)		 
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getCrossReference() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.
	 */
	public void testGetCrossReference() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"PKTABLE_CAT","PKTABLE_SCHEM","PKTABLE_NAME","PKCOLUMN_NAME","FKTABLE_CAT","FKTABLE_SCHEM","FKTABLE_NAME","FKCOLUMN_NAME","KEY_SEQ","UPDATE_RULE","DELETE_RULE","FK_NAME","PK_NAME","DEFERRABILITY"}; 
			boolean test_status=true; 
			
			logMsg("Calling DatabaseMetaData.getCrossReference");
			//invoke getCrossReference method
			ResultSet oRet_ResultSet = dbmd.getCrossReference(sCatalogName,sSchemaName,sPtable,sCatalogName,sSchemaName,sFtable);
			String sRetStr = new String();
			sRetStr = "";
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getCrossReference Failed!");
			}
			
			// Store all the columns returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(8) + ",";
			if(sRetStr == "")
				logMsg("getCrossReference did not return any columns");
			else
				logMsg("The columns returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getCrossReference is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getCrossReference is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetIndexInfo1
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getIndexInfo(Str calg,Str sch,Str tab,boolean uni,boolean approx)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of an index column. (See JDK 1.2.2 API documentation)	
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getIndexInfo() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetIndexInfo1() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getIndexInfo with approximate data and without accurate results");
			//invoke getIndexInfo method
			ResultSet oRet_ResultSet = dbmd.getIndexInfo(sCatalogName,sSchemaName,sFtable,true,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the index name returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(6) + ",";
			if(sRetStr == "")
				logMsg("getIndexInfo did not return any index names");
			else
				logMsg("The index names returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getIndexInfo1 is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getIndexInfo1 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetIndexInfo2
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getIndexInfo(Str calg,Str sch,Str tab,boolean uni,boolean approx)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of an index column. (See JDK 1.2.2 API documentation)	
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getIndexInfo() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetIndexInfo2() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getIndexInfo with approximate data and with accurate results");
			//invoke getIndexInfo method
			ResultSet oRet_ResultSet = dbmd.getIndexInfo(sCatalogName,sSchemaName,sFtable,true,false);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the index name returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(6) + ",";
			if(sRetStr == "")
				logMsg("getIndexInfo did not return any index names");
			else
				logMsg("The index names returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getIndexInfo2 is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getIndexInfo2 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetIndexInfo3
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getIndexInfo(Str calg,Str sch,Str tab,boolean uni,boolean approx)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of an index column. (See JDK 1.2.2 API documentation)	
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getIndexInfo() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetIndexInfo3() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getIndexInfo without approximate data and with accurate results");
			//invoke getIndexInfo method
			ResultSet oRet_ResultSet = dbmd.getIndexInfo(sCatalogName,sSchemaName,sFtable,false,false);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the index name returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(6) + ",";
			if(sRetStr == "")
				logMsg("getIndexInfo did not return any index names");
			else
				logMsg("The index names returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getIndexInfo3 is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getIndexInfo3 is Failed!", e);
		}
	}


	/*
	 * @testName:         testGetIndexInfo4
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getIndexInfo(Str calg,Str sch,Str tab,boolean uni,boolean approx)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of an index column. (See JDK 1.2.2 API documentation)	
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getIndexInfo() method on that object.
	 *                    It should return a ResultSet object.
	 *
	 */
	public void testGetIndexInfo4() throws Fault 
	{
		try 
		{
			logMsg("Calling DatabaseMetaData.getIndexInfo without approximate data and without accurate results");
			//invoke getIndexInfo method
			ResultSet oRet_ResultSet = dbmd.getIndexInfo(sCatalogName,sSchemaName,sFtable,false,true);
			String sRetStr = new String();
			sRetStr = "";
			// Store all the index name returned
			while(oRet_ResultSet.next())
				sRetStr += oRet_ResultSet.getString(6) + ",";
			if(sRetStr == "")
				logMsg("getIndexInfo did not return any index names");
			else
				logMsg("The index names returned Are : " + sRetStr.substring(0,sRetStr.length() - 1));
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getIndexInfo4 is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getIndexInfo4 is Failed!", e);
		}
	}


/*
	 * @testName:         testGetIndexInfo5
	 * @assertion:        The DatabaseMetaData provides information about the database.
	 *                    (See section 15.1 of JDBC 2.0 API Reference & Tutorial 2nd edition)
	 *                     
	 *                    A  driver must provide full support for DatabaseMetaData and 
	 *                    ResultSetMetaData.  This implies that all of the methods in the 
	 *                    DatabaseMetaData interface must be implemented and must behave as 
	 *                    specified in the JDBC 1.0 and 2.0 specifications.  None of the 
	 *                    methods in DatabaseMetaData and ResultSetMetaData may throw an 
	 *                    exception because they are not implemented. (See section 6.2.2.3 
	 *                    of Java2 Platform Enterprise Edition (J2EE) Specification v1.2)
	 *                    The getIndexInfo(Str calg,Str sch,Str tab,boolean uni,boolean approx)
	 *                    method must return a ResultSet object with each row is a
	 *                    description of an index column. (See JDK 1.2.2 API documentation)	
	 *
	 * @test_Strategy:    Get a DatabaseMetadata object from the connection to the database
	 *                    and call the getIndexInfo() method on that object.
	 *                    It should return a ResultSet object.
	 *		      Validate the column names and column ordering.
	 */
	public void testGetIndexInfo5() throws Fault 
	{
		try 
		{
			String sColumnNames[]={"TABLE_CAT","TABLE_SCHEM","TABLE_NAME","NON_UNIQUE","INDEX_QUALIFIER","INDEX_NAME","TYPE","ORDINAL_POSITION","COLUMN_NAME","ASC_OR_DESC","CARDINALITY","PAGES","FILTER_CONDITION"}; 
			boolean test_status=true; 
			
			logMsg("Calling DatabaseMetaData.getIndexInfo without approximate data and without accurate results");
			//invoke getIndexInfo method
			ResultSet oRet_ResultSet = dbmd.getIndexInfo(sCatalogName,sSchemaName,sFtable,false,true);
			
			// Call to columnCompare for the exact match of column names
			test_status=columnCompare(sColumnNames,oRet_ResultSet);
			if( test_status==false ) 
			{			
				logMsg("Columns return are not same either in order or name");
				throw new Fault("Call to getCrossReference Failed!");
			}
					
		} 
		catch ( SQLException sqle )
		{
			logErr("SQL Exception " + sqle.getMessage());
			throw new Fault("Call to getIndexInfo4 is Failed!", sqle);
		}	
		catch ( Exception e ) 
		{ 
			logErr("Unexpected Exception " + e.getMessage());
			throw new Fault("Call to getIndexInfo4 is Failed!", e);
		}
	}


	/* cleanup */
	public void  cleanup() throws Fault	
	{
		try
		{
			// Close the database 
			dbSch.destroyData(conn);
			dbSch.dbUnConnect(conn);
			logMsg("Cleanup ok;");
		}
		catch (Exception e)
		{
			logErr("An error occurred while closing the database connection");
		}	
	}
}

