1 16 17 package org.springframework.jdbc.support; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.io.Reader ; 23 import java.io.StringReader ; 24 import java.sql.PreparedStatement ; 25 import java.sql.SQLException ; 26 import java.sql.ResultSet ; 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 39 public class DefaultLobHandlerTests extends TestCase { 40 41 public void testGetBlobAsBytes() throws SQLException { 42 LobHandler lobHandler = new DefaultLobHandler(); 43 MockControl rsControl = MockControl.createControl(ResultSet .class); 44 ResultSet rs = (ResultSet ) 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 { 53 LobHandler lobHandler = new DefaultLobHandler(); 54 MockControl rsControl = MockControl.createControl(ResultSet .class); 55 ResultSet rs = (ResultSet ) 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 { 64 LobHandler lobHandler = new DefaultLobHandler(); 65 MockControl rsControl = MockControl.createControl(ResultSet .class); 66 ResultSet rs = (ResultSet ) 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 { 75 LobHandler lobHandler = new DefaultLobHandler(); 76 MockControl rsControl = MockControl.createControl(ResultSet .class); 77 ResultSet rs = (ResultSet ) 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 { 86 LobHandler lobHandler = new DefaultLobHandler(); 87 MockControl rsControl = MockControl.createControl(ResultSet .class); 88 ResultSet rs = (ResultSet ) 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 { 97 LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator(); 98 byte[] content = "testContent".getBytes(); 99 100 MockControl psControl = MockControl.createControl(PreparedStatement .class); 101 PreparedStatement ps = (PreparedStatement ) 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 , IOException { 110 LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator(); 111 InputStream bis = new ByteArrayInputStream ("testContent".getBytes()); 112 113 MockControl psControl = MockControl.createControl(PreparedStatement .class); 114 PreparedStatement ps = (PreparedStatement ) 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 , IOException { 123 LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator(); 124 String content = "testContent"; 125 126 MockControl psControl = MockControl.createControl(PreparedStatement .class); 127 PreparedStatement ps = (PreparedStatement ) 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 , IOException { 136 LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator(); 137 InputStream bis = new ByteArrayInputStream ("testContent".getBytes()); 138 139 MockControl psControl = MockControl.createControl(PreparedStatement .class); 140 PreparedStatement ps = (PreparedStatement ) 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 , IOException { 149 LobCreator lobCreator = (new DefaultLobHandler()).getLobCreator(); 150 Reader str = new StringReader ("testContent"); 151 152 MockControl psControl = MockControl.createControl(PreparedStatement .class); 153 PreparedStatement ps = (PreparedStatement ) 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 |