1 19 20 package org.apache.derbyTesting.functionTests.tests.jdbc4; 21 22 import java.sql.Connection ; 23 import java.sql.PreparedStatement ; 24 import java.sql.SQLException ; 25 import java.sql.SQLFeatureNotSupportedException ; 26 import java.sql.Types ; 27 import junit.framework.Test; 28 import junit.framework.TestSuite; 29 30 import org.apache.derbyTesting.junit.BaseJDBCTestCase; 31 32 40 public class SetObjectUnsupportedTest extends BaseJDBCTestCase { 41 42 private final TypeInfo typeInfo; 43 45 private final boolean callable; 46 47 56 private SetObjectUnsupportedTest(String name, TypeInfo typeInfo, 57 boolean callable) { 58 super(name); 59 this.typeInfo = typeInfo; 60 this.callable = callable; 61 } 62 63 66 public String getName() { 67 return super.getName() + "_" + typeInfo.name; 68 } 69 70 77 private PreparedStatement prepare() throws SQLException { 78 String sql = "values (CAST (? AS VARCHAR(128)))"; 79 return callable ? prepareCall(sql) : prepareStatement(sql); 80 } 81 82 89 public void testUnsupportedSetObject() throws SQLException { 90 PreparedStatement ps = prepare(); 91 try { 92 ps.setObject(1, null, typeInfo.type); 93 fail("No exception thrown."); 94 } catch (SQLFeatureNotSupportedException e) { 95 } 97 ps.close(); 98 } 99 100 107 public void testUnsupportedSetObjectWithScale() throws SQLException { 108 PreparedStatement ps = prepare(); 109 try { 110 ps.setObject(1, null, typeInfo.type, 0); 111 fail("No exception thrown."); 112 } catch (SQLFeatureNotSupportedException e) { 113 } 115 ps.close(); 116 } 117 118 125 public void testUnsupportedSetNull() throws SQLException { 126 PreparedStatement ps = prepare(); 127 try { 128 ps.setNull(1, typeInfo.type); 129 fail("No exception thrown."); 130 } catch (SQLFeatureNotSupportedException e) { 131 } 133 ps.close(); 134 } 135 136 143 public void testUnsupportedSetNullWithTypeName() throws SQLException { 144 PreparedStatement ps = prepare(); 145 try { 146 ps.setNull(1, typeInfo.type, typeInfo.name); 147 fail("No exception thrown."); 148 } catch (SQLFeatureNotSupportedException e) { 149 } 151 ps.close(); 152 } 153 154 157 private static final TypeInfo[] TYPES = { 158 new TypeInfo("ARRAY", Types.ARRAY), 159 new TypeInfo("DATALINK", Types.DATALINK), 160 new TypeInfo("NCHAR", Types.NCHAR), 161 new TypeInfo("NCLOB", Types.NCLOB), 162 new TypeInfo("NVARCHAR", Types.NVARCHAR), 163 new TypeInfo("LONGNVARCHAR", Types.LONGNVARCHAR), 164 new TypeInfo("REF", Types.REF), 165 new TypeInfo("ROWID", Types.ROWID), 166 new TypeInfo("SQLXML", Types.SQLXML), 167 new TypeInfo("STRUCT", Types.STRUCT), 168 }; 169 170 179 static Test suite(boolean callable) { 180 TestSuite suite = new TestSuite(); 181 for (TypeInfo typeInfo : TYPES) { 182 suite.addTest(new SetObjectUnsupportedTest 183 ("testUnsupportedSetObject", typeInfo, callable)); 184 suite.addTest(new SetObjectUnsupportedTest 185 ("testUnsupportedSetObjectWithScale", 186 typeInfo, callable)); 187 suite.addTest(new SetObjectUnsupportedTest 188 ("testUnsupportedSetNull", typeInfo, callable)); 189 suite.addTest(new SetObjectUnsupportedTest 190 ("testUnsupportedSetNullWithTypeName", 191 typeInfo, callable)); 192 } 193 return suite; 194 } 195 196 197 private static class TypeInfo { 198 final String name; 199 final int type; 200 TypeInfo(String name, int type) { 201 this.name = name; 202 this.type = type; 203 } 204 } 205 } 206 | Popular Tags |