Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
5cb1b1d1
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 搜索 >>
提交
5cb1b1d1
编写于
12月 12, 2008
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moving unit tests from .testsuite -> .aop
上级
56908e32
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
371 addition
and
63 deletion
+371
-63
org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
...ork/aop/framework/autoproxy/AbstractAutoProxyCreator.java
+13
-13
org.springframework.aop/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java
...org/springframework/aop/framework/AopProxyUtilsTests.java
+25
-15
org.springframework.aop/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java
...ngframework/aop/framework/IntroductionBenchmarkTests.java
+8
-10
org.springframework.testsuite/.settings/org.eclipse.jdt.core.prefs
...gframework.testsuite/.settings/org.eclipse.jdt.core.prefs
+257
-1
org.springframework.testsuite/.settings/org.eclipse.jdt.ui.prefs
...ingframework.testsuite/.settings/org.eclipse.jdt.ui.prefs
+4
-0
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java
...aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java
+23
-3
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java
...mework/aop/framework/autoproxy/AutoProxyCreatorTests.java
+19
-8
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorInitTests.java
...ramework/autoproxy/BeanNameAutoProxyCreatorInitTests.java
+6
-9
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java
...op/framework/autoproxy/BeanNameAutoProxyCreatorTests.java
+16
-4
未找到文件。
org.springframework.aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java
浏览文件 @
5cb1b1d1
...
...
@@ -144,7 +144,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
private
final
Set
<
Object
>
nonAdvisedBeans
=
Collections
.
synchronizedSet
(
new
HashSet
<
Object
>());
private
final
Map
<
Object
,
Class
>
proxyTypes
=
new
ConcurrentHashMap
<
Object
,
Class
>();
private
final
Map
<
Object
,
Class
<?>>
proxyTypes
=
new
ConcurrentHashMap
<
Object
,
Class
<?>
>();
/**
...
...
@@ -253,12 +253,12 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
}
public
Class
predictBeanType
(
Class
beanClass
,
String
beanName
)
{
public
Class
<?>
predictBeanType
(
Class
<?>
beanClass
,
String
beanName
)
{
Object
cacheKey
=
getCacheKey
(
beanClass
,
beanName
);
return
this
.
proxyTypes
.
get
(
cacheKey
);
}
public
Constructor
[]
determineCandidateConstructors
(
Class
beanClass
,
String
beanName
)
throws
BeansException
{
public
Constructor
<?>[]
determineCandidateConstructors
(
Class
<?>
beanClass
,
String
beanName
)
throws
BeansException
{
return
null
;
}
...
...
@@ -268,7 +268,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
return
wrapIfNecessary
(
bean
,
beanName
,
cacheKey
);
}
public
Object
postProcessBeforeInstantiation
(
Class
beanClass
,
String
beanName
)
throws
BeansException
{
public
Object
postProcessBeforeInstantiation
(
Class
<?>
beanClass
,
String
beanName
)
throws
BeansException
{
Object
cacheKey
=
getCacheKey
(
beanClass
,
beanName
);
if
(!
this
.
targetSourcedBeans
.
contains
(
cacheKey
))
{
...
...
@@ -332,7 +332,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @param beanName the bean name
* @return the cache key for the given class and name
*/
protected
Object
getCacheKey
(
Class
beanClass
,
String
beanName
)
{
protected
Object
getCacheKey
(
Class
<?>
beanClass
,
String
beanName
)
{
return
beanClass
.
getName
()
+
"_"
+
beanName
;
}
...
...
@@ -379,7 +379,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @see org.aopalliance.intercept.MethodInterceptor
* @see #shouldSkip
*/
protected
boolean
isInfrastructureClass
(
Class
beanClass
)
{
protected
boolean
isInfrastructureClass
(
Class
<?>
beanClass
)
{
boolean
retVal
=
Advisor
.
class
.
isAssignableFrom
(
beanClass
)
||
Advice
.
class
.
isAssignableFrom
(
beanClass
)
||
AopInfrastructureBean
.
class
.
isAssignableFrom
(
beanClass
);
...
...
@@ -398,7 +398,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @param beanName the name of the bean
* @return whether to skip the given bean
*/
protected
boolean
shouldSkip
(
Class
beanClass
,
String
beanName
)
{
protected
boolean
shouldSkip
(
Class
<?>
beanClass
,
String
beanName
)
{
return
false
;
}
...
...
@@ -412,7 +412,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @return a TargetSource for this bean
* @see #setCustomTargetSourceCreators
*/
protected
TargetSource
getCustomTargetSource
(
Class
beanClass
,
String
beanName
)
{
protected
TargetSource
getCustomTargetSource
(
Class
<?>
beanClass
,
String
beanName
)
{
// We can't create fancy target sources for directly registered singletons.
if
(
this
.
customTargetSourceCreators
!=
null
&&
this
.
beanFactory
!=
null
&&
this
.
beanFactory
.
containsBean
(
beanName
))
{
...
...
@@ -445,7 +445,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @see #buildAdvisors
*/
protected
Object
createProxy
(
Class
beanClass
,
String
beanName
,
Object
[]
specificInterceptors
,
TargetSource
targetSource
)
{
Class
<?>
beanClass
,
String
beanName
,
Object
[]
specificInterceptors
,
TargetSource
targetSource
)
{
ProxyFactory
proxyFactory
=
new
ProxyFactory
();
// Copy our properties (proxyTargetClass etc) inherited from ProxyConfig.
...
...
@@ -454,8 +454,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
if
(!
shouldProxyTargetClass
(
beanClass
,
beanName
))
{
// Must allow for introductions; can't just set interfaces to
// the target's interfaces only.
Class
[]
targetInterfaces
=
ClassUtils
.
getAllInterfacesForClass
(
beanClass
,
this
.
proxyClassLoader
);
for
(
Class
targetInterface
:
targetInterfaces
)
{
Class
<?>
[]
targetInterfaces
=
ClassUtils
.
getAllInterfacesForClass
(
beanClass
,
this
.
proxyClassLoader
);
for
(
Class
<?>
targetInterface
:
targetInterfaces
)
{
proxyFactory
.
addInterface
(
targetInterface
);
}
}
...
...
@@ -487,7 +487,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @return whether the given bean should be proxied with its target class
* @see AutoProxyUtils#shouldProxyTargetClass
*/
protected
boolean
shouldProxyTargetClass
(
Class
beanClass
,
String
beanName
)
{
protected
boolean
shouldProxyTargetClass
(
Class
<?>
beanClass
,
String
beanName
)
{
return
(
isProxyTargetClass
()
||
(
this
.
beanFactory
instanceof
ConfigurableListableBeanFactory
&&
AutoProxyUtils
.
shouldProxyTargetClass
((
ConfigurableListableBeanFactory
)
this
.
beanFactory
,
beanName
)));
...
...
@@ -591,6 +591,6 @@ public abstract class AbstractAutoProxyCreator extends ProxyConfig
* @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS
*/
protected
abstract
Object
[]
getAdvicesAndAdvisorsForBean
(
Class
beanClass
,
String
beanName
,
TargetSource
customTargetSource
)
throws
BeansException
;
Class
<?>
beanClass
,
String
beanName
,
TargetSource
customTargetSource
)
throws
BeansException
;
}
org.springframework.
testsuite
/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java
→
org.springframework.
aop
/src/test/java/org/springframework/aop/framework/AopProxyUtilsTests.java
浏览文件 @
5cb1b1d1
...
...
@@ -16,105 +16,115 @@
package
org.springframework.aop.framework
;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Proxy
;
import
java.util.Arrays
;
import
java.util.List
;
import
junit.framework.TestCase
;
import
org.junit.Test
;
import
org.springframework.aop.SpringProxy
;
import
org.springframework.beans.ITestBean
;
import
org.springframework.beans.TestBean
;
/**
* @author Rod Johnson
* @author Chris Beams
*/
public
class
AopProxyUtilsTests
extends
TestCase
{
public
class
AopProxyUtilsTests
{
@Test
public
void
testCompleteProxiedInterfacesWorksWithNull
()
{
AdvisedSupport
as
=
new
AdvisedSupport
();
Class
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
Class
<?>
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
assertEquals
(
2
,
completedInterfaces
.
length
);
List
ifaces
=
Arrays
.
asList
(
completedInterfaces
);
List
<?>
ifaces
=
Arrays
.
asList
(
completedInterfaces
);
assertTrue
(
ifaces
.
contains
(
Advised
.
class
));
assertTrue
(
ifaces
.
contains
(
SpringProxy
.
class
));
}
@Test
public
void
testCompleteProxiedInterfacesWorksWithNullOpaque
()
{
AdvisedSupport
as
=
new
AdvisedSupport
();
as
.
setOpaque
(
true
);
Class
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
Class
<?>
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
assertEquals
(
1
,
completedInterfaces
.
length
);
}
@Test
public
void
testCompleteProxiedInterfacesAdvisedNotIncluded
()
{
AdvisedSupport
as
=
new
AdvisedSupport
();
as
.
addInterface
(
ITestBean
.
class
);
as
.
addInterface
(
Comparable
.
class
);
Class
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
Class
<?>
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
assertEquals
(
4
,
completedInterfaces
.
length
);
// Can't assume ordering for others, so use a list
List
l
=
Arrays
.
asList
(
completedInterfaces
);
List
<?>
l
=
Arrays
.
asList
(
completedInterfaces
);
assertTrue
(
l
.
contains
(
Advised
.
class
));
assertTrue
(
l
.
contains
(
ITestBean
.
class
));
assertTrue
(
l
.
contains
(
Comparable
.
class
));
}
@Test
public
void
testCompleteProxiedInterfacesAdvisedIncluded
()
{
AdvisedSupport
as
=
new
AdvisedSupport
();
as
.
addInterface
(
ITestBean
.
class
);
as
.
addInterface
(
Comparable
.
class
);
as
.
addInterface
(
Advised
.
class
);
Class
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
Class
<?>
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
assertEquals
(
4
,
completedInterfaces
.
length
);
// Can't assume ordering for others, so use a list
List
l
=
Arrays
.
asList
(
completedInterfaces
);
List
<?>
l
=
Arrays
.
asList
(
completedInterfaces
);
assertTrue
(
l
.
contains
(
Advised
.
class
));
assertTrue
(
l
.
contains
(
ITestBean
.
class
));
assertTrue
(
l
.
contains
(
Comparable
.
class
));
}
@Test
public
void
testCompleteProxiedInterfacesAdvisedNotIncludedOpaque
()
{
AdvisedSupport
as
=
new
AdvisedSupport
();
as
.
setOpaque
(
true
);
as
.
addInterface
(
ITestBean
.
class
);
as
.
addInterface
(
Comparable
.
class
);
Class
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
Class
<?>
[]
completedInterfaces
=
AopProxyUtils
.
completeProxiedInterfaces
(
as
);
assertEquals
(
3
,
completedInterfaces
.
length
);
// Can't assume ordering for others, so use a list
List
l
=
Arrays
.
asList
(
completedInterfaces
);
List
<?>
l
=
Arrays
.
asList
(
completedInterfaces
);
assertFalse
(
l
.
contains
(
Advised
.
class
));
assertTrue
(
l
.
contains
(
ITestBean
.
class
));
assertTrue
(
l
.
contains
(
Comparable
.
class
));
}
@Test
public
void
testProxiedUserInterfacesWithSingleInterface
()
{
ProxyFactory
pf
=
new
ProxyFactory
();
pf
.
setTarget
(
new
TestBean
());
pf
.
addInterface
(
ITestBean
.
class
);
Object
proxy
=
pf
.
getProxy
();
Class
[]
userInterfaces
=
AopProxyUtils
.
proxiedUserInterfaces
(
proxy
);
Class
<?>
[]
userInterfaces
=
AopProxyUtils
.
proxiedUserInterfaces
(
proxy
);
assertEquals
(
1
,
userInterfaces
.
length
);
assertEquals
(
ITestBean
.
class
,
userInterfaces
[
0
]);
}
@Test
public
void
testProxiedUserInterfacesWithMultipleInterfaces
()
{
ProxyFactory
pf
=
new
ProxyFactory
();
pf
.
setTarget
(
new
TestBean
());
pf
.
addInterface
(
ITestBean
.
class
);
pf
.
addInterface
(
Comparable
.
class
);
Object
proxy
=
pf
.
getProxy
();
Class
[]
userInterfaces
=
AopProxyUtils
.
proxiedUserInterfaces
(
proxy
);
Class
<?>
[]
userInterfaces
=
AopProxyUtils
.
proxiedUserInterfaces
(
proxy
);
assertEquals
(
2
,
userInterfaces
.
length
);
assertEquals
(
ITestBean
.
class
,
userInterfaces
[
0
]);
assertEquals
(
Comparable
.
class
,
userInterfaces
[
1
]);
}
@Test
public
void
testProxiedUserInterfacesWithNoInterface
()
{
Object
proxy
=
Proxy
.
newProxyInstance
(
getClass
().
getClassLoader
(),
new
Class
[
0
],
new
InvocationHandler
()
{
...
...
@@ -123,7 +133,7 @@ public class AopProxyUtilsTests extends TestCase {
}
});
try
{
Class
[]
userInterfaces
=
AopProxyUtils
.
proxiedUserInterfaces
(
proxy
);
AopProxyUtils
.
proxiedUserInterfaces
(
proxy
);
fail
(
"Should have thrown IllegalArgumentException"
);
}
catch
(
IllegalArgumentException
ex
)
{
...
...
org.springframework.
testsuite
/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java
→
org.springframework.
aop
/src/test/java/org/springframework/aop/framework/IntroductionBenchmarkTests.java
浏览文件 @
5cb1b1d1
...
...
@@ -16,8 +16,7 @@
package
org.springframework.aop.framework
;
import
junit.framework.TestCase
;
import
org.junit.Test
;
import
org.springframework.aop.support.DelegatingIntroductionInterceptor
;
import
org.springframework.beans.ITestBean
;
import
org.springframework.beans.TestBean
;
...
...
@@ -26,10 +25,13 @@ import org.springframework.util.StopWatch;
/**
* Benchmarks for introductions.
*
* NOTE: No assertions!
*
* @author Rod Johnson
* @author Chris Beams
* @since 2.0
*/
public
class
IntroductionBenchmarkTests
extends
TestCase
{
public
class
IntroductionBenchmarkTests
{
private
static
final
int
EXPECTED_COMPARE
=
13
;
...
...
@@ -37,12 +39,8 @@ public class IntroductionBenchmarkTests extends TestCase {
private
static
final
int
INVOCATIONS
=
100000
;
public
void
testBenchmarks
()
{
timeManyInvocations
();
}
@SuppressWarnings
(
"serial"
)
public
static
class
SimpleCounterIntroduction
extends
DelegatingIntroductionInterceptor
implements
Counter
{
public
int
getCount
()
{
return
EXPECTED_COMPARE
;
}
...
...
@@ -52,7 +50,8 @@ public class IntroductionBenchmarkTests extends TestCase {
int
getCount
();
}
protected
long
timeManyInvocations
()
{
@Test
public
void
timeManyInvocations
()
{
StopWatch
sw
=
new
StopWatch
();
TestBean
target
=
new
TestBean
();
...
...
@@ -82,6 +81,5 @@ public class IntroductionBenchmarkTests extends TestCase {
sw
.
stop
();
System
.
out
.
println
(
sw
.
prettyPrint
());
return
sw
.
getLastTaskTimeMillis
();
}
}
org.springframework.testsuite/.settings/org.eclipse.jdt.core.prefs
浏览文件 @
5cb1b1d1
此差异已折叠。
点击以展开。
org.springframework.testsuite/.settings/org.eclipse.jdt.ui.prefs
0 → 100644
浏览文件 @
5cb1b1d1
#Fri Dec 12 10:33:53 PST 2008
eclipse.preferences.version=1
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
formatter_settings_version=11
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorTests.java
浏览文件 @
5cb1b1d1
...
...
@@ -16,12 +16,15 @@
package
org.springframework.aop.framework.autoproxy
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.io.IOException
;
import
javax.servlet.ServletException
;
import
junit.framework.TestCase
;
import
org.junit.Test
;
import
org.springframework.aop.framework.Advised
;
import
org.springframework.aop.framework.CountingBeforeAdvice
;
import
org.springframework.aop.framework.Lockable
;
...
...
@@ -41,8 +44,9 @@ import org.springframework.transaction.CallCountingTransactionManager;
* Tests for auto proxy creation by advisor recognition.
*
* @author Rod Johnson
* @author Chris Beams
*/
public
class
AdvisorAutoProxyCreatorTests
extends
TestCase
{
public
class
AdvisorAutoProxyCreatorTests
{
private
static
final
String
ADVISOR_APC_BEAN_NAME
=
"aapc"
;
...
...
@@ -55,6 +59,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
return
new
ClassPathXmlApplicationContext
(
"/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml"
);
}
@Test
public
void
testDefaultExclusionPrefix
()
throws
Exception
{
DefaultAdvisorAutoProxyCreator
aapc
=
(
DefaultAdvisorAutoProxyCreator
)
getBeanFactory
().
getBean
(
ADVISOR_APC_BEAN_NAME
);
assertEquals
(
ADVISOR_APC_BEAN_NAME
+
DefaultAdvisorAutoProxyCreator
.
SEPARATOR
,
aapc
.
getAdvisorBeanNamePrefix
());
...
...
@@ -64,18 +69,21 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
/**
* If no pointcuts match (no attrs) there should be proxying.
*/
@Test
public
void
testNoProxy
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
Object
o
=
bf
.
getBean
(
"noSetters"
);
assertFalse
(
AopUtils
.
isAopProxy
(
o
));
}
@Test
public
void
testTxIsProxied
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
ITestBean
test
=
(
ITestBean
)
bf
.
getBean
(
"test"
);
assertTrue
(
AopUtils
.
isAopProxy
(
test
));
}
@Test
public
void
testRegexpApplied
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
ITestBean
test
=
(
ITestBean
)
bf
.
getBean
(
"test"
);
...
...
@@ -90,6 +98,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
* appear in the chain before "specific" interceptors,
* which are sourced from matching advisors
*/
@Test
public
void
testCommonInterceptorAndAdvisor
()
throws
Exception
{
BeanFactory
bf
=
new
ClassPathXmlApplicationContext
(
"/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml"
);
ITestBean
test1
=
(
ITestBean
)
bf
.
getBean
(
"test1"
);
...
...
@@ -119,6 +128,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
* We have custom TargetSourceCreators but there's no match, and
* hence no proxying, for this bean
*/
@Test
public
void
testCustomTargetSourceNoMatch
()
throws
Exception
{
BeanFactory
bf
=
new
ClassPathXmlApplicationContext
(
"/org/springframework/aop/framework/autoproxy/customTargetSource.xml"
);
ITestBean
test
=
(
ITestBean
)
bf
.
getBean
(
"test"
);
...
...
@@ -127,6 +137,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals
(
"Kerry"
,
test
.
getSpouse
().
getName
());
}
@Test
public
void
testCustomPrototypeTargetSource
()
throws
Exception
{
CountingTestBean
.
count
=
0
;
BeanFactory
bf
=
new
ClassPathXmlApplicationContext
(
"/org/springframework/aop/framework/autoproxy/customTargetSource.xml"
);
...
...
@@ -141,6 +152,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
CountingTestBean
.
count
=
0
;
}
@Test
public
void
testLazyInitTargetSource
()
throws
Exception
{
CountingTestBean
.
count
=
0
;
BeanFactory
bf
=
new
ClassPathXmlApplicationContext
(
"/org/springframework/aop/framework/autoproxy/customTargetSource.xml"
);
...
...
@@ -155,6 +167,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
CountingTestBean
.
count
=
0
;
}
@Test
public
void
testQuickTargetSourceCreator
()
throws
Exception
{
ClassPathXmlApplicationContext
bf
=
new
ClassPathXmlApplicationContext
(
"/org/springframework/aop/framework/autoproxy/quickTargetSource.xml"
);
...
...
@@ -200,6 +213,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
}
/*
@Test
public void testIntroductionIsProxied() throws Exception {
BeanFactory bf = getBeanFactory();
Object modifiable = bf.getBean("modifiable1");
...
...
@@ -209,6 +223,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
}
*/
@Test
public
void
testTransactionAttributeOnMethod
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
ITestBean
test
=
(
ITestBean
)
bf
.
getBean
(
"test"
);
...
...
@@ -230,6 +245,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
/**
* Should not roll back on servlet exception.
*/
@Test
public
void
testRollbackRulesOnMethodCauseRollback
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
Rollback
rb
=
(
Rollback
)
bf
.
getBean
(
"rollback"
);
...
...
@@ -255,6 +271,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals
(
"Transaction counts match"
,
1
,
txMan
.
rollbacks
);
}
@Test
public
void
testRollbackRulesOnMethodPreventRollback
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
Rollback
rb
=
(
Rollback
)
bf
.
getBean
(
"rollback"
);
...
...
@@ -272,6 +289,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals
(
"Transaction counts match"
,
1
,
txMan
.
commits
);
}
@Test
public
void
testProgrammaticRollback
()
throws
Exception
{
BeanFactory
bf
=
getBeanFactory
();
...
...
@@ -289,6 +307,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
assertEquals
(
1
,
txMan
.
rollbacks
);
}
@Test
public
void
testWithOptimizedProxy
()
throws
Exception
{
BeanFactory
beanFactory
=
new
ClassPathXmlApplicationContext
(
"org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml"
);
...
...
@@ -311,6 +330,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
* The Modifiable behaviour of each instance of TestBean should be distinct.
*/
/*
@Test
public void testIntroductionViaPrototype() throws Exception {
BeanFactory bf = getBeanFactory();
...
...
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java
浏览文件 @
5cb1b1d1
...
...
@@ -16,11 +16,13 @@
package
org.springframework.aop.framework.autoproxy
;
import
static
org
.
junit
.
Assert
.*;
import
java.lang.reflect.Proxy
;
import
junit.framework.TestCase
;
import
org.aopalliance.intercept.MethodInterceptor
;
import
org.aopalliance.intercept.MethodInvocation
;
import
org.junit.Test
;
import
org.springframework.aop.TargetSource
;
import
org.springframework.aop.support.AopUtils
;
...
...
@@ -38,10 +40,12 @@ import org.springframework.context.support.StaticMessageSource;
/**
* @author Juergen Hoeller
* @author Chris Beams
* @since 09.12.2003
*/
public
class
AutoProxyCreatorTests
extends
TestCase
{
public
class
AutoProxyCreatorTests
{
@Test
public
void
testBeanNameAutoProxyCreator
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
sac
.
registerSingleton
(
"testInterceptor"
,
TestInterceptor
.
class
);
...
...
@@ -90,6 +94,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals
(
7
,
ti
.
nrOfInvocations
);
}
@Test
public
void
testBeanNameAutoProxyCreatorWithFactoryBeanProxy
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
sac
.
registerSingleton
(
"testInterceptor"
,
TestInterceptor
.
class
);
...
...
@@ -114,7 +119,7 @@ public class AutoProxyCreatorTests extends TestCase {
singletonToBeProxied
.
getName
();
assertEquals
(
1
,
ti
.
nrOfInvocations
);
FactoryBean
factory
=
(
FactoryBean
)
sac
.
getBean
(
"&singletonFactoryToBeProxied"
);
FactoryBean
<?>
factory
=
(
FactoryBean
<?>
)
sac
.
getBean
(
"&singletonFactoryToBeProxied"
);
assertTrue
(
Proxy
.
isProxyClass
(
factory
.
getClass
()));
TestBean
tb
=
(
TestBean
)
sac
.
getBean
(
"singletonFactoryToBeProxied"
);
assertFalse
(
AopUtils
.
isAopProxy
(
tb
));
...
...
@@ -123,6 +128,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals
(
3
,
ti
.
nrOfInvocations
);
}
@Test
public
void
testCustomAutoProxyCreator
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
sac
.
registerSingleton
(
"testAutoProxyCreator"
,
TestAutoProxyCreator
.
class
);
...
...
@@ -150,6 +156,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals
(
2
,
tapc
.
testInterceptor
.
nrOfInvocations
);
}
@Test
public
void
testAutoProxyCreatorWithFactoryBean
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
sac
.
registerSingleton
(
"testAutoProxyCreator"
,
TestAutoProxyCreator
.
class
);
...
...
@@ -159,7 +166,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator
tapc
=
(
TestAutoProxyCreator
)
sac
.
getBean
(
"testAutoProxyCreator"
);
tapc
.
testInterceptor
.
nrOfInvocations
=
0
;
FactoryBean
factory
=
(
FactoryBean
)
sac
.
getBean
(
"&singletonFactoryToBeProxied"
);
FactoryBean
<?>
factory
=
(
FactoryBean
<?>
)
sac
.
getBean
(
"&singletonFactoryToBeProxied"
);
assertTrue
(
AopUtils
.
isCglibProxy
(
factory
));
TestBean
tb
=
(
TestBean
)
sac
.
getBean
(
"singletonFactoryToBeProxied"
);
...
...
@@ -169,6 +176,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals
(
3
,
tapc
.
testInterceptor
.
nrOfInvocations
);
}
@Test
public
void
testAutoProxyCreatorWithFactoryBeanAndPrototype
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
sac
.
registerSingleton
(
"testAutoProxyCreator"
,
TestAutoProxyCreator
.
class
);
...
...
@@ -182,7 +190,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator
tapc
=
(
TestAutoProxyCreator
)
sac
.
getBean
(
"testAutoProxyCreator"
);
tapc
.
testInterceptor
.
nrOfInvocations
=
0
;
FactoryBean
prototypeFactory
=
(
FactoryBean
)
sac
.
getBean
(
"&prototypeFactoryToBeProxied"
);
FactoryBean
<?>
prototypeFactory
=
(
FactoryBean
<?>
)
sac
.
getBean
(
"&prototypeFactoryToBeProxied"
);
assertTrue
(
AopUtils
.
isCglibProxy
(
prototypeFactory
));
TestBean
tb
=
(
TestBean
)
sac
.
getBean
(
"prototypeFactoryToBeProxied"
);
assertTrue
(
AopUtils
.
isCglibProxy
(
tb
));
...
...
@@ -192,6 +200,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals
(
3
,
tapc
.
testInterceptor
.
nrOfInvocations
);
}
@Test
public
void
testAutoProxyCreatorWithFactoryBeanAndProxyObjectOnly
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
...
...
@@ -206,7 +215,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator
tapc
=
(
TestAutoProxyCreator
)
sac
.
getBean
(
"testAutoProxyCreator"
);
tapc
.
testInterceptor
.
nrOfInvocations
=
0
;
FactoryBean
factory
=
(
FactoryBean
)
sac
.
getBean
(
"&singletonFactoryToBeProxied"
);
FactoryBean
<?>
factory
=
(
FactoryBean
<?>
)
sac
.
getBean
(
"&singletonFactoryToBeProxied"
);
assertFalse
(
AopUtils
.
isAopProxy
(
factory
));
TestBean
tb
=
(
TestBean
)
sac
.
getBean
(
"singletonFactoryToBeProxied"
);
...
...
@@ -222,6 +231,7 @@ public class AutoProxyCreatorTests extends TestCase {
assertEquals
(
2
,
tapc
.
testInterceptor
.
nrOfInvocations
);
}
@Test
public
void
testAutoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly
()
{
StaticApplicationContext
sac
=
new
StaticApplicationContext
();
...
...
@@ -238,7 +248,7 @@ public class AutoProxyCreatorTests extends TestCase {
TestAutoProxyCreator
tapc
=
(
TestAutoProxyCreator
)
sac
.
getBean
(
"testAutoProxyCreator"
);
tapc
.
testInterceptor
.
nrOfInvocations
=
0
;
FactoryBean
prototypeFactory
=
(
FactoryBean
)
sac
.
getBean
(
"&prototypeFactoryToBeProxied"
);
FactoryBean
<?>
prototypeFactory
=
(
FactoryBean
<?>
)
sac
.
getBean
(
"&prototypeFactoryToBeProxied"
);
assertTrue
(
AopUtils
.
isCglibProxy
(
prototypeFactory
));
TestBean
tb
=
(
TestBean
)
sac
.
getBean
(
"prototypeFactoryToBeProxied"
);
assertFalse
(
AopUtils
.
isCglibProxy
(
tb
));
...
...
@@ -249,6 +259,7 @@ public class AutoProxyCreatorTests extends TestCase {
}
@SuppressWarnings
(
"serial"
)
public
static
class
TestAutoProxyCreator
extends
AbstractAutoProxyCreator
{
private
boolean
proxyFactoryBean
=
true
;
...
...
@@ -270,7 +281,7 @@ public class AutoProxyCreatorTests extends TestCase {
this
.
proxyObject
=
proxyObject
;
}
protected
Object
[]
getAdvicesAndAdvisorsForBean
(
Class
beanClass
,
String
name
,
TargetSource
customTargetSource
)
{
protected
Object
[]
getAdvicesAndAdvisorsForBean
(
Class
<?>
beanClass
,
String
name
,
TargetSource
customTargetSource
)
{
if
(
StaticMessageSource
.
class
.
equals
(
beanClass
))
{
return
DO_NOT_PROXY
;
}
...
...
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorInitTests.java
浏览文件 @
5cb1b1d1
...
...
@@ -16,30 +16,27 @@
package
org.springframework.aop.framework.autoproxy
;
import
junit.framework.TestCase
;
import
static
org
.
junit
.
Assert
.*
;
import
org.junit.Test
;
import
org.springframework.beans.TestBean
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
/**
* @author Juergen Hoeller
* @author Dave Syer
* @author Chris Beams
*/
public
class
BeanNameAutoProxyCreatorInitTests
extends
TestCase
{
public
class
BeanNameAutoProxyCreatorInitTests
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testIgnoreAdvisorThatIsCurrentlyCreation
()
{
ClassPathXmlApplicationContext
ctx
=
new
ClassPathXmlApplicationContext
(
"beanNameAutoProxyCreatorInitTests.xml"
,
getClass
());
TestBean
bean
=
(
TestBean
)
ctx
.
getBean
(
"bean"
);
bean
.
setName
(
"foo"
);
assertEquals
(
"foo"
,
bean
.
getName
());
try
{
bean
.
setName
(
null
);
fail
(
"Expected IllegalArgumentException"
);
}
catch
(
IllegalArgumentException
ex
)
{
// expected
}
bean
.
setName
(
null
);
// should throw
}
}
org.springframework.testsuite/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorTests.java
浏览文件 @
5cb1b1d1
...
...
@@ -16,10 +16,12 @@
package
org.springframework.aop.framework.autoproxy
;
import
java.io.IOException
;
import
static
org
.
junit
.
Assert
.*
;
import
j
unit.framework.TestCase
;
import
j
ava.io.IOException
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.aop.framework.Advised
;
import
org.springframework.aop.framework.CountingBeforeAdvice
;
import
org.springframework.aop.framework.Lockable
;
...
...
@@ -35,35 +37,41 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Rod Johnson
* @author Rob Harrop
* @author Chris Beams
*/
public
class
BeanNameAutoProxyCreatorTests
extends
TestCase
{
public
class
BeanNameAutoProxyCreatorTests
{
private
BeanFactory
beanFactory
;
protected
void
setUp
()
throws
IOException
{
@Before
public
void
setUp
()
throws
IOException
{
// Note that we need an ApplicationContext, not just a BeanFactory,
// for post-processing and hence auto-proxying to work.
this
.
beanFactory
=
new
ClassPathXmlApplicationContext
(
"beanNameAutoProxyCreatorTests.xml"
,
getClass
());
}
@Test
public
void
testNoProxy
()
{
TestBean
tb
=
(
TestBean
)
beanFactory
.
getBean
(
"noproxy"
);
assertFalse
(
AopUtils
.
isAopProxy
(
tb
));
assertEquals
(
"noproxy"
,
tb
.
getName
());
}
@Test
public
void
testJdkProxyWithExactNameMatch
()
{
ITestBean
tb
=
(
ITestBean
)
beanFactory
.
getBean
(
"onlyJdk"
);
jdkAssertions
(
tb
,
1
);
assertEquals
(
"onlyJdk"
,
tb
.
getName
());
}
@Test
public
void
testJdkProxyWithDoubleProxying
()
{
ITestBean
tb
=
(
ITestBean
)
beanFactory
.
getBean
(
"doubleJdk"
);
jdkAssertions
(
tb
,
2
);
assertEquals
(
"doubleJdk"
,
tb
.
getName
());
}
@Test
public
void
testJdkIntroduction
()
{
ITestBean
tb
=
(
ITestBean
)
beanFactory
.
getBean
(
"introductionUsingJdk"
);
NopInterceptor
nop
=
(
NopInterceptor
)
beanFactory
.
getBean
(
"introductionNopInterceptor"
);
...
...
@@ -102,6 +110,7 @@ public class BeanNameAutoProxyCreatorTests extends TestCase {
}
}
@Test
public
void
testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean
()
{
ITestBean
tb
=
(
ITestBean
)
beanFactory
.
getBean
(
"factory-introductionUsingJdk"
);
NopInterceptor
nop
=
(
NopInterceptor
)
beanFactory
.
getBean
(
"introductionNopInterceptor"
);
...
...
@@ -139,18 +148,21 @@ public class BeanNameAutoProxyCreatorTests extends TestCase {
}
}
@Test
public
void
testJdkProxyWithWildcardMatch
()
{
ITestBean
tb
=
(
ITestBean
)
beanFactory
.
getBean
(
"jdk1"
);
jdkAssertions
(
tb
,
1
);
assertEquals
(
"jdk1"
,
tb
.
getName
());
}
@Test
public
void
testCglibProxyWithWildcardMatch
()
{
TestBean
tb
=
(
TestBean
)
beanFactory
.
getBean
(
"cglib1"
);
cglibAssertions
(
tb
);
assertEquals
(
"cglib1"
,
tb
.
getName
());
}
@Test
public
void
testWithFrozenProxy
()
{
ITestBean
testBean
=
(
ITestBean
)
beanFactory
.
getBean
(
"frozenBean"
);
assertTrue
(((
Advised
)
testBean
).
isFrozen
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录