Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wqh754186373
spring-framework
提交
a02ee196
S
spring-framework
项目概览
wqh754186373
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a02ee196
编写于
10月 30, 2008
作者:
A
Arjen Poutsma
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved tests from testsuite to jdbc
上级
faa74a39
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
102 addition
and
347 deletion
+102
-347
org.springframework.jdbc/src/test/java/org/springframework/jdbc/Customer.java
...jdbc/src/test/java/org/springframework/jdbc/Customer.java
+50
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/SimpleRowCountCallbackHandler.java
...ingframework/jdbc/core/SimpleRowCountCallbackHandler.java
+42
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java
...mework/jdbc/datasource/DataSourceJtaTransactionTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java
...rk/jdbc/datasource/DataSourceTransactionManagerTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/datasource/DriverManagerDataSourceTests.java
...amework/jdbc/datasource/DriverManagerDataSourceTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapterTests.java
...dbc/datasource/UserCredentialsDataSourceAdapterTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java
.../org/springframework/jdbc/object/BatchSqlUpdateTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java
.../org/springframework/jdbc/object/RdbmsOperationTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java
...t/java/org/springframework/jdbc/object/SqlQueryTests.java
+10
-8
org.springframework.jdbc/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java
.../java/org/springframework/jdbc/object/SqlUpdateTests.java
+0
-0
org.springframework.jdbc/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java
...org/springframework/jdbc/object/StoredProcedureTests.java
+0
-0
org.springframework.testsuite/src/test/java/org/springframework/jdbc/object/SqlFunctionTests.java
...ava/org/springframework/jdbc/object/SqlFunctionTests.java
+0
-339
未找到文件。
org.springframework.jdbc/src/test/java/org/springframework/jdbc/Customer.java
0 → 100644
浏览文件 @
a02ee196
/*
* Copyright 2002-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.jdbc
;
/**
* @author Juergen Hoeller
*/
public
class
Customer
{
private
int
id
;
private
String
forename
;
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getForename
()
{
return
forename
;
}
public
void
setForename
(
String
forename
)
{
this
.
forename
=
forename
;
}
public
String
toString
()
{
return
"Customer: id="
+
id
+
"; forename="
+
forename
;
}
}
org.springframework.jdbc/src/test/java/org/springframework/jdbc/core/SimpleRowCountCallbackHandler.java
0 → 100644
浏览文件 @
a02ee196
/*
* Copyright 2002-2006 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.jdbc.core
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
/**
* Simple row count callback handler for testing purposes.
* Does not call any JDBC methods on the given ResultSet.
*
* @author Juergen Hoeller
* @since 2.0
*/
public
class
SimpleRowCountCallbackHandler
implements
RowCallbackHandler
{
private
int
count
;
public
void
processRow
(
ResultSet
rs
)
throws
SQLException
{
count
++;
}
public
int
getCount
()
{
return
count
;
}
}
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/datasource/DataSourceJtaTransactionTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/datasource/DataSourceTransactionManagerTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/datasource/DriverManagerDataSourceTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/datasource/DriverManagerDataSourceTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapterTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapterTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/object/BatchSqlUpdateTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/object/RdbmsOperationTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java
浏览文件 @
a02ee196
...
...
@@ -39,6 +39,8 @@ import org.springframework.jdbc.Customer;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.SqlParameter
;
import
junit.framework.Assert
;
/**
* @author Trevor Cook
* @author Thomas Risberg
...
...
@@ -962,10 +964,10 @@ public class SqlQueryTests extends AbstractJdbcTests {
List
cust
=
query
.
findCustomers
(
ids
);
assertEquals
(
"We got two customers back"
,
cust
.
size
(),
2
);
assertEquals
(
"First customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getId
(),
1
);
assertEquals
(
"First customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getForename
(),
"rod"
);
assertEquals
(
"Second customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getId
(),
2
);
assertEquals
(
"Second customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getForename
(),
"juergen"
);
Assert
.
assertEquals
(
"First customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getId
(),
1
);
Assert
.
assertEquals
(
"First customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getForename
(),
"rod"
);
Assert
.
assertEquals
(
"Second customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getId
(),
2
);
Assert
.
assertEquals
(
"Second customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getForename
(),
"juergen"
);
}
public
void
testNamedParameterQueryReusingParameter
()
throws
SQLException
{
...
...
@@ -1032,10 +1034,10 @@ public class SqlQueryTests extends AbstractJdbcTests {
List
cust
=
query
.
findCustomers
(
new
Integer
(
1
));
assertEquals
(
"We got two customers back"
,
cust
.
size
(),
2
);
assertEquals
(
"First customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getId
(),
1
);
assertEquals
(
"First customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getForename
(),
"rod"
);
assertEquals
(
"Second customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getId
(),
2
);
assertEquals
(
"Second customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getForename
(),
"juergen"
);
Assert
.
assertEquals
(
"First customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getId
(),
1
);
Assert
.
assertEquals
(
"First customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
0
)).
getForename
(),
"rod"
);
Assert
.
assertEquals
(
"Second customer id was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getId
(),
2
);
Assert
.
assertEquals
(
"Second customer forename was assigned correctly"
,
((
Customer
)
cust
.
get
(
1
)).
getForename
(),
"juergen"
);
}
public
void
testNamedParameterUsingInvalidQuestionMarkPlaceHolders
()
throws
SQLException
{
...
...
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.
testsuite
/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java
→
org.springframework.
jdbc
/src/test/java/org/springframework/jdbc/object/StoredProcedureTests.java
浏览文件 @
a02ee196
文件已移动
org.springframework.testsuite/src/test/java/org/springframework/jdbc/object/SqlFunctionTests.java
已删除
100644 → 0
浏览文件 @
faa74a39
/*
* Copyright 2002-2008 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.jdbc.object
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
java.sql.Types
;
import
org.apache.commons.logging.LogFactory
;
import
org.easymock.MockControl
;
import
org.springframework.dao.IncorrectResultSizeDataAccessException
;
import
org.springframework.jdbc.AbstractJdbcTests
;
import
org.springframework.jdbc.core.JdbcTemplate
;
/**
* @author Trevor Cook
*/
public
class
SqlFunctionTests
extends
AbstractJdbcTests
{
private
static
final
String
FUNCTION
=
"select count(id) from mytable"
;
private
static
final
String
FUNCTION_INT
=
"select count(id) from mytable where myparam = ?"
;
private
static
final
String
FUNCTION_MIXED
=
"select count(id) from mytable where myparam = ? and mystring = ?"
;
private
final
boolean
debugEnabled
=
LogFactory
.
getLog
(
JdbcTemplate
.
class
).
isDebugEnabled
();
private
MockControl
ctrlPreparedStatement
;
private
PreparedStatement
mockPreparedStatement
;
private
MockControl
ctrlResultSet
;
private
ResultSet
mockResultSet
;
private
MockControl
ctrlResultSetMetaData
;
private
ResultSetMetaData
mockResultSetMetaData
;
protected
void
setUp
()
throws
Exception
{
super
.
setUp
();
ctrlPreparedStatement
=
MockControl
.
createControl
(
PreparedStatement
.
class
);
mockPreparedStatement
=
(
PreparedStatement
)
ctrlPreparedStatement
.
getMock
();
ctrlResultSet
=
MockControl
.
createControl
(
ResultSet
.
class
);
mockResultSet
=
(
ResultSet
)
ctrlResultSet
.
getMock
();
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
}
protected
void
tearDown
()
throws
Exception
{
super
.
tearDown
();
if
(
shouldVerify
())
{
ctrlPreparedStatement
.
verify
();
ctrlResultSet
.
verify
();
ctrlResultSetMetaData
.
verify
();
}
}
protected
void
replay
()
{
super
.
replay
();
ctrlPreparedStatement
.
replay
();
ctrlResultSet
.
replay
();
ctrlResultSetMetaData
.
replay
();
}
public
void
testFunction
()
throws
SQLException
{
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
mockResultSetMetaData
.
getColumnCount
();
ctrlResultSetMetaData
.
setReturnValue
(
1
);
mockResultSet
.
getMetaData
();
ctrlResultSet
.
setReturnValue
(
mockResultSetMetaData
,
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getObject
(
1
);
ctrlResultSet
.
setReturnValue
(
new
Integer
(
14
));
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
false
);
mockResultSet
.
close
();
ctrlResultSet
.
setVoidCallable
();
mockPreparedStatement
.
executeQuery
();
ctrlPreparedStatement
.
setReturnValue
(
mockResultSet
);
if
(
debugEnabled
)
{
mockPreparedStatement
.
getWarnings
();
ctrlPreparedStatement
.
setReturnValue
(
null
);
}
mockPreparedStatement
.
close
();
ctrlPreparedStatement
.
setVoidCallable
();
mockConnection
.
prepareStatement
(
FUNCTION
);
ctrlConnection
.
setReturnValue
(
mockPreparedStatement
);
replay
();
SqlFunction
function
=
new
SqlFunction
();
function
.
setDataSource
(
mockDataSource
);
function
.
setSql
(
FUNCTION
);
function
.
compile
();
int
count
=
function
.
run
();
assertTrue
(
"Function returned value 14"
,
count
==
14
);
}
public
void
testTooManyRows
()
throws
SQLException
{
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
mockResultSetMetaData
.
getColumnCount
();
ctrlResultSetMetaData
.
setReturnValue
(
1
,
2
);
mockResultSet
.
getMetaData
();
ctrlResultSet
.
setReturnValue
(
mockResultSetMetaData
,
2
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getObject
(
1
);
ctrlResultSet
.
setReturnValue
(
new
Integer
(
14
),
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getObject
(
1
);
ctrlResultSet
.
setReturnValue
(
new
Integer
(
15
),
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
false
);
mockResultSet
.
close
();
ctrlResultSet
.
setVoidCallable
();
mockPreparedStatement
.
executeQuery
();
ctrlPreparedStatement
.
setReturnValue
(
mockResultSet
);
if
(
debugEnabled
)
{
mockPreparedStatement
.
getWarnings
();
ctrlPreparedStatement
.
setReturnValue
(
null
);
}
mockPreparedStatement
.
close
();
ctrlPreparedStatement
.
setVoidCallable
();
mockConnection
.
prepareStatement
(
FUNCTION
);
ctrlConnection
.
setReturnValue
(
mockPreparedStatement
);
replay
();
SqlFunction
function
=
new
SqlFunction
(
mockDataSource
,
FUNCTION
);
function
.
compile
();
try
{
int
count
=
function
.
run
();
fail
(
"Shouldn't continue when too many rows returned"
);
}
catch
(
IncorrectResultSizeDataAccessException
idaauex
)
{
// OK
}
}
public
void
testFunctionInt
()
throws
SQLException
{
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
mockResultSetMetaData
.
getColumnCount
();
ctrlResultSetMetaData
.
setReturnValue
(
1
);
mockResultSet
.
getMetaData
();
ctrlResultSet
.
setReturnValue
(
mockResultSetMetaData
,
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getObject
(
1
);
ctrlResultSet
.
setReturnValue
(
new
Integer
(
14
));
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
false
);
mockResultSet
.
close
();
ctrlResultSet
.
setVoidCallable
();
mockPreparedStatement
.
setObject
(
1
,
new
Integer
(
1
),
Types
.
INTEGER
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
executeQuery
();
ctrlPreparedStatement
.
setReturnValue
(
mockResultSet
);
if
(
debugEnabled
)
{
mockPreparedStatement
.
getWarnings
();
ctrlPreparedStatement
.
setReturnValue
(
null
);
}
mockPreparedStatement
.
close
();
ctrlPreparedStatement
.
setVoidCallable
();
mockConnection
.
prepareStatement
(
FUNCTION_INT
);
ctrlConnection
.
setReturnValue
(
mockPreparedStatement
);
replay
();
SqlFunction
function
=
new
SqlFunction
(
mockDataSource
,
FUNCTION_INT
);
function
.
setTypes
(
new
int
[]
{
Types
.
INTEGER
});
function
.
compile
();
int
count
=
function
.
run
(
1
);
assertTrue
(
"Function returned value 14"
,
count
==
14
);
}
public
void
testFunctionMixed
()
throws
SQLException
{
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
mockResultSetMetaData
.
getColumnCount
();
ctrlResultSetMetaData
.
setReturnValue
(
1
);
mockResultSet
.
getMetaData
();
ctrlResultSet
.
setReturnValue
(
mockResultSetMetaData
,
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getObject
(
1
);
ctrlResultSet
.
setReturnValue
(
new
Integer
(
14
));
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
false
);
mockResultSet
.
close
();
ctrlResultSet
.
setVoidCallable
();
mockPreparedStatement
.
setObject
(
1
,
new
Integer
(
1
),
Types
.
INTEGER
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
setString
(
2
,
"rod"
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
executeQuery
();
ctrlPreparedStatement
.
setReturnValue
(
mockResultSet
);
if
(
debugEnabled
)
{
mockPreparedStatement
.
getWarnings
();
ctrlPreparedStatement
.
setReturnValue
(
null
);
}
mockPreparedStatement
.
close
();
ctrlPreparedStatement
.
setVoidCallable
();
mockConnection
.
prepareStatement
(
FUNCTION_MIXED
);
ctrlConnection
.
setReturnValue
(
mockPreparedStatement
);
replay
();
SqlFunction
function
=
new
SqlFunction
(
mockDataSource
,
FUNCTION_MIXED
,
new
int
[]
{
Types
.
INTEGER
,
Types
.
VARCHAR
});
function
.
compile
();
int
count
=
function
.
run
(
new
Object
[]
{
new
Integer
(
1
),
"rod"
});
assertTrue
(
"Function returned value 14"
,
count
==
14
);
}
public
void
testFunctionWithStringResult
()
throws
SQLException
{
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
mockResultSetMetaData
.
getColumnCount
();
ctrlResultSetMetaData
.
setReturnValue
(
1
);
mockResultSet
.
getMetaData
();
ctrlResultSet
.
setReturnValue
(
mockResultSetMetaData
,
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getObject
(
1
);
ctrlResultSet
.
setReturnValue
(
"14"
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
false
);
mockResultSet
.
close
();
ctrlResultSet
.
setVoidCallable
();
mockPreparedStatement
.
setObject
(
1
,
new
Integer
(
1
),
Types
.
INTEGER
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
setString
(
2
,
"rod"
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
executeQuery
();
ctrlPreparedStatement
.
setReturnValue
(
mockResultSet
);
if
(
debugEnabled
)
{
mockPreparedStatement
.
getWarnings
();
ctrlPreparedStatement
.
setReturnValue
(
null
);
}
mockPreparedStatement
.
close
();
ctrlPreparedStatement
.
setVoidCallable
();
mockConnection
.
prepareStatement
(
FUNCTION_MIXED
);
ctrlConnection
.
setReturnValue
(
mockPreparedStatement
);
replay
();
SqlFunction
function
=
new
SqlFunction
(
mockDataSource
,
FUNCTION_MIXED
);
function
.
setTypes
(
new
int
[]
{
Types
.
INTEGER
,
Types
.
VARCHAR
});
function
.
compile
();
String
result
=
(
String
)
function
.
runGeneric
(
new
Object
[]
{
new
Integer
(
1
),
"rod"
});
assertTrue
(
"Function returned value 14"
,
"14"
.
equals
(
result
));
}
public
void
testFunctionWithStringConvertedResult
()
throws
SQLException
{
ctrlResultSetMetaData
=
MockControl
.
createControl
(
ResultSetMetaData
.
class
);
mockResultSetMetaData
=
(
ResultSetMetaData
)
ctrlResultSetMetaData
.
getMock
();
mockResultSetMetaData
.
getColumnCount
();
ctrlResultSetMetaData
.
setReturnValue
(
1
);
mockResultSet
.
getMetaData
();
ctrlResultSet
.
setReturnValue
(
mockResultSetMetaData
,
1
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
true
);
mockResultSet
.
getString
(
1
);
ctrlResultSet
.
setReturnValue
(
"14"
);
mockResultSet
.
next
();
ctrlResultSet
.
setReturnValue
(
false
);
mockResultSet
.
close
();
ctrlResultSet
.
setVoidCallable
();
mockPreparedStatement
.
setObject
(
1
,
new
Integer
(
1
),
Types
.
INTEGER
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
setString
(
2
,
"rod"
);
ctrlPreparedStatement
.
setVoidCallable
();
mockPreparedStatement
.
executeQuery
();
ctrlPreparedStatement
.
setReturnValue
(
mockResultSet
);
if
(
debugEnabled
)
{
mockPreparedStatement
.
getWarnings
();
ctrlPreparedStatement
.
setReturnValue
(
null
);
}
mockPreparedStatement
.
close
();
ctrlPreparedStatement
.
setVoidCallable
();
mockConnection
.
prepareStatement
(
FUNCTION_MIXED
);
ctrlConnection
.
setReturnValue
(
mockPreparedStatement
);
replay
();
SqlFunction
function
=
new
SqlFunction
(
mockDataSource
,
FUNCTION_MIXED
);
function
.
setTypes
(
new
int
[]
{
Types
.
INTEGER
,
Types
.
VARCHAR
});
function
.
setResultType
(
String
.
class
);
function
.
compile
();
String
result
=
(
String
)
function
.
runGeneric
(
new
Object
[]
{
new
Integer
(
1
),
"rod"
});
assertTrue
(
"Function returned value 14"
,
"14"
.
equals
(
result
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录