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
21b815aa
Commit
21b815aa
authored
Dec 16, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-7560
parent
5a7624df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
50 deletions
+20
-50
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+7
-0
TestDatabaseAutoConfiguration.java
...est/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java
+3
-50
additional-spring-configuration-metadata.json
...es/META-INF/additional-spring-configuration-metadata.json
+10
-0
No files found.
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
21b815aa
...
...
@@ -1155,4 +1155,11 @@ content into your application; rather pick only the properties that you need.
spring.devtools.remote.secret= # A shared secret required to establish a connection (required to enable remote support).
spring.devtools.remote.secret-header-name=X-AUTH-TOKEN # HTTP header used to transfer the shared secret.
# ----------------------------------------
# TESTING PROPERTIES
# ----------------------------------------
spring.test.database.replace=any # Type of existing DataSource to replace.
----
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java
View file @
21b815aa
...
...
@@ -31,22 +31,16 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
import
org.springframework.boot.autoconfigure.AutoConfigureBefore
;
import
org.springframework.boot.autoconfigure.condition.ConditionMessage
;
import
org.springframework.boot.autoconfigure.condition.ConditionOutcome
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.
SpringBootCondition
;
import
org.springframework.boot.autoconfigure.condition.
ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.boot.bind.RelaxedPropertyResolver
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ConditionContext
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.type.AnnotatedTypeMetadata
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
;
import
org.springframework.util.Assert
;
...
...
@@ -56,7 +50,6 @@ import org.springframework.util.ObjectUtils;
* Auto-configuration for a test database.
*
* @author Phillip Webb
* @author Eddú Meléndez
* @since 1.4.0
* @see AutoConfigureTestDatabase
*/
...
...
@@ -64,9 +57,6 @@ import org.springframework.util.ObjectUtils;
@AutoConfigureBefore
(
DataSourceAutoConfiguration
.
class
)
public
class
TestDatabaseAutoConfiguration
{
private
static
final
String
SPRING_TEST_DATABASE_PREFIX
=
"spring.test.database."
;
private
static
final
String
REPLACE_PROPERTY
=
"replace"
;
private
final
Environment
environment
;
TestDatabaseAutoConfiguration
(
Environment
environment
)
{
...
...
@@ -74,55 +64,18 @@ public class TestDatabaseAutoConfiguration {
}
@Bean
@Conditional
(
TestDatabaseReplaceAutoConfiguredCondition
.
class
)
@Conditional
OnProperty
(
prefix
=
"spring.test.database"
,
name
=
"replace"
,
havingValue
=
"AUTO_CONFIGURED"
)
@ConditionalOnMissingBean
public
DataSource
dataSource
()
{
return
new
EmbeddedDataSourceFactory
(
this
.
environment
).
getEmbeddedDatabase
();
}
@Bean
@Conditional
(
TestDatabaseReplaceAnyCondition
.
class
)
@Conditional
OnProperty
(
prefix
=
"spring.test.database"
,
name
=
"replace"
,
havingValue
=
"ANY"
,
matchIfMissing
=
true
)
public
static
EmbeddedDataSourceBeanFactoryPostProcessor
embeddedDataSourceBeanFactoryPostProcessor
()
{
return
new
EmbeddedDataSourceBeanFactoryPostProcessor
();
}
static
class
TestDatabaseReplaceAutoConfiguredCondition
extends
SpringBootCondition
{
@Override
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
context
.
getEnvironment
(),
SPRING_TEST_DATABASE_PREFIX
);
ConditionMessage
.
Builder
message
=
ConditionMessage
.
forCondition
(
"Test Database Replace Property"
);
if
(
resolver
.
containsProperty
(
REPLACE_PROPERTY
)
&&
"NONE"
.
equals
(
resolver
.
getProperty
(
REPLACE_PROPERTY
)))
{
return
ConditionOutcome
.
noMatch
(
message
.
didNotFind
(
"NONE"
).
atAll
());
}
else
if
(
resolver
.
containsProperty
(
REPLACE_PROPERTY
)
&&
"AUTO_CONFIGURED"
.
equals
(
resolver
.
getProperty
(
REPLACE_PROPERTY
)))
{
return
ConditionOutcome
.
match
(
message
.
found
(
"AUTO_CONFIGURED"
).
atAll
());
}
return
ConditionOutcome
.
noMatch
(
message
.
didNotFind
(
"spring.test.database.replace"
).
atAll
());
}
}
static
class
TestDatabaseReplaceAnyCondition
extends
SpringBootCondition
{
@Override
public
ConditionOutcome
getMatchOutcome
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
context
.
getEnvironment
(),
SPRING_TEST_DATABASE_PREFIX
);
ConditionMessage
.
Builder
message
=
ConditionMessage
.
forCondition
(
"Test Database Replace Property"
);
if
(
resolver
.
containsProperty
(
REPLACE_PROPERTY
)
&&
"NONE"
.
equals
(
resolver
.
getProperty
(
REPLACE_PROPERTY
)))
{
return
ConditionOutcome
.
noMatch
(
message
.
didNotFind
(
"NONE"
).
atAll
());
}
else
if
(!
resolver
.
containsProperty
(
REPLACE_PROPERTY
)
||
"ANY"
.
equals
(
resolver
.
getProperty
(
REPLACE_PROPERTY
)))
{
return
ConditionOutcome
.
match
(
message
.
found
(
"ANY"
).
atAll
());
}
return
ConditionOutcome
.
noMatch
(
message
.
didNotFind
(
"spring.test.database.replace"
).
atAll
());
}
}
@Order
(
Ordered
.
LOWEST_PRECEDENCE
)
private
static
class
EmbeddedDataSourceBeanFactoryPostProcessor
implements
BeanDefinitionRegistryPostProcessor
{
...
...
spring-boot-test-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
0 → 100644
View file @
21b815aa
{
"properties"
:
[
{
"name"
:
"spring.test.database.replace"
,
"type"
:
"org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase$Replace"
,
"description"
:
"Type of existing DataSource to replace."
,
"defaultValue"
:
"any"
}
]
}
\ No newline at end of file
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