*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* ---------------
* TestExceptions.java
* ---------------
* Author: Volker Berlin
*
*/
package smallsql.junit;
import junit.framework.*;
import java.sql.*;
public class TestExceptions extends BasicTestCase {
private TestValue testValue;
private static boolean init;
private static final TestValue[] TESTS = new TestValue[]{
a(null , 0, "SELECT 23 FROM"), a(null , 0, "SELECT c FROM exceptions Group By i"), a(null , 0, "SELECT first(c) FROM exceptions Group By i ORDER by c"), a(null , 0, "SELECT 1 ORDER BY substring('qwert', 2, -3)"),
};
TestExceptions(TestValue testValue){
super(testValue.sql);
this.testValue = testValue;
}
private void init() throws Exception{
if(init) return;
Connection con = AllTests.getConnection();
Statement st = con.createStatement();
dropTable( con, "exceptions");
st.execute("Create Table exceptions (c varchar(30), i int)");
init = true;
}
public void runTest() throws Exception{
init();
Connection con = AllTests.getConnection();
Statement st = con.createStatement();
ResultSet rs = null;
try{
rs = st.executeQuery( testValue.sql );
}catch(SQLException sqle){
assertEquals( "SQLState wrong", testValue.sqlstate, sqle.getSQLState() );
assertEquals( "Error Code wrong", testValue.errorCode, sqle.getErrorCode() );
}
assertNull(rs);
}
public static Test suite() throws Exception{
TestSuite theSuite = new TestSuite("Exceptions");
for(int i=0; i<TESTS.length; i++){
theSuite.addTest(new TestExceptions( TESTS[i] ) );
}
return theSuite;
}
private static TestValue a(String sqlstate, int errorCode, String sql ){
TestValue value = new TestValue();
value.sql = sql;
value.sqlstate = sqlstate;
value.errorCode = errorCode;
return value;
}
private static class TestValue{
String sql;
String sqlstate;
int errorCode;
}
}