Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
c79ecc29
Commit
c79ecc29
authored
Apr 11, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
7956e682
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
7 deletions
+66
-7
ConditionalOnBeanTests.java
.../boot/autoconfigure/condition/ConditionalOnBeanTests.java
+14
-7
ConditionalOnMissingBeanTests.java
...utoconfigure/condition/ConditionalOnMissingBeanTests.java
+52
-0
No files found.
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnBeanTests.java
View file @
c79ecc29
...
...
@@ -57,12 +57,7 @@ public class ConditionalOnBeanTests {
this
.
context
.
register
(
FooConfiguration
.
class
,
OnBeanNameAndTypeConfiguration
.
class
);
this
.
context
.
refresh
();
/*
* Arguably this should be true, but as things are implemented the conditions
* specified in the different attributes of @ConditionalOnBean are combined with
* logical OR (not AND) so if any of them match the condition is true.
*/
assertThat
(
this
.
context
.
containsBean
(
"bar"
)).
isFalse
();
assertThat
(
this
.
context
.
containsBean
(
"bar"
)).
isTrue
();
}
@Test
...
...
@@ -132,28 +127,34 @@ public class ConditionalOnBeanTests {
@Configuration
@ConditionalOnBean
(
name
=
"foo"
)
protected
static
class
OnBeanNameConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
@ConditionalOn
Missing
Bean
(
name
=
"foo"
,
value
=
Date
.
class
)
@ConditionalOnBean
(
name
=
"foo"
,
value
=
Date
.
class
)
protected
static
class
OnBeanNameAndTypeConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
@ConditionalOnBean
(
annotation
=
EnableScheduling
.
class
)
protected
static
class
OnAnnotationConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
...
...
@@ -177,30 +178,36 @@ public class ConditionalOnBeanTests {
@Configuration
@ConditionalOnBean
(
type
=
"some.type.Missing"
)
protected
static
class
OnBeanMissingClassConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
@EnableScheduling
protected
static
class
FooConfiguration
{
@Bean
public
String
foo
()
{
return
"foo"
;
}
}
@Configuration
@ImportResource
(
"org/springframework/boot/autoconfigure/condition/foo.xml"
)
protected
static
class
XmlConfiguration
{
}
@Configuration
@ImportResource
(
"org/springframework/boot/autoconfigure/condition/foo.xml"
)
@Import
(
OnBeanNameConfiguration
.
class
)
protected
static
class
CombinedXmlConfiguration
{
}
@Configuration
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnMissingBeanTests.java
View file @
c79ecc29
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
condition
;
import
java.util.Date
;
import
org.junit.Test
;
import
org.springframework.beans.factory.FactoryBean
;
...
...
@@ -66,6 +68,19 @@ public class ConditionalOnMissingBeanTests {
assertThat
(
this
.
context
.
getBean
(
"foo"
)).
isEqualTo
(
"foo"
);
}
@Test
public
void
testNameAndTypeOnMissingBeanCondition
()
{
this
.
context
.
register
(
FooConfiguration
.
class
,
OnBeanNameAndTypeConfiguration
.
class
);
this
.
context
.
refresh
();
/*
* Arguably this should be true, but as things are implemented the conditions
* specified in the different attributes of @ConditionalOnBean are combined with
* logical OR (not AND) so if any of them match the condition is true.
*/
assertThat
(
this
.
context
.
containsBean
(
"bar"
)).
isFalse
();
}
@Test
public
void
hierarchyConsidered
()
throws
Exception
{
this
.
context
.
register
(
FooConfiguration
.
class
);
...
...
@@ -219,49 +234,72 @@ public class ConditionalOnMissingBeanTests {
@Configuration
@ConditionalOnMissingBean
(
name
=
"foo"
)
protected
static
class
OnBeanNameConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
@ConditionalOnMissingBean
(
name
=
"foo"
,
value
=
Date
.
class
)
@ConditionalOnBean
(
name
=
"foo"
,
value
=
Date
.
class
)
protected
static
class
OnBeanNameAndTypeConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
protected
static
class
FactoryBeanConfiguration
{
@Bean
public
FactoryBean
<
ExampleBean
>
exampleBeanFactoryBean
()
{
return
new
ExampleFactoryBean
(
"foo"
);
}
}
@Configuration
protected
static
class
FactoryBeanWithBeanMethodArgumentsConfiguration
{
@Bean
public
FactoryBean
<
ExampleBean
>
exampleBeanFactoryBean
(
@Value
(
"${theValue}"
)
String
value
)
{
return
new
ExampleFactoryBean
(
value
);
}
}
@Configuration
protected
static
class
ConcreteFactoryBeanConfiguration
{
@Bean
public
ExampleFactoryBean
exampleBeanFactoryBean
()
{
return
new
ExampleFactoryBean
(
"foo"
);
}
}
@Configuration
protected
static
class
UnhelpfulFactoryBeanConfiguration
{
@Bean
@SuppressWarnings
(
"rawtypes"
)
public
FactoryBean
exampleBeanFactoryBean
()
{
return
new
ExampleFactoryBean
(
"foo"
);
}
}
@Configuration
@Import
(
NonspecificFactoryBeanClassAttributeRegistrar
.
class
)
protected
static
class
NonspecificFactoryBeanClassAttributeConfiguration
{
}
protected
static
class
NonspecificFactoryBeanClassAttributeRegistrar
...
...
@@ -284,6 +322,7 @@ public class ConditionalOnMissingBeanTests {
@Configuration
@Import
(
NonspecificFactoryBeanClassAttributeRegistrar
.
class
)
protected
static
class
NonspecificFactoryBeanStringAttributeConfiguration
{
}
protected
static
class
NonspecificFactoryBeanStringAttributeRegistrar
...
...
@@ -326,15 +365,18 @@ public class ConditionalOnMissingBeanTests {
@Configuration
@ImportResource
(
"org/springframework/boot/autoconfigure/condition/factorybean.xml"
)
protected
static
class
FactoryBeanXmlConfiguration
{
}
@Configuration
protected
static
class
ConditionalOnFactoryBean
{
@Bean
@ConditionalOnMissingBean
(
ExampleBean
.
class
)
public
ExampleBean
createExampleBean
()
{
return
new
ExampleBean
(
"direct"
);
}
}
@Configuration
...
...
@@ -372,45 +414,55 @@ public class ConditionalOnMissingBeanTests {
@Configuration
@ConditionalOnMissingBean
(
annotation
=
EnableScheduling
.
class
)
protected
static
class
OnAnnotationConfiguration
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
@EnableScheduling
protected
static
class
FooConfiguration
{
@Bean
public
String
foo
()
{
return
"foo"
;
}
}
@Configuration
@ConditionalOnMissingBean
(
name
=
"foo"
)
protected
static
class
HierarchyConsidered
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
@ConditionalOnMissingBean
(
name
=
"foo"
,
search
=
SearchStrategy
.
CURRENT
)
protected
static
class
HierarchyNotConsidered
{
@Bean
public
String
bar
()
{
return
"bar"
;
}
}
@Configuration
protected
static
class
ExampleBeanConfiguration
{
@Bean
public
ExampleBean
exampleBean
()
{
return
new
ExampleBean
(
"test"
);
}
}
@Configuration
...
...
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