Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
d66f85bd
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
d66f85bd
编写于
9月 22, 2015
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
0ad59ddb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
40 deletion
+48
-40
spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java
...amework/cache/annotation/SpringCacheAnnotationParser.java
+3
-3
spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java
...cache/annotation/AnnotationCacheOperationSourceTests.java
+45
-37
未找到文件。
spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java
浏览文件 @
d66f85bd
...
...
@@ -194,11 +194,11 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
return
new
DefaultCacheConfig
();
}
private
<
T
extends
Annotation
>
Collection
<
T
>
getAnnotations
(
AnnotatedElement
ae
,
Class
<
T
>
annotationType
)
{
Collection
<
T
>
anns
=
new
ArrayList
<
T
>(
2
);
private
<
A
extends
Annotation
>
Collection
<
A
>
getAnnotations
(
AnnotatedElement
ae
,
Class
<
A
>
annotationType
)
{
Collection
<
A
>
anns
=
new
ArrayList
<
A
>(
2
);
// look at raw annotation
T
ann
=
ae
.
getAnnotation
(
annotationType
);
A
ann
=
ae
.
getAnnotation
(
annotationType
);
if
(
ann
!=
null
)
{
anns
.
add
(
AnnotationUtils
.
synthesizeAnnotation
(
ann
,
ae
));
}
...
...
spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java
浏览文件 @
d66f85bd
...
...
@@ -21,6 +21,7 @@ import java.lang.annotation.Retention;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Iterator
;
...
...
@@ -31,6 +32,7 @@ import org.junit.rules.ExpectedException;
import
org.springframework.cache.interceptor.CacheEvictOperation
;
import
org.springframework.cache.interceptor.CacheOperation
;
import
org.springframework.cache.interceptor.CacheableOperation
;
import
org.springframework.core.annotation.AliasFor
;
import
org.springframework.util.ReflectionUtils
;
import
static
org
.
junit
.
Assert
.*;
...
...
@@ -42,15 +44,14 @@ import static org.junit.Assert.*;
public
class
AnnotationCacheOperationSourceTests
{
@Rule
public
final
ExpectedException
throw
n
=
ExpectedException
.
none
();
public
final
ExpectedException
exceptio
n
=
ExpectedException
.
none
();
private
AnnotationCacheOperationSource
source
=
new
AnnotationCacheOperationSource
();
private
Collection
<
CacheOperation
>
getOps
(
Class
<?>
target
,
String
name
,
int
expectedNumberOfOperations
)
{
private
Collection
<
CacheOperation
>
getOps
(
Class
<?>
target
,
String
name
,
int
expectedNumberOfOperations
)
{
Collection
<
CacheOperation
>
result
=
getOps
(
target
,
name
);
assertEquals
(
"Wrong number of operation(s) for '"
+
name
+
"'"
,
expectedNumberOfOperations
,
result
.
size
());
assertEquals
(
"Wrong number of operation(s) for '"
+
name
+
"'"
,
expectedNumberOfOperations
,
result
.
size
());
return
result
;
}
...
...
@@ -60,13 +61,13 @@ public class AnnotationCacheOperationSourceTests {
}
@Test
public
void
testS
ingularAnnotation
()
throws
Exception
{
public
void
s
ingularAnnotation
()
throws
Exception
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"singular"
,
1
);
assertTrue
(
ops
.
iterator
().
next
()
instanceof
CacheableOperation
);
}
@Test
public
void
testM
ultipleAnnotation
()
throws
Exception
{
public
void
m
ultipleAnnotation
()
throws
Exception
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"multiple"
,
2
);
Iterator
<
CacheOperation
>
it
=
ops
.
iterator
();
assertTrue
(
it
.
next
()
instanceof
CacheableOperation
);
...
...
@@ -74,7 +75,7 @@ public class AnnotationCacheOperationSourceTests {
}
@Test
public
void
testC
aching
()
throws
Exception
{
public
void
c
aching
()
throws
Exception
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"caching"
,
2
);
Iterator
<
CacheOperation
>
it
=
ops
.
iterator
();
assertTrue
(
it
.
next
()
instanceof
CacheableOperation
);
...
...
@@ -82,13 +83,13 @@ public class AnnotationCacheOperationSourceTests {
}
@Test
public
void
testS
ingularStereotype
()
throws
Exception
{
public
void
s
ingularStereotype
()
throws
Exception
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"singleStereotype"
,
1
);
assertTrue
(
ops
.
iterator
().
next
()
instanceof
CacheEvictOperation
);
}
@Test
public
void
testM
ultipleStereotypes
()
throws
Exception
{
public
void
m
ultipleStereotypes
()
throws
Exception
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"multipleStereotype"
,
3
);
Iterator
<
CacheOperation
>
it
=
ops
.
iterator
();
assertTrue
(
it
.
next
()
instanceof
CacheableOperation
);
...
...
@@ -101,65 +102,57 @@ public class AnnotationCacheOperationSourceTests {
}
@Test
public
void
testC
ustomKeyGenerator
()
{
public
void
c
ustomKeyGenerator
()
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"customKeyGenerator"
,
1
);
CacheOperation
cacheOperation
=
ops
.
iterator
().
next
();
assertEquals
(
"Custom key generator not set"
,
"custom"
,
cacheOperation
.
getKeyGenerator
());
}
@Test
public
void
testC
ustomKeyGeneratorInherited
()
{
public
void
c
ustomKeyGeneratorInherited
()
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"customKeyGeneratorInherited"
,
1
);
CacheOperation
cacheOperation
=
ops
.
iterator
().
next
();
assertEquals
(
"Custom key generator not set"
,
"custom"
,
cacheOperation
.
getKeyGenerator
());
}
@Test
public
void
testKeyAndKeyGeneratorCannotBeSetTogether
()
{
try
{
getOps
(
AnnotatedClass
.
class
,
"invalidKeyAndKeyGeneratorSet"
);
fail
(
"Should have failed to parse @Cacheable annotation"
);
}
catch
(
IllegalStateException
e
)
{
// expected
}
public
void
keyAndKeyGeneratorCannotBeSetTogether
()
{
exception
.
expect
(
IllegalStateException
.
class
);
getOps
(
AnnotatedClass
.
class
,
"invalidKeyAndKeyGeneratorSet"
);
}
@Test
public
void
testC
ustomCacheManager
()
{
public
void
c
ustomCacheManager
()
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"customCacheManager"
,
1
);
CacheOperation
cacheOperation
=
ops
.
iterator
().
next
();
assertEquals
(
"Custom cache manager not set"
,
"custom"
,
cacheOperation
.
getCacheManager
());
}
@Test
public
void
testC
ustomCacheManagerInherited
()
{
public
void
c
ustomCacheManagerInherited
()
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"customCacheManagerInherited"
,
1
);
CacheOperation
cacheOperation
=
ops
.
iterator
().
next
();
assertEquals
(
"Custom cache manager not set"
,
"custom"
,
cacheOperation
.
getCacheManager
());
}
@Test
public
void
testC
ustomCacheResolver
()
{
public
void
c
ustomCacheResolver
()
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"customCacheResolver"
,
1
);
CacheOperation
cacheOperation
=
ops
.
iterator
().
next
();
assertEquals
(
"Custom cache resolver not set"
,
"custom"
,
cacheOperation
.
getCacheResolver
());
}
@Test
public
void
testC
ustomCacheResolverInherited
()
{
public
void
c
ustomCacheResolverInherited
()
{
Collection
<
CacheOperation
>
ops
=
getOps
(
AnnotatedClass
.
class
,
"customCacheResolverInherited"
,
1
);
CacheOperation
cacheOperation
=
ops
.
iterator
().
next
();
assertEquals
(
"Custom cache resolver not set"
,
"custom"
,
cacheOperation
.
getCacheResolver
());
}
@Test
public
void
testCacheResolverAndCacheManagerCannotBeSetTogether
()
{
try
{
getOps
(
AnnotatedClass
.
class
,
"invalidCacheResolverAndCacheManagerSet"
);
fail
(
"Should have failed to parse @Cacheable annotation"
);
}
catch
(
IllegalStateException
e
)
{
// expected
}
public
void
cacheResolverAndCacheManagerCannotBeSetTogether
()
{
exception
.
expect
(
IllegalStateException
.
class
);
getOps
(
AnnotatedClass
.
class
,
"invalidCacheResolverAndCacheManagerSet"
);
}
@Test
...
...
@@ -239,14 +232,14 @@ public class AnnotationCacheOperationSourceTests {
assertEquals
(
"Wrong key manager"
,
keyGenerator
,
actual
.
getKeyGenerator
());
assertEquals
(
"Wrong cache manager"
,
cacheManager
,
actual
.
getCacheManager
());
assertEquals
(
"Wrong cache resolver"
,
cacheResolver
,
actual
.
getCacheResolver
());
for
(
String
cacheName
:
cacheNames
)
{
assertTrue
(
"Cache '"
+
cacheName
+
"' not found (got "
+
actual
.
getCacheNames
(),
actual
.
getCacheNames
().
contains
(
cacheName
));
}
assertEquals
(
"Wrong number of cache name(s)"
,
cacheNames
.
length
,
actual
.
getCacheNames
().
size
());
assertEquals
(
"Wrong number of cache names"
,
cacheNames
.
length
,
actual
.
getCacheNames
().
size
());
Arrays
.
stream
(
cacheNames
).
forEach
(
cacheName
->
assertTrue
(
"Cache '"
+
cacheName
+
"' not found in "
+
actual
.
getCacheNames
(),
actual
.
getCacheNames
().
contains
(
cacheName
)));
}
private
static
class
AnnotatedClass
{
@Cacheable
(
"test"
)
public
void
singular
()
{
}
...
...
@@ -256,7 +249,7 @@ public class AnnotationCacheOperationSourceTests {
public
void
multiple
()
{
}
@Caching
(
cacheable
=
{
@Cacheable
(
"test"
)},
evict
=
{
@CacheEvict
(
"test"
)}
)
@Caching
(
cacheable
=
@Cacheable
(
"test"
),
evict
=
@CacheEvict
(
"test"
)
)
public
void
caching
()
{
}
...
...
@@ -357,7 +350,6 @@ public class AnnotationCacheOperationSourceTests {
@Cacheable
public
void
noCustomization
()
{
}
}
@CacheConfigFoo
...
...
@@ -411,4 +403,20 @@ public class AnnotationCacheOperationSourceTests {
cacheManager
=
"classCacheManager"
,
cacheResolver
=
"classCacheResolver"
)
public
@interface
CacheConfigFoo
{
}
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
({
ElementType
.
METHOD
,
ElementType
.
TYPE
})
@Cacheable
public
@interface
ComposedCacheable
{
@AliasFor
(
annotation
=
Cacheable
.
class
,
attribute
=
"cacheNames"
)
String
[]
value
()
default
{};
@AliasFor
(
annotation
=
Cacheable
.
class
,
attribute
=
"cacheNames"
)
String
[]
cacheNames
()
default
{};
@AliasFor
(
annotation
=
Cacheable
.
class
,
attribute
=
"key"
)
String
key
()
default
""
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录