DefaultLobCreator supports JDBC 4.0 set-stream variants without length parameter

Issue: SPR-12265
This commit is contained in:
Juergen Hoeller
2014-09-26 23:56:43 +02:00
parent 7f9baa3a09
commit d65db65fad
2 changed files with 47 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Test;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
@@ -39,10 +40,14 @@ import static org.mockito.BDDMockito.*;
public class DefaultLobHandlerTests {
private ResultSet rs = mock(ResultSet.class);
private PreparedStatement ps = mock(PreparedStatement.class);
private LobHandler lobHandler = new DefaultLobHandler();
private LobCreator lobCreator = lobHandler.getLobCreator();
@Test
public void testGetBlobAsBytes() throws SQLException {
lobHandler.getBlobAsBytes(rs, 1);
@@ -82,12 +87,18 @@ public class DefaultLobHandlerTests {
@Test
public void testSetBlobAsBinaryStream() throws SQLException, IOException {
InputStream bis = new ByteArrayInputStream("testContent".getBytes());
lobCreator.setBlobAsBinaryStream(ps, 1, bis, 11);
verify(ps).setBinaryStream(1, bis, 11);
}
@Test
public void testSetBlobAsBinaryStreamWithoutLength() throws SQLException, IOException {
InputStream bis = new ByteArrayInputStream("testContent".getBytes());
lobCreator.setBlobAsBinaryStream(ps, 1, bis, -1);
verify(ps).setBinaryStream(1, bis);
}
@Test
public void testSetClobAsString() throws SQLException, IOException {
String content = "testContent";
@@ -102,6 +113,13 @@ public class DefaultLobHandlerTests {
verify(ps).setAsciiStream(1, bis, 11);
}
@Test
public void testSetClobAsAsciiStreamWithoutLength() throws SQLException, IOException {
InputStream bis = new ByteArrayInputStream("testContent".getBytes());
lobCreator.setClobAsAsciiStream(ps, 1, bis, -1);
verify(ps).setAsciiStream(1, bis);
}
@Test
public void testSetClobAsCharacterStream() throws SQLException, IOException {
Reader str = new StringReader("testContent");
@@ -109,4 +127,11 @@ public class DefaultLobHandlerTests {
verify(ps).setCharacterStream(1, str, 11);
}
@Test
public void testSetClobAsCharacterStreamWithoutLength() throws SQLException, IOException {
Reader str = new StringReader("testContent");
lobCreator.setClobAsCharacterStream(ps, 1, str, -1);
verify(ps).setCharacterStream(1, str);
}
}