| 1 21 22 package org.apache.derbyTesting.functionTests.tests.tools; 23 24 import java.io.UnsupportedEncodingException ; 25 import java.sql.Connection ; 26 import java.sql.SQLException ; 27 import java.sql.Statement ; 28 29 import junit.framework.Test; 30 import junit.framework.TestSuite; 31 32 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 33 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup; 34 35 39 public class IJRunScriptTest extends BaseJDBCTestCase { 40 41 public static Test suite() 42 { 43 TestSuite suite = new TestSuite(); 44 suite.addTestSuite(IJRunScriptTest.class); 45 return new CleanDatabaseTestSetup(suite); 46 } 47 48 public IJRunScriptTest(String name) 49 { 50 super(name); 51 } 52 53 59 public void testScriptExecution() 60 throws SQLException , UnsupportedEncodingException  61 { 62 runTestingScript("CREATE TABLE T1(I INT);\nCREATE TABLE T2(I INT)", 0); 63 64 66 Statement s = createStatement(); 67 68 assertEquals(2, s.executeUpdate("INSERT INTO T1 VALUES 1,2")); 70 71 assertEquals(3, s.executeUpdate("INSERT INTO T2 VALUES 1,2,4")); 73 74 runTestingScript("DROP TABLE T1;DROP TABLE T2", 0); 75 76 s.close(); 77 } 78 79 84 public void testEmptyScript() 85 throws SQLException , UnsupportedEncodingException  86 { 87 runTestingScript("", 0); 88 } 89 90 95 public void testAutoCommitCommand() 96 throws SQLException , UnsupportedEncodingException  97 { 98 Connection conn = getConnection(); 99 assertTrue(conn.getAutoCommit()); 100 runTestingScript("AUTOCOMMIT OFF;", 0); 101 102 assertFalse(conn.isClosed()); 103 assertFalse(conn.getAutoCommit()); 104 } 105 106 111 public void testErrorsCount() 112 throws SQLException , UnsupportedEncodingException  113 { 114 runTestingScript("CREATE TAAABLE T (I INT);", 1); 116 runTestingScript("INSERT INTO TIJ VALUES 1;", 1); 117 118 runTestingScript("INSERT INTO TIJ VALUES 1;\nDELETE FROM SYS.SYSTABLES", 2); 120 runTestingScript("INSERT INTO TIJ VALUES 1;DELETE FROM SYS.SYSTABLES", 2); 121 122 runTestingScript("CREATX TABLE TIJME(I INT);CREATE TABLE TIJME(I INT);" + 124 "INSERT INTO TIJME VALUES 1,3,4;" + 125 "INSERT INTO TIJME VALUESS 1,3,4;" + 126 "DROP TABLE TIJME" 127 , 2); 128 129 } 130 131 132 141 private void runTestingScript(String script, int expectedErrorCount) 142 throws UnsupportedEncodingException , SQLException  143 { 144 int errorCount = runSQLCommands(script); 145 assertEquals("Error count on " + script, 146 expectedErrorCount, errorCount ); 147 } 148 149 } 150 | Popular Tags |