001 package com.sptci.rwt;
002
003 import java.sql.Connection;
004 import java.sql.Statement;
005
006 import static junit.framework.Assert.*;
007 import junit.framework.Test;
008 import junit.framework.TestCase;
009 import junit.framework.TestSuite;
010
011 import com.sptci.util.CloseJDBCResources;
012
013 /**
014 * Unit test for closing a JDBC {@link java.sql.Connection} through
015 * {@link ConnectionFactory#close} method.
016 *
017 * <p>© Copyright 2007 <a href='http://sptci.com/' target='_new'>Sans Pareil Technologies, Inc.</a></p>
018 *
019 * @author Rakesh Vidyadharan 2007-09-25
020 * @version $Id: DeleteTestObjects.java 4123 2008-05-25 21:49:01Z rakesh $
021 */
022 public class DeleteTestObjects extends TestCase
023 {
024 public static Test suite()
025 {
026 return new TestSuite( DeleteTestObjects.class );
027 }
028
029 /**
030 * Drop the test tables and objects created for testing.
031 */
032 public void testDrop() throws Exception
033 {
034 String ddl = "drop trigger $TRIGGERNAME$ on $REFTABLENAME$;\n" +
035 "drop function $FUNCTIONNAME$();\n" +
036 "drop view $VIEWNAME$;\n" +
037 "drop index $INDEXNAME$;\n" +
038 "drop table $REFTABLENAME$;\n" +
039 "drop table $TABLENAME$;\n" +
040 "drop sequence $SEQUENCENAME$;\n";
041 ddl = ddl.replaceAll( "\\$TABLENAME\\$", CreateTestObjects.tableName );
042 ddl = ddl.replaceAll( "\\$REFTABLENAME\\$", CreateTestObjects.refTableName );
043 ddl = ddl.replaceAll( "\\$VIEWNAME\\$", CreateTestObjects.viewName );
044 ddl = ddl.replaceAll( "\\$FUNCTIONNAME\\$", CreateTestObjects.functionName );
045 ddl = ddl.replaceAll( "\\$TRIGGERNAME\\$", CreateTestObjects.triggerName );
046 ddl = ddl.replaceAll( "\\$SEQUENCENAME\\$", CreateTestObjects.sequenceName );
047 ddl = ddl.replaceAll( "\\$INDEXNAME\\$", CreateTestObjects.indexName );
048 Connection connection = null;
049 Statement statement = null;
050
051 try
052 {
053 connection = CreateTestObjects.manager.open();
054 statement = connection.createStatement();
055 statement.execute( ddl );
056 }
057 finally
058 {
059 CloseJDBCResources.close( statement );
060 CloseJDBCResources.close( connection );
061 }
062
063 System.out.format( "Dropped test tables: %s, %s and view: %s%n",
064 CreateTestObjects.tableName, CreateTestObjects.refTableName,
065 CreateTestObjects.viewName );
066 }
067 }