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
c212f107
Commit
c212f107
authored
Nov 24, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
e687d3ae
ca788a90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
TestDatabaseAutoConfiguration.java
.../autoconfigure/orm/jpa/TestDatabaseAutoConfiguration.java
+2
-1
TestDatabaseAutoConfigurationTests.java
...configure/orm/jpa/TestDatabaseAutoConfigurationTests.java
+41
-1
No files found.
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestDatabaseAutoConfiguration.java
View file @
c212f107
...
...
@@ -196,7 +196,8 @@ public class TestDatabaseAutoConfiguration {
"Cannot determine embedded database for tests. If you want "
+
"an embedded database please put a supported one "
+
"on the classpath."
);
return
new
EmbeddedDatabaseBuilder
().
setType
(
connection
.
getType
()).
build
();
return
new
EmbeddedDatabaseBuilder
().
generateUniqueName
(
true
)
.
setType
(
connection
.
getType
()).
build
();
}
}
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestDatabaseAutoConfigurationTests.java
View file @
c212f107
...
...
@@ -24,6 +24,11 @@ import org.junit.Test;
import
org.springframework.boot.test.util.EnvironmentTestUtils
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
...
@@ -49,7 +54,30 @@ public class TestDatabaseAutoConfigurationTests {
assertThat
(
this
.
context
.
getBeansOfType
(
DataSource
.
class
)).
isEmpty
();
}
@Test
public
void
replaceWithUniqueDatabase
()
{
load
(
ExistingDataSourceConfiguration
.
class
);
DataSource
datasource
=
this
.
context
.
getBean
(
DataSource
.
class
);
JdbcTemplate
jdbcTemplate
=
new
JdbcTemplate
(
datasource
);
jdbcTemplate
.
execute
(
"create table example (id int, name varchar);"
);
ConfigurableApplicationContext
anotherContext
=
doLoad
(
ExistingDataSourceConfiguration
.
class
);
try
{
DataSource
anotherDatasource
=
anotherContext
.
getBean
(
DataSource
.
class
);
JdbcTemplate
anotherJdbcTemplate
=
new
JdbcTemplate
(
anotherDatasource
);
anotherJdbcTemplate
.
execute
(
"create table example (id int, name varchar);"
);
}
finally
{
anotherContext
.
close
();
}
}
public
void
load
(
Class
<?>
config
,
String
...
environment
)
{
this
.
context
=
doLoad
(
config
,
environment
);
}
public
ConfigurableApplicationContext
doLoad
(
Class
<?>
config
,
String
...
environment
)
{
AnnotationConfigApplicationContext
ctx
=
new
AnnotationConfigApplicationContext
();
if
(
config
!=
null
)
{
ctx
.
register
(
config
);
...
...
@@ -57,7 +85,19 @@ public class TestDatabaseAutoConfigurationTests {
ctx
.
register
(
TestDatabaseAutoConfiguration
.
class
);
EnvironmentTestUtils
.
addEnvironment
(
ctx
,
environment
);
ctx
.
refresh
();
this
.
context
=
ctx
;
return
ctx
;
}
@Configuration
static
class
ExistingDataSourceConfiguration
{
@Bean
public
DataSource
dataSource
()
{
EmbeddedDatabaseBuilder
builder
=
new
EmbeddedDatabaseBuilder
()
.
setType
(
EmbeddedDatabaseType
.
HSQL
);
return
builder
.
build
();
}
}
}
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