Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
0b0c8f15
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
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,体验更适合开发者的 AI 搜索 >>
提交
0b0c8f15
编写于
12月 16, 2008
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moving .ejb.access unit tests from .testsuite -> .context
上级
d3a46efe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
214 addition
and
249 deletion
+214
-249
org.springframework.context/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
...ramework/ejb/access/LocalSlsbInvokerInterceptorTests.java
+52
-59
org.springframework.context/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java
...jb/access/LocalStatelessSessionProxyFactoryBeanTests.java
+29
-33
org.springframework.context/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
...k/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
+91
-106
org.springframework.context/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java
...ss/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java
+42
-51
未找到文件。
org.springframework.
testsuite
/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
→
org.springframework.
context
/src/test/java/org/springframework/ejb/access/LocalSlsbInvokerInterceptorTests.java
浏览文件 @
0b0c8f15
...
...
@@ -16,40 +16,43 @@
package
org.springframework.ejb.access
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
junit
.
Assert
.*;
import
javax.ejb.CreateException
;
import
javax.ejb.EJBLocalHome
;
import
javax.ejb.EJBLocalObject
;
import
javax.naming.Context
;
import
javax.naming.NamingException
;
import
junit.framework.TestCase
;
import
org.easymock.MockControl
;
import
org.junit.Test
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.jndi.JndiTemplate
;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @author Chris Beams
*/
public
class
LocalSlsbInvokerInterceptorTests
extends
TestCase
{
public
class
LocalSlsbInvokerInterceptorTests
{
/**
* Test that it performs the correct lookup.
*/
@Test
public
void
testPerformsLookup
()
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
LocalInterfaceWithBusinessMethods
.
class
);
final
LocalInterfaceWithBusinessMethods
ejb
=
(
LocalInterfaceWithBusinessMethods
)
ejbControl
.
getMock
();
ejbControl
.
replay
();
LocalInterfaceWithBusinessMethods
ejb
=
createMock
(
LocalInterfaceWithBusinessMethods
.
class
);
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
);
String
jndiName
=
"foobar"
;
Context
mockContext
=
mockContext
(
jndiName
,
ejb
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
configuredInterceptor
(
mockContext
,
jndiName
);
contextControl
.
verify
(
);
verify
(
mockContext
);
}
@Test
public
void
testLookupFailure
()
throws
Exception
{
final
NamingException
nex
=
new
NamingException
();
final
String
jndiName
=
"foobar"
;
...
...
@@ -74,20 +77,18 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
}
}
@Test
public
void
testInvokesMethodOnEjbInstance
()
throws
Exception
{
Object
retVal
=
new
Object
();
MockControl
ejbControl
=
MockControl
.
createControl
(
LocalInterfaceWithBusinessMethods
.
class
);
final
LocalInterfaceWithBusinessMethods
ejb
=
(
LocalInterfaceWithBusinessMethods
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setReturnValue
(
retVal
,
1
);
LocalInterfaceWithBusinessMethods
ejb
=
createMock
(
LocalInterfaceWithBusinessMethods
.
class
);
expect
(
ejb
.
targetMethod
()).
andReturn
(
retVal
);
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
);
String
jndiName
=
"foobar"
;
Context
mockContext
=
mockContext
(
jndiName
,
ejb
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
ProxyFactory
pf
=
new
ProxyFactory
(
new
Class
[]
{
BusinessMethods
.
class
}
);
pf
.
addAdvice
(
si
);
...
...
@@ -95,24 +96,22 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
assertTrue
(
target
.
targetMethod
()
==
retVal
);
contextControl
.
verify
(
);
ejbControl
.
verify
(
);
verify
(
mockContext
);
verify
(
ejb
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithSeparateBusinessMethods
()
throws
Exception
{
Object
retVal
=
new
Object
();
MockControl
ejbControl
=
MockControl
.
createControl
(
LocalInterface
.
class
);
final
LocalInterface
ejb
=
(
LocalInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setReturnValue
(
retVal
,
1
);
LocalInterface
ejb
=
createMock
(
LocalInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andReturn
(
retVal
);
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
);
String
jndiName
=
"foobar"
;
Context
mockContext
=
mockContext
(
jndiName
,
ejb
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
ProxyFactory
pf
=
new
ProxyFactory
(
new
Class
[]
{
BusinessMethods
.
class
}
);
pf
.
addAdvice
(
si
);
...
...
@@ -120,21 +119,19 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
assertTrue
(
target
.
targetMethod
()
==
retVal
);
contextControl
.
verify
(
);
ejbControl
.
verify
(
);
verify
(
mockContext
);
verify
(
ejb
);
}
private
void
testException
(
Exception
expected
)
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
LocalInterfaceWithBusinessMethods
.
class
);
final
LocalInterfaceWithBusinessMethods
ejb
=
(
LocalInterfaceWithBusinessMethods
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setThrowable
(
expected
);
ejbControl
.
replay
();
LocalInterfaceWithBusinessMethods
ejb
=
createMock
(
LocalInterfaceWithBusinessMethods
.
class
);
expect
(
ejb
.
targetMethod
()).
andThrow
(
expected
);
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
);
String
jndiName
=
"foobar"
;
Context
mockContext
=
mockContext
(
jndiName
,
ejb
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
LocalSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
ProxyFactory
pf
=
new
ProxyFactory
(
new
Class
[]
{
LocalInterfaceWithBusinessMethods
.
class
}
);
pf
.
addAdvice
(
si
);
...
...
@@ -148,38 +145,33 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
assertTrue
(
thrown
==
expected
);
}
contextControl
.
verify
(
);
ejbControl
.
verify
(
);
verify
(
mockContext
);
verify
(
ejb
);
}
@Test
public
void
testApplicationException
()
throws
Exception
{
testException
(
new
ApplicationException
());
}
protected
MockControl
contextControl
(
final
String
jndiName
,
final
Object
ejbInstance
)
protected
Context
mockContext
(
final
String
jndiName
,
final
Object
ejbInstance
)
throws
Exception
{
MockControl
homeControl
=
MockControl
.
createControl
(
SlsbHome
.
class
);
final
SlsbHome
mockHome
=
(
SlsbHome
)
homeControl
.
getMock
();
mockHome
.
create
();
homeControl
.
setReturnValue
(
ejbInstance
,
1
);
homeControl
.
replay
();
final
SlsbHome
mockHome
=
createMock
(
SlsbHome
.
class
);
expect
(
mockHome
.
create
()).
andReturn
((
LocalInterface
)
ejbInstance
);
replay
(
mockHome
);
MockControl
ctxControl
=
MockControl
.
createControl
(
Context
.
class
);
final
Context
mockCtx
=
(
Context
)
ctxControl
.
getMock
();
final
Context
mockCtx
=
createMock
(
Context
.
class
);
mockCtx
.
lookup
(
"java:comp/env/"
+
jndiName
);
ctxControl
.
setReturnValue
(
mockHome
);
expect
(
mockCtx
.
lookup
(
"java:comp/env/"
+
jndiName
)).
andReturn
(
mockHome
);
mockCtx
.
close
();
ctxControl
.
setVoidCallable
();
ctxControl
.
replay
();
return
ctxControl
;
replay
(
mockCtx
);
return
mockCtx
;
}
protected
LocalSlsbInvokerInterceptor
configuredInterceptor
(
MockControl
contextControl
,
final
String
jndiName
)
protected
LocalSlsbInvokerInterceptor
configuredInterceptor
(
final
Context
mockCtx
,
final
String
jndiName
)
throws
Exception
{
final
Context
mockCtx
=
(
Context
)
contextControl
.
getMock
();
LocalSlsbInvokerInterceptor
si
=
new
LocalSlsbInvokerInterceptor
();
si
.
setJndiTemplate
(
new
JndiTemplate
()
{
protected
Context
createInitialContext
()
throws
NamingException
{
...
...
@@ -219,7 +211,8 @@ public class LocalSlsbInvokerInterceptorTests extends TestCase {
}
private
class
ApplicationException
extends
Exception
{
@SuppressWarnings
(
"serial"
)
private
class
ApplicationException
extends
Exception
{
public
ApplicationException
()
{
super
(
"appException"
);
...
...
org.springframework.
testsuite
/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java
→
org.springframework.
context
/src/test/java/org/springframework/ejb/access/LocalStatelessSessionProxyFactoryBeanTests.java
浏览文件 @
0b0c8f15
...
...
@@ -16,6 +16,9 @@
package
org.springframework.ejb.access
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.reflect.Proxy
;
import
javax.ejb.CreateException
;
...
...
@@ -23,35 +26,30 @@ import javax.ejb.EJBLocalHome;
import
javax.ejb.EJBLocalObject
;
import
javax.naming.NamingException
;
import
junit.framework.TestCase
;
import
org.easymock.MockControl
;
import
org.junit.Test
;
import
org.springframework.jndi.JndiTemplate
;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @author Chris Beams
* @since 21.05.2003
*/
public
class
LocalStatelessSessionProxyFactoryBeanTests
extends
TestCase
{
public
class
LocalStatelessSessionProxyFactoryBeanTests
{
@Test
public
void
testInvokesMethod
()
throws
Exception
{
final
int
value
=
11
;
final
String
jndiName
=
"foo"
;
MockControl
ec
=
MockControl
.
createControl
(
MyEjb
.
class
);
MyEjb
myEjb
=
(
MyEjb
)
ec
.
getMock
();
myEjb
.
getValue
();
ec
.
setReturnValue
(
value
,
1
);
MyEjb
myEjb
=
createMock
(
MyEjb
.
class
);
expect
(
myEjb
.
getValue
()).
andReturn
(
value
);
myEjb
.
remove
();
ec
.
setVoidCallable
(
1
);
ec
.
replay
();
replay
(
myEjb
);
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
home
.
create
();
mc
.
setReturnValue
(
myEjb
,
1
);
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
expect
(
home
.
create
()).
andReturn
(
myEjb
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
throws
NamingException
{
...
...
@@ -73,19 +71,18 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
MyBusinessMethods
mbm
=
(
MyBusinessMethods
)
fb
.
getObject
();
assertTrue
(
Proxy
.
isProxyClass
(
mbm
.
getClass
()));
assertTrue
(
mbm
.
getValue
()
==
value
);
mc
.
verify
();
ec
.
verify
(
);
verify
(
myEjb
);
verify
(
home
);
}
@Test
public
void
testInvokesMethodOnEjb3StyleBean
()
throws
Exception
{
final
int
value
=
11
;
final
String
jndiName
=
"foo"
;
MockControl
ec
=
MockControl
.
createControl
(
MyEjb
.
class
);
final
MyEjb
myEjb
=
(
MyEjb
)
ec
.
getMock
();
myEjb
.
getValue
();
ec
.
setReturnValue
(
value
,
1
);
ec
.
replay
();
final
MyEjb
myEjb
=
createMock
(
MyEjb
.
class
);
expect
(
myEjb
.
getValue
()).
andReturn
(
value
);
replay
(
myEjb
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
throws
NamingException
{
...
...
@@ -107,18 +104,17 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
MyBusinessMethods
mbm
=
(
MyBusinessMethods
)
fb
.
getObject
();
assertTrue
(
Proxy
.
isProxyClass
(
mbm
.
getClass
()));
assertTrue
(
mbm
.
getValue
()
==
value
);
ec
.
verify
(
);
verify
(
myEjb
);
}
@Test
public
void
testCreateException
()
throws
Exception
{
final
String
jndiName
=
"foo"
;
final
CreateException
cex
=
new
CreateException
();
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
home
.
create
();
mc
.
setThrowable
(
cex
);
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
expect
(
home
.
create
()).
andThrow
(
cex
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
throws
NamingException
{
...
...
@@ -149,17 +145,17 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
assertSame
(
cex
,
ex
.
getCause
());
}
mc
.
verify
(
);
verify
(
home
);
}
@Test
public
void
testNoBusinessInterfaceSpecified
()
throws
Exception
{
// Will do JNDI lookup to get home but won't call create
// Could actually try to figure out interface from create?
final
String
jndiName
=
"foo"
;
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
throws
NamingException
{
...
...
@@ -188,7 +184,7 @@ public class LocalStatelessSessionProxyFactoryBeanTests extends TestCase {
}
// Expect no methods on home
mc
.
verify
(
);
verify
(
home
);
}
...
...
org.springframework.
testsuite
/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
→
org.springframework.
context
/src/test/java/org/springframework/ejb/access/SimpleRemoteSlsbInvokerInterceptorTests.java
浏览文件 @
0b0c8f15
...
...
@@ -16,6 +16,9 @@
package
org.springframework.ejb.access
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
junit
.
Assert
.*;
import
java.rmi.ConnectException
;
import
java.rmi.RemoteException
;
...
...
@@ -25,9 +28,7 @@ import javax.ejb.EJBObject;
import
javax.naming.Context
;
import
javax.naming.NamingException
;
import
junit.framework.TestCase
;
import
org.easymock.MockControl
;
import
org.junit.Test
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.jndi.JndiTemplate
;
import
org.springframework.remoting.RemoteAccessException
;
...
...
@@ -35,35 +36,31 @@ import org.springframework.remoting.RemoteAccessException;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @author Chris Beams
*/
public
class
SimpleRemoteSlsbInvokerInterceptorTests
extends
TestCase
{
public
class
SimpleRemoteSlsbInvokerInterceptorTests
{
private
MockControl
contextControl
(
private
Context
mockContext
(
String
jndiName
,
RemoteInterface
ejbInstance
,
int
createCount
,
int
lookupCount
,
int
closeCount
)
throws
Exception
{
MockControl
homeControl
=
MockControl
.
createControl
(
SlsbHome
.
class
);
final
SlsbHome
mockHome
=
(
SlsbHome
)
homeControl
.
getMock
();
mockHome
.
create
();
homeControl
.
setReturnValue
(
ejbInstance
,
createCount
);
homeControl
.
replay
();
final
SlsbHome
mockHome
=
createMock
(
SlsbHome
.
class
);
expect
(
mockHome
.
create
()).
andReturn
(
ejbInstance
).
times
(
createCount
);
replay
(
mockHome
);
MockControl
ctxControl
=
MockControl
.
createControl
(
Context
.
class
);
final
Context
mockCtx
=
(
Context
)
ctxControl
.
getMock
();
final
Context
mockCtx
=
createMock
(
Context
.
class
);
mockCtx
.
lookup
(
"java:comp/env/"
+
jndiName
);
ctxControl
.
setReturnValue
(
mockHome
,
lookupCount
);
expect
(
mockCtx
.
lookup
(
"java:comp/env/"
+
jndiName
)).
andReturn
(
mockHome
).
times
(
lookupCount
);
mockCtx
.
close
();
ctxControl
.
setVoidCallable
(
closeCount
);
ctxControl
.
replay
(
);
expectLastCall
().
times
(
closeCount
);
replay
(
mockCtx
);
return
ctxControl
;
return
mockCtx
;
}
private
SimpleRemoteSlsbInvokerInterceptor
configuredInterceptor
(
MockControl
ctxControl
,
String
jndiName
)
throws
Exception
{
final
Context
mockCtx
,
String
jndiName
)
throws
Exception
{
final
Context
mockCtx
=
(
Context
)
ctxControl
.
getMock
();
SimpleRemoteSlsbInvokerInterceptor
si
=
createInterceptor
();
si
.
setJndiTemplate
(
new
JndiTemplate
()
{
protected
Context
createInitialContext
()
{
...
...
@@ -80,7 +77,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
return
new
SimpleRemoteSlsbInvokerInterceptor
();
}
protected
Object
configuredProxy
(
SimpleRemoteSlsbInvokerInterceptor
si
,
Class
ifc
)
throws
NamingException
{
protected
Object
configuredProxy
(
SimpleRemoteSlsbInvokerInterceptor
si
,
Class
<?>
ifc
)
throws
NamingException
{
si
.
afterPropertiesSet
();
ProxyFactory
pf
=
new
ProxyFactory
(
new
Class
[]
{
ifc
});
pf
.
addAdvice
(
si
);
...
...
@@ -88,38 +85,38 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
}
@Test
public
void
testPerformsLookup
()
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejbControl
.
replay
();
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
replay
(
ejb
);
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
1
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
1
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
RemoteInterface
target
=
(
RemoteInterface
)
configuredProxy
(
si
,
RemoteInterface
.
class
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
configuredProxy
(
si
,
RemoteInterface
.
class
);
contextControl
.
verify
(
);
verify
(
mockContext
);
}
@Test
public
void
testPerformsLookupWithAccessContext
()
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setReturnValue
(
null
);
ejbControl
.
replay
();
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andReturn
(
null
);
replay
(
ejb
);
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
2
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
2
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
si
.
setExposeAccessContext
(
true
);
RemoteInterface
target
=
(
RemoteInterface
)
configuredProxy
(
si
,
RemoteInterface
.
class
);
assertNull
(
target
.
targetMethod
());
contextControl
.
verify
(
);
verify
(
mockContext
);
}
@Test
public
void
testLookupFailure
()
throws
Exception
{
final
NamingException
nex
=
new
NamingException
();
final
String
jndiName
=
"foobar"
;
...
...
@@ -144,31 +141,32 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
}
}
@Test
public
void
testInvokesMethodOnEjbInstance
()
throws
Exception
{
doTestInvokesMethodOnEjbInstance
(
true
,
true
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithLazyLookup
()
throws
Exception
{
doTestInvokesMethodOnEjbInstance
(
false
,
true
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithLazyLookupAndNoCache
()
throws
Exception
{
doTestInvokesMethodOnEjbInstance
(
false
,
false
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithNoCache
()
throws
Exception
{
doTestInvokesMethodOnEjbInstance
(
true
,
false
);
}
private
void
doTestInvokesMethodOnEjbInstance
(
boolean
lookupHomeOnStartup
,
boolean
cacheHome
)
throws
Exception
{
Object
retVal
=
new
Object
();
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setReturnValue
(
retVal
,
2
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andReturn
(
retVal
).
times
(
2
);
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
2
);
ejbControl
.
replay
();
replay
(
ejb
);
int
lookupCount
=
1
;
if
(!
cacheHome
)
{
...
...
@@ -179,9 +177,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
}
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
2
,
lookupCount
,
lookupCount
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
2
,
lookupCount
,
lookupCount
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
si
.
setLookupHomeOnStartup
(
lookupHomeOnStartup
);
si
.
setCacheHome
(
cacheHome
);
...
...
@@ -189,46 +187,40 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
assertTrue
(
target
.
targetMethod
()
==
retVal
);
assertTrue
(
target
.
targetMethod
()
==
retVal
);
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithHomeInterface
()
throws
Exception
{
Object
retVal
=
new
Object
();
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setReturnValue
(
retVal
,
1
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andReturn
(
retVal
);
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
1
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
1
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
si
.
setHomeInterface
(
SlsbHome
.
class
);
RemoteInterface
target
=
(
RemoteInterface
)
configuredProxy
(
si
,
RemoteInterface
.
class
);
assertTrue
(
target
.
targetMethod
()
==
retVal
);
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithRemoteException
()
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setThrowable
(
new
RemoteException
(),
1
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andThrow
(
new
RemoteException
());
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
1
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
1
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
RemoteInterface
target
=
(
RemoteInterface
)
configuredProxy
(
si
,
RemoteInterface
.
class
);
try
{
...
...
@@ -239,22 +231,25 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
// expected
}
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh
()
throws
Exception
{
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh
(
true
,
true
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookup
()
throws
Exception
{
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh
(
false
,
true
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndLazyLookupAndNoCache
()
throws
Exception
{
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh
(
false
,
false
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithConnectExceptionWithRefreshAndNoCache
()
throws
Exception
{
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh
(
true
,
false
);
}
...
...
@@ -262,13 +257,11 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
private
void
doTestInvokesMethodOnEjbInstanceWithConnectExceptionWithRefresh
(
boolean
lookupHomeOnStartup
,
boolean
cacheHome
)
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setThrowable
(
new
ConnectException
(
""
),
2
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andThrow
(
new
ConnectException
(
""
)).
times
(
2
);
ejb
.
remove
();
e
jbControl
.
setVoidCallable
(
2
);
ejbControl
.
replay
(
);
e
xpectLastCall
().
times
(
2
);
replay
(
ejb
);
int
lookupCount
=
2
;
if
(!
cacheHome
)
{
...
...
@@ -279,9 +272,9 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
}
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
2
,
lookupCount
,
lookupCount
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
2
,
lookupCount
,
lookupCount
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
si
.
setRefreshHomeOnConnectFailure
(
true
);
si
.
setLookupHomeOnStartup
(
lookupHomeOnStartup
);
si
.
setCacheHome
(
cacheHome
);
...
...
@@ -295,45 +288,39 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
// expected
}
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithBusinessInterface
()
throws
Exception
{
Object
retVal
=
new
Object
();
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setReturnValue
(
retVal
,
1
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andReturn
(
retVal
);
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
1
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
1
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
BusinessInterface
target
=
(
BusinessInterface
)
configuredProxy
(
si
,
BusinessInterface
.
class
);
assertTrue
(
target
.
targetMethod
()
==
retVal
);
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
@Test
public
void
testInvokesMethodOnEjbInstanceWithBusinessInterfaceWithRemoteException
()
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setThrowable
(
new
RemoteException
(),
1
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andThrow
(
new
RemoteException
());
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
1
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
1
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
BusinessInterface
target
=
(
BusinessInterface
)
configuredProxy
(
si
,
BusinessInterface
.
class
);
try
{
...
...
@@ -344,31 +331,29 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
// expected
}
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
@Test
public
void
testApplicationException
()
throws
Exception
{
doTestException
(
new
ApplicationException
());
}
@Test
public
void
testRemoteException
()
throws
Exception
{
doTestException
(
new
RemoteException
());
}
private
void
doTestException
(
Exception
expected
)
throws
Exception
{
MockControl
ejbControl
=
MockControl
.
createControl
(
RemoteInterface
.
class
);
final
RemoteInterface
ejb
=
(
RemoteInterface
)
ejbControl
.
getMock
();
ejb
.
targetMethod
();
ejbControl
.
setThrowable
(
expected
);
final
RemoteInterface
ejb
=
createMock
(
RemoteInterface
.
class
);
expect
(
ejb
.
targetMethod
()).
andThrow
(
expected
);
ejb
.
remove
();
ejbControl
.
setVoidCallable
(
1
);
ejbControl
.
replay
();
replay
(
ejb
);
final
String
jndiName
=
"foobar"
;
MockControl
contextControl
=
contextControl
(
jndiName
,
ejb
,
1
,
1
,
1
);
Context
mockContext
=
mockContext
(
jndiName
,
ejb
,
1
,
1
,
1
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
contextControl
,
jndiName
);
SimpleRemoteSlsbInvokerInterceptor
si
=
configuredInterceptor
(
mockContext
,
jndiName
);
RemoteInterface
target
=
(
RemoteInterface
)
configuredProxy
(
si
,
RemoteInterface
.
class
);
try
{
...
...
@@ -379,8 +364,7 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
assertTrue
(
thrown
==
expected
);
}
contextControl
.
verify
();
ejbControl
.
verify
();
verify
(
mockContext
,
ejb
);
}
...
...
@@ -406,7 +390,8 @@ public class SimpleRemoteSlsbInvokerInterceptorTests extends TestCase {
}
protected
class
ApplicationException
extends
Exception
{
@SuppressWarnings
(
"serial"
)
protected
class
ApplicationException
extends
Exception
{
public
ApplicationException
()
{
super
(
"appException"
);
...
...
org.springframework.
testsuite
/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java
→
org.springframework.
context
/src/test/java/org/springframework/ejb/access/SimpleRemoteStatelessSessionProxyFactoryBeanTests.java
浏览文件 @
0b0c8f15
...
...
@@ -16,6 +16,9 @@
package
org.springframework.ejb.access
;
import
static
org
.
easymock
.
EasyMock
.*;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.reflect.Proxy
;
import
java.rmi.RemoteException
;
...
...
@@ -24,8 +27,7 @@ import javax.ejb.EJBHome;
import
javax.ejb.EJBObject
;
import
javax.naming.NamingException
;
import
org.easymock.MockControl
;
import
org.junit.Test
;
import
org.springframework.jndi.JndiTemplate
;
import
org.springframework.remoting.RemoteAccessException
;
...
...
@@ -40,30 +42,26 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
return
new
SimpleRemoteStatelessSessionProxyFactoryBean
();
}
protected
Object
configuredProxy
(
SimpleRemoteSlsbInvokerInterceptor
si
,
Class
ifc
)
throws
NamingException
{
protected
Object
configuredProxy
(
SimpleRemoteSlsbInvokerInterceptor
si
,
Class
<?>
ifc
)
throws
NamingException
{
SimpleRemoteStatelessSessionProxyFactoryBean
fb
=
(
SimpleRemoteStatelessSessionProxyFactoryBean
)
si
;
fb
.
setBusinessInterface
(
ifc
);
fb
.
afterPropertiesSet
();
return
fb
.
getObject
();
}
@Test
public
void
testInvokesMethod
()
throws
Exception
{
final
int
value
=
11
;
final
String
jndiName
=
"foo"
;
MockControl
ec
=
MockControl
.
createControl
(
MyEjb
.
class
);
MyEjb
myEjb
=
(
MyEjb
)
ec
.
getMock
();
myEjb
.
getValue
();
ec
.
setReturnValue
(
value
,
1
);
MyEjb
myEjb
=
createMock
(
MyEjb
.
class
);
expect
(
myEjb
.
getValue
()).
andReturn
(
value
);
myEjb
.
remove
();
ec
.
setVoidCallable
(
1
);
ec
.
replay
();
replay
(
myEjb
);
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
home
.
create
();
mc
.
setReturnValue
(
myEjb
,
1
);
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
expect
(
home
.
create
()).
andReturn
(
myEjb
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
{
...
...
@@ -85,19 +83,18 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
MyBusinessMethods
mbm
=
(
MyBusinessMethods
)
fb
.
getObject
();
assertTrue
(
Proxy
.
isProxyClass
(
mbm
.
getClass
()));
assertEquals
(
"Returns expected value"
,
value
,
mbm
.
getValue
());
mc
.
verify
(
);
ec
.
verify
(
);
verify
(
myEjb
);
verify
(
home
);
}
@Test
public
void
testInvokesMethodOnEjb3StyleBean
()
throws
Exception
{
final
int
value
=
11
;
final
String
jndiName
=
"foo"
;
MockControl
ec
=
MockControl
.
createControl
(
MyEjb
.
class
);
final
MyEjb
myEjb
=
(
MyEjb
)
ec
.
getMock
();
myEjb
.
getValue
();
ec
.
setReturnValue
(
value
,
1
);
ec
.
replay
();
final
MyEjb
myEjb
=
createMock
(
MyEjb
.
class
);
expect
(
myEjb
.
getValue
()).
andReturn
(
value
);
replay
(
myEjb
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
{
...
...
@@ -119,28 +116,24 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
MyBusinessMethods
mbm
=
(
MyBusinessMethods
)
fb
.
getObject
();
assertTrue
(
Proxy
.
isProxyClass
(
mbm
.
getClass
()));
assertEquals
(
"Returns expected value"
,
value
,
mbm
.
getValue
());
ec
.
verify
(
);
verify
(
myEjb
);
}
@Test
public
void
testRemoteException
()
throws
Exception
{
final
RemoteException
rex
=
new
RemoteException
();
final
String
jndiName
=
"foo"
;
MockControl
ec
=
MockControl
.
createControl
(
MyEjb
.
class
);
MyEjb
myEjb
=
(
MyEjb
)
ec
.
getMock
();
myEjb
.
getValue
();
ec
.
setThrowable
(
rex
);
MyEjb
myEjb
=
createMock
(
MyEjb
.
class
);
expect
(
myEjb
.
getValue
()).
andThrow
(
rex
);
// TODO might want to control this behaviour...
// Do we really want to call remove after a remote exception?
myEjb
.
remove
();
ec
.
setVoidCallable
(
1
);
ec
.
replay
();
replay
(
myEjb
);
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
home
.
create
();
mc
.
setReturnValue
(
myEjb
,
1
);
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
expect
(
home
.
create
()).
andReturn
(
myEjb
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
{
...
...
@@ -168,19 +161,18 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
catch
(
RemoteException
ex
)
{
assertSame
(
"Threw expected RemoteException"
,
rex
,
ex
);
}
mc
.
verify
(
);
ec
.
verify
(
);
verify
(
myEjb
);
verify
(
home
);
}
@Test
public
void
testCreateException
()
throws
Exception
{
final
String
jndiName
=
"foo"
;
final
CreateException
cex
=
new
CreateException
();
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
home
.
create
();
mc
.
setThrowable
(
cex
);
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
expect
(
home
.
create
()).
andThrow
(
cex
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
{
...
...
@@ -211,18 +203,17 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
// expected
}
mc
.
verify
(
);
verify
(
home
);
}
@Test
public
void
testCreateExceptionWithLocalBusinessInterface
()
throws
Exception
{
final
String
jndiName
=
"foo"
;
final
CreateException
cex
=
new
CreateException
();
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
home
.
create
();
mc
.
setThrowable
(
cex
);
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
expect
(
home
.
create
()).
andThrow
(
cex
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
{
...
...
@@ -253,17 +244,17 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
assertTrue
(
ex
.
getCause
()
==
cex
);
}
mc
.
verify
(
);
verify
(
home
);
}
@Test
public
void
testNoBusinessInterfaceSpecified
()
throws
Exception
{
// Will do JNDI lookup to get home but won't call create
// Could actually try to figure out interface from create?
final
String
jndiName
=
"foo"
;
MockControl
mc
=
MockControl
.
createControl
(
MyHome
.
class
);
final
MyHome
home
=
(
MyHome
)
mc
.
getMock
();
mc
.
replay
();
final
MyHome
home
=
createMock
(
MyHome
.
class
);
replay
(
home
);
JndiTemplate
jt
=
new
JndiTemplate
()
{
public
Object
lookup
(
String
name
)
throws
NamingException
{
...
...
@@ -292,7 +283,7 @@ public class SimpleRemoteStatelessSessionProxyFactoryBeanTests extends SimpleRem
}
// Expect no methods on home
mc
.
verify
(
);
verify
(
home
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录