1 16 17 package org.springframework.jdbc.core; 18 19 import java.sql.PreparedStatement ; 20 import java.sql.SQLException ; 21 import java.sql.Types ; 22 import java.util.GregorianCalendar ; 23 24 import junit.framework.TestCase; 25 import org.easymock.MockControl; 26 27 31 public class StatementCreatorUtilsTests extends TestCase { 32 33 private MockControl psControl; 34 private PreparedStatement ps; 35 36 protected void setUp() { 37 psControl = MockControl.createControl(PreparedStatement .class); 38 ps = (PreparedStatement ) psControl.getMock(); 39 } 40 41 protected void tearDown() { 42 psControl.verify(); 43 } 44 45 public void testSetParameterValueWithNullAndType() throws SQLException { 46 ps.setNull(1, Types.VARCHAR); 47 psControl.setVoidCallable(1); 48 psControl.replay(); 49 StatementCreatorUtils.setParameterValue(ps, 1, Types.VARCHAR, null, null); 50 } 51 52 public void testSetParameterValueWithNullAndTypeName() throws SQLException { 53 ps.setNull(1, Types.VARCHAR, "mytype"); 54 psControl.setVoidCallable(1); 55 psControl.replay(); 56 StatementCreatorUtils.setParameterValue(ps, 1, Types.VARCHAR, "mytype", null); 57 } 58 59 public void testSetParameterValueWithNullAndUnknownType() throws SQLException { 60 ps.setObject(1, null); 61 psControl.setVoidCallable(1); 62 psControl.replay(); 63 StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, null, null); 64 } 65 66 public void testSetParameterValueWithString() throws SQLException { 67 ps.setString(1, "test"); 68 psControl.setVoidCallable(1); 69 psControl.replay(); 70 StatementCreatorUtils.setParameterValue(ps, 1, Types.VARCHAR, null, "test"); 71 } 72 73 public void testSetParameterValueWithStringAndSpecialType() throws SQLException { 74 ps.setObject(1, "test", Types.CHAR); 75 psControl.setVoidCallable(1); 76 psControl.replay(); 77 StatementCreatorUtils.setParameterValue(ps, 1, Types.CHAR, null, "test"); 78 } 79 80 public void testSetParameterValueWithStringAndUnknownType() throws SQLException { 81 ps.setObject(1, "test"); 82 psControl.setVoidCallable(1); 83 psControl.replay(); 84 StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, null, "test"); 85 } 86 87 public void testSetParameterValueWithSqlDate() throws SQLException { 88 java.sql.Date date = new java.sql.Date (1000); 89 ps.setDate(1, date); 90 psControl.setVoidCallable(1); 91 psControl.replay(); 92 StatementCreatorUtils.setParameterValue(ps, 1, Types.DATE, null, date); 93 } 94 95 public void testSetParameterValueWithDateAndUtilDate() throws SQLException { 96 java.util.Date date = new java.util.Date (1000); 97 ps.setDate(1, new java.sql.Date (1000)); 98 psControl.setVoidCallable(1); 99 psControl.replay(); 100 StatementCreatorUtils.setParameterValue(ps, 1, Types.DATE, null, date); 101 } 102 103 public void testSetParameterValueWithDateAndCalendar() throws SQLException { 104 java.util.Calendar cal = new GregorianCalendar (); 105 ps.setDate(1, new java.sql.Date (cal.getTime().getTime()), cal); 106 psControl.setVoidCallable(1); 107 psControl.replay(); 108 StatementCreatorUtils.setParameterValue(ps, 1, Types.DATE, null, cal); 109 } 110 111 public void testSetParameterValueWithSqlTime() throws SQLException { 112 java.sql.Time time = new java.sql.Time (1000); 113 ps.setTime(1, time); 114 psControl.setVoidCallable(1); 115 psControl.replay(); 116 StatementCreatorUtils.setParameterValue(ps, 1, Types.TIME, null, time); 117 } 118 119 public void testSetParameterValueWithTimeAndUtilDate() throws SQLException { 120 java.util.Date date = new java.util.Date (1000); 121 ps.setTime(1, new java.sql.Time (1000)); 122 psControl.setVoidCallable(1); 123 psControl.replay(); 124 StatementCreatorUtils.setParameterValue(ps, 1, Types.TIME, null, date); 125 } 126 127 public void testSetParameterValueWithTimeAndCalendar() throws SQLException { 128 java.util.Calendar cal = new GregorianCalendar (); 129 ps.setTime(1, new java.sql.Time (cal.getTime().getTime()), cal); 130 psControl.setVoidCallable(1); 131 psControl.replay(); 132 StatementCreatorUtils.setParameterValue(ps, 1, Types.TIME, null, cal); 133 } 134 135 public void testSetParameterValueWithSqlTimestamp() throws SQLException { 136 java.sql.Timestamp timestamp = new java.sql.Timestamp (1000); 137 ps.setTimestamp(1, timestamp); 138 psControl.setVoidCallable(1); 139 psControl.replay(); 140 StatementCreatorUtils.setParameterValue(ps, 1, Types.TIMESTAMP, null, timestamp); 141 } 142 143 public void testSetParameterValueWithTimestampAndUtilDate() throws SQLException { 144 java.util.Date date = new java.util.Date (1000); 145 ps.setTimestamp(1, new java.sql.Timestamp (1000)); 146 psControl.setVoidCallable(1); 147 psControl.replay(); 148 StatementCreatorUtils.setParameterValue(ps, 1, Types.TIMESTAMP, null, date); 149 } 150 151 public void testSetParameterValueWithTimestampAndCalendar() throws SQLException { 152 java.util.Calendar cal = new GregorianCalendar (); 153 ps.setTimestamp(1, new java.sql.Timestamp (cal.getTime().getTime()), cal); 154 psControl.setVoidCallable(1); 155 psControl.replay(); 156 StatementCreatorUtils.setParameterValue(ps, 1, Types.TIMESTAMP, null, cal); 157 } 158 159 public void testSetParameterValueWithDateAndUnknownType() throws SQLException { 160 java.util.Date date = new java.util.Date (1000); 161 ps.setObject(1, new java.sql.Timestamp (1000)); 162 psControl.setVoidCallable(1); 163 psControl.replay(); 164 StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, null, date); 165 } 166 167 public void testSetParameterValueWithCalendarAndUnknownType() throws SQLException { 168 java.util.Calendar cal = new GregorianCalendar (); 169 ps.setObject(1, new java.sql.Timestamp (cal.getTime().getTime())); 170 psControl.setVoidCallable(1); 171 psControl.replay(); 172 StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, null, cal); 173 } 174 175 } 176 | Popular Tags |