Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
aa9ed39c
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
aa9ed39c
编写于
4月 07, 2018
作者:
J
Jason Song
提交者:
GitHub
4月 07, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1039 from nobodyiam/config-injection-inheritance
add config injection with inheritance test
上级
86a5a651
360abba2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
115 addition
and
1 deletion
+115
-1
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
...rip/framework/apollo/spring/JavaConfigAnnotationTest.java
+115
-1
未找到文件。
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
浏览文件 @
aa9ed39c
...
...
@@ -54,6 +54,22 @@ public class JavaConfigAnnotationTest extends AbstractSpringIntegrationTest {
getBean
(
TestApolloConfigBean2
.
class
,
AppConfig2
.
class
);
}
@Test
public
void
testApolloConfigWithInheritance
()
throws
Exception
{
Config
applicationConfig
=
mock
(
Config
.
class
);
Config
fxApolloConfig
=
mock
(
Config
.
class
);
mockConfig
(
ConfigConsts
.
NAMESPACE_APPLICATION
,
applicationConfig
);
mockConfig
(
FX_APOLLO_NAMESPACE
,
fxApolloConfig
);
TestApolloChildConfigBean
bean
=
getBean
(
TestApolloChildConfigBean
.
class
,
AppConfig6
.
class
);
assertEquals
(
applicationConfig
,
bean
.
getConfig
());
assertEquals
(
applicationConfig
,
bean
.
getAnotherConfig
());
assertEquals
(
fxApolloConfig
,
bean
.
getYetAnotherConfig
());
assertEquals
(
applicationConfig
,
bean
.
getSomeConfig
());
}
@Test
public
void
testApolloConfigChangeListener
()
throws
Exception
{
Config
applicationConfig
=
mock
(
Config
.
class
);
...
...
@@ -127,6 +143,63 @@ public class JavaConfigAnnotationTest extends AbstractSpringIntegrationTest {
getBean
(
TestApolloConfigChangeListenerBean3
.
class
,
AppConfig5
.
class
);
}
@Test
public
void
testApolloConfigChangeListenerWithInheritance
()
throws
Exception
{
Config
applicationConfig
=
mock
(
Config
.
class
);
Config
fxApolloConfig
=
mock
(
Config
.
class
);
mockConfig
(
ConfigConsts
.
NAMESPACE_APPLICATION
,
applicationConfig
);
mockConfig
(
FX_APOLLO_NAMESPACE
,
fxApolloConfig
);
final
List
<
ConfigChangeListener
>
applicationListeners
=
Lists
.
newArrayList
();
final
List
<
ConfigChangeListener
>
fxApolloListeners
=
Lists
.
newArrayList
();
doAnswer
(
new
Answer
()
{
@Override
public
Object
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
applicationListeners
.
add
(
invocation
.
getArgumentAt
(
0
,
ConfigChangeListener
.
class
));
return
Void
.
class
;
}
}).
when
(
applicationConfig
).
addChangeListener
(
any
(
ConfigChangeListener
.
class
));
doAnswer
(
new
Answer
()
{
@Override
public
Object
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
fxApolloListeners
.
add
(
invocation
.
getArgumentAt
(
0
,
ConfigChangeListener
.
class
));
return
Void
.
class
;
}
}).
when
(
fxApolloConfig
).
addChangeListener
(
any
(
ConfigChangeListener
.
class
));
ConfigChangeEvent
someEvent
=
mock
(
ConfigChangeEvent
.
class
);
ConfigChangeEvent
anotherEvent
=
mock
(
ConfigChangeEvent
.
class
);
TestApolloChildConfigChangeListener
bean
=
getBean
(
TestApolloChildConfigChangeListener
.
class
,
AppConfig7
.
class
);
//PropertySourcesProcessor add listeners to listen config changed of all namespace
assertEquals
(
5
,
applicationListeners
.
size
());
assertEquals
(
1
,
fxApolloListeners
.
size
());
for
(
ConfigChangeListener
listener
:
applicationListeners
)
{
listener
.
onChange
(
someEvent
);
}
assertEquals
(
someEvent
,
bean
.
getChangeEvent1
());
assertEquals
(
someEvent
,
bean
.
getChangeEvent2
());
assertEquals
(
someEvent
,
bean
.
getChangeEvent3
());
assertEquals
(
someEvent
,
bean
.
getSomeChangeEvent
());
for
(
ConfigChangeListener
listener
:
fxApolloListeners
)
{
listener
.
onChange
(
anotherEvent
);
}
assertEquals
(
someEvent
,
bean
.
getChangeEvent1
());
assertEquals
(
someEvent
,
bean
.
getChangeEvent2
());
assertEquals
(
anotherEvent
,
bean
.
getChangeEvent3
());
assertEquals
(
someEvent
,
bean
.
getSomeChangeEvent
());
}
private
<
T
>
T
getBean
(
Class
<
T
>
beanClass
,
Class
<?>...
annotatedClasses
)
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
annotatedClasses
);
...
...
@@ -178,6 +251,24 @@ public class JavaConfigAnnotationTest extends AbstractSpringIntegrationTest {
}
}
@Configuration
@EnableApolloConfig
static
class
AppConfig6
{
@Bean
public
TestApolloChildConfigBean
bean
()
{
return
new
TestApolloChildConfigBean
();
}
}
@Configuration
@EnableApolloConfig
static
class
AppConfig7
{
@Bean
public
TestApolloChildConfigChangeListener
bean
()
{
return
new
TestApolloChildConfigChangeListener
();
}
}
static
class
TestApolloConfigBean1
{
@ApolloConfig
private
Config
config
;
...
...
@@ -199,11 +290,21 @@ public class JavaConfigAnnotationTest extends AbstractSpringIntegrationTest {
}
}
public
static
class
TestApolloConfigBean2
{
static
class
TestApolloConfigBean2
{
@ApolloConfig
private
String
config
;
}
static
class
TestApolloChildConfigBean
extends
TestApolloConfigBean1
{
@ApolloConfig
private
Config
someConfig
;
public
Config
getSomeConfig
()
{
return
someConfig
;
}
}
static
class
TestApolloConfigChangeListenerBean1
{
private
ConfigChangeEvent
changeEvent1
;
private
ConfigChangeEvent
changeEvent2
;
...
...
@@ -251,4 +352,17 @@ public class JavaConfigAnnotationTest extends AbstractSpringIntegrationTest {
}
}
static
class
TestApolloChildConfigChangeListener
extends
TestApolloConfigChangeListenerBean1
{
private
ConfigChangeEvent
someChangeEvent
;
@ApolloConfigChangeListener
private
void
someOnChange
(
ConfigChangeEvent
changeEvent
)
{
this
.
someChangeEvent
=
changeEvent
;
}
public
ConfigChangeEvent
getSomeChangeEvent
()
{
return
someChangeEvent
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录