Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
aa9ed39c
Unverified
Commit
aa9ed39c
authored
Apr 07, 2018
by
Jason Song
Committed by
GitHub
Apr 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1039 from nobodyiam/config-injection-inheritance
add config injection with inheritance test
parents
86a5a651
360abba2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
1 deletion
+115
-1
JavaConfigAnnotationTest.java
...rip/framework/apollo/spring/JavaConfigAnnotationTest.java
+115
-1
No files found.
apollo-client/src/test/java/com/ctrip/framework/apollo/spring/JavaConfigAnnotationTest.java
View file @
aa9ed39c
...
...
@@ -55,6 +55,22 @@ public class JavaConfigAnnotationTest extends AbstractSpringIntegrationTest {
}
@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
);
Config
fxApolloConfig
=
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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment