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
c4026806
Commit
c4026806
authored
Oct 19, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
ccca943e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
35 deletions
+28
-35
CustomHibernateJpaAutoConfigurationTests.java
...ure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java
+28
-35
No files found.
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/CustomHibernateJpaAutoConfigurationTests.java
View file @
c4026806
...
...
@@ -23,16 +23,13 @@ import java.util.Map;
import
javax.sql.DataSource
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.TestAutoConfigurationPackage
;
import
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration
;
import
org.springframework.boot.autoconfigure.orm.jpa.test.City
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.boot.test.context.runner.ApplicationContextRunner
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.orm.jpa.vendor.Database
;
...
...
@@ -44,49 +41,45 @@ import static org.mockito.BDDMockito.given;
import
static
org
.
mockito
.
Mockito
.
mock
;
/**
*
T
ests for {@link HibernateJpaAutoConfiguration}.
*
Additional t
ests for {@link HibernateJpaAutoConfiguration}.
*
* @author Dave Syer
* @author Phillip Webb
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
public
class
CustomHibernateJpaAutoConfigurationTests
{
protected
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
private
final
ApplicationContextRunner
contextRunner
=
new
ApplicationContextRunner
()
.
withUserConfiguration
(
TestConfiguration
.
class
)
.
withConfiguration
(
AutoConfigurations
.
of
(
DataSourceAutoConfiguration
.
class
,
HibernateJpaAutoConfiguration
.
class
));
@After
public
void
close
()
{
this
.
context
.
close
();
}
@Test
public
void
testNamingStrategyDelegatorTakesPrecedence
()
{
TestPropertyValues
.
of
(
"spring.jpa.properties.hibernate.ejb.naming_strategy_delegator:"
+
"org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator"
);
this
.
context
.
register
(
TestConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
HibernateJpaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
JpaProperties
bean
=
this
.
context
.
getBean
(
JpaProperties
.
class
);
Map
<
String
,
String
>
hibernateProperties
=
bean
.
getHibernateProperties
(
"create-drop"
);
assertThat
(
hibernateProperties
.
get
(
"hibernate.ejb.naming_strategy"
)).
isNull
();
public
void
namingStrategyDelegatorTakesPrecedence
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.jpa.properties.hibernate.ejb.naming_strategy_delegator:"
+
"org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator"
).
run
((
context
)
->
{
JpaProperties
bean
=
context
.
getBean
(
JpaProperties
.
class
);
Map
<
String
,
String
>
hibernateProperties
=
bean
.
getHibernateProperties
(
"create-drop"
);
assertThat
(
hibernateProperties
.
get
(
"hibernate.ejb.naming_strategy"
)).
isNull
();
});
}
@Test
public
void
testDefaultDatabaseForH2
()
throws
Exception
{
TestPropertyValues
.
of
(
"spring.datasource.url:jdbc:h2:mem:testdb"
,
"spring.datasource.initialize:false"
).
applyTo
(
this
.
context
);
this
.
context
.
register
(
TestConfiguration
.
class
,
DataSourceAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
HibernateJpaAutoConfiguration
.
class
);
this
.
context
.
refresh
();
HibernateJpaVendorAdapter
bean
=
this
.
context
.
getBean
(
HibernateJpaVendorAdapter
.
class
);
Database
database
=
(
Database
)
ReflectionTestUtils
.
getField
(
bean
,
"database"
);
assertThat
(
database
).
isEqualTo
(
Database
.
H2
);
public
void
defaultDatabaseForH2
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.datasource.url:jdbc:h2:mem:testdb"
,
"spring.datasource.initialize:false"
).
run
((
context
)
->
{
HibernateJpaVendorAdapter
bean
=
context
.
getBean
(
HibernateJpaVendorAdapter
.
class
);
Database
database
=
(
Database
)
ReflectionTestUtils
.
getField
(
bean
,
"database"
);
assertThat
(
database
).
isEqualTo
(
Database
.
H2
);
});
}
@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