KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > support > DefaultLobHandlerTests


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.support;
18
19 import java.io.ByteArrayInputStream JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.InputStream JavaDoc;
22 import java.io.Reader JavaDoc;
23 import java.io.StringReader JavaDoc;
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.sql.ResultSet JavaDoc;
27
28 import junit.framework.TestCase;
29 import org.easymock.MockControl;
30
31 import org.springframework.jdbc.support.lob.DefaultLobHandler;
32 import org.springframework.jdbc.support.lob.LobCreator;
33 import org.springframework.jdbc.support.lob.LobHandler;
34
35 /**
36  * @author Juergen Hoeller
37  * @since 17.12.2003
38  */

39 public class DefaultLobHandlerTests extends TestCase {
40
41     public void testGetBlobAsBytes() throws SQLException JavaDoc {
42         LobHandler lobHandler = new DefaultLobHandler();
43         MockControl rsControl = MockControl.createControl(ResultSet JavaDoc.class);
44         ResultSet JavaDoc rs = (ResultSet JavaDoc) rsControl.getMock();
45         rs.getBytes(1);
46         rsControl.setReturnValue(null);
47         rsControl.replay();
48         lobHandler.getBlobAsBytes(rs, 1);
49         rsControl.verify();
50     }
51
52     public void testGetBlobAsBinaryStream() throws SQLException JavaDoc {
53         LobHandler lobHandler = new DefaultLobHandler();
54         MockControl rsControl = MockControl.createControl(ResultSet JavaDoc.class);
55         ResultSet JavaDoc rs = (ResultSet JavaDoc) rsControl.getMock();
56         rs.getBinaryStream(1);
57         rsControl.setReturnValue(null);
58         rsControl.replay();
59         lobHandler.getBlobAsBinaryStream(rs, 1);
60         rsControl.verify();
61     }
62
63     public void testGetClobAsString() throws SQLException JavaDoc {
64         LobHandler lobHandler = new DefaultLobHandler();
65         MockControl rsControl = MockControl.createControl(ResultSet JavaDoc.class);
66         ResultSet JavaDoc rs = (ResultSet JavaDoc) rsControl.getMock();
67         rs.getString(1);
68         rsControl.setReturnValue(null);
69         rsControl.replay();
70         lobHandler.getClobAsString(rs, 1);
71         rsControl.verify();
72     }
73
74     public void testGetClobAsAsciiStream() throws SQLException JavaDoc {
75         LobHandler lobHandler = new DefaultLobHandler();
76         MockControl rsControl = MockControl.createControl(ResultSet JavaDoc.class);
77         ResultSet JavaDoc rs = (ResultSet JavaDoc) rsControl.getMock();
78         rs.getAsciiStream(1);
79         rsControl.setReturnValue(null);
80         rsControl.replay();
81         lobHandler.getClobAsAsciiStream(rs, 1);
82         rsControl.verify();
83     }
84
85     public void testGetClobAsCharacterStream() throws SQLException JavaDoc {
86         LobHandler lobHandler = new DefaultLobHandler();
87         MockControl rsControl = MockControl.createControl(ResultSet JavaDoc.class);
88         ResultSet JavaDoc rs = (ResultSet JavaDoc) rsControl.getMock();
89         rs.getCharacterStream(1);
90         rsControl.setReturnValue(null);
91         rsControl.replay();
92         lobHandler.getClobAsCharacterStream(rs, 1);
93         rsControl.verify();
94     }
95
96     public void testSetBlobAsBytes() throws SQLException JavaDoc {
97         LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator();
98         byte[] content = "testContent".getBytes();
99
100         MockControl psControl = MockControl.createControl(PreparedStatement JavaDoc.class);
101         PreparedStatement JavaDoc ps = (PreparedStatement JavaDoc) psControl.getMock();
102         ps.setBytes(1, content);
103         psControl.replay();
104
105         lobCreator.setBlobAsBytes(ps, 1, content);
106         psControl.verify();
107     }
108
109     public void testSetBlobAsBinaryStream() throws SQLException JavaDoc, IOException JavaDoc {
110         LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator();
111         InputStream JavaDoc bis = new ByteArrayInputStream JavaDoc("testContent".getBytes());
112
113         MockControl psControl = MockControl.createControl(PreparedStatement JavaDoc.class);
114         PreparedStatement JavaDoc ps = (PreparedStatement JavaDoc) psControl.getMock();
115         ps.setBinaryStream(1, bis, 11);
116         psControl.replay();
117
118         lobCreator.setBlobAsBinaryStream(ps, 1, bis, 11);
119         psControl.verify();
120     }
121
122     public void testSetClobAsString() throws SQLException JavaDoc, IOException JavaDoc {
123         LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator();
124         String JavaDoc content = "testContent";
125
126         MockControl psControl = MockControl.createControl(PreparedStatement JavaDoc.class);
127         PreparedStatement JavaDoc ps = (PreparedStatement JavaDoc) psControl.getMock();
128         ps.setString(1, content);
129         psControl.replay();
130
131         lobCreator.setClobAsString(ps, 1, content);
132         psControl.verify();
133     }
134
135     public void testSetClobAsAsciiStream() throws SQLException JavaDoc, IOException JavaDoc {
136         LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator();
137         InputStream JavaDoc bis = new ByteArrayInputStream JavaDoc("testContent".getBytes());
138
139         MockControl psControl = MockControl.createControl(PreparedStatement JavaDoc.class);
140         PreparedStatement JavaDoc ps = (PreparedStatement JavaDoc) psControl.getMock();
141         ps.setAsciiStream(1, bis, 11);
142         psControl.replay();
143
144         lobCreator.setClobAsAsciiStream(ps, 1, bis, 11);
145         psControl.verify();
146     }
147
148     public void testSetClobAsCharacterStream() throws SQLException JavaDoc, IOException JavaDoc {
149         LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator();
150         Reader JavaDoc str = new StringReader JavaDoc("testContent");
151
152         MockControl psControl = MockControl.createControl(PreparedStatement JavaDoc.class);
153         PreparedStatement JavaDoc ps = (PreparedStatement JavaDoc) psControl.getMock();
154         ps.setCharacterStream(1, str, 11);
155         psControl.replay();
156
157         lobCreator.setClobAsCharacterStream(ps, 1, str, 11);
158         psControl.verify();
159     }
160
161 }
162
Popular Tags