KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > core > StatementCreatorUtilsTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.jdbc.core;
18
19 import java.sql.PreparedStatement JavaDoc;
20 import java.sql.SQLException JavaDoc;
21 import java.sql.Types JavaDoc;
22 import java.util.GregorianCalendar JavaDoc;
23
24 import junit.framework.TestCase;
25 import org.easymock.MockControl;
26
27 /**
28  * @author Juergen Hoeller
29  * @since 31.08.2004
30  */

31 public class StatementCreatorUtilsTests extends TestCase {
32
33     private MockControl psControl;
34     private PreparedStatement JavaDoc ps;
35
36     protected void setUp() {
37         psControl = MockControl.createControl(PreparedStatement JavaDoc.class);
38         ps = (PreparedStatement JavaDoc) psControl.getMock();
39     }
40
41     protected void tearDown() {
42         psControl.verify();
43     }
44
45     public void testSetParameterValueWithNullAndType() throws SQLException JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
88         java.sql.Date JavaDoc date = new java.sql.Date JavaDoc(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 JavaDoc {
96         java.util.Date JavaDoc date = new java.util.Date JavaDoc(1000);
97         ps.setDate(1, new java.sql.Date JavaDoc(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 JavaDoc {
104         java.util.Calendar JavaDoc cal = new GregorianCalendar JavaDoc();
105         ps.setDate(1, new java.sql.Date JavaDoc(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 JavaDoc {
112         java.sql.Time JavaDoc time = new java.sql.Time JavaDoc(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 JavaDoc {
120         java.util.Date JavaDoc date = new java.util.Date JavaDoc(1000);
121         ps.setTime(1, new java.sql.Time JavaDoc(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 JavaDoc {
128         java.util.Calendar JavaDoc cal = new GregorianCalendar JavaDoc();
129         ps.setTime(1, new java.sql.Time JavaDoc(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 JavaDoc {
136         java.sql.Timestamp JavaDoc timestamp = new java.sql.Timestamp JavaDoc(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 JavaDoc {
144         java.util.Date JavaDoc date = new java.util.Date JavaDoc(1000);
145         ps.setTimestamp(1, new java.sql.Timestamp JavaDoc(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 JavaDoc {
152         java.util.Calendar JavaDoc cal = new GregorianCalendar JavaDoc();
153         ps.setTimestamp(1, new java.sql.Timestamp JavaDoc(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 JavaDoc {
160         java.util.Date JavaDoc date = new java.util.Date JavaDoc(1000);
161         ps.setObject(1, new java.sql.Timestamp JavaDoc(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 JavaDoc {
168         java.util.Calendar JavaDoc cal = new GregorianCalendar JavaDoc();
169         ps.setObject(1, new java.sql.Timestamp JavaDoc(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