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
09de86fd
Commit
09de86fd
authored
Nov 04, 2013
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test broken by MySQL dependency
parent
fc40ad4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
5 deletions
+52
-5
DataSourceAutoConfiguration.java
.../boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java
+2
-1
DataSourceAutoConfigurationTests.java
.../autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
+50
-4
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration.java
View file @
09de86fd
...
...
@@ -86,7 +86,8 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
@PostConstruct
protected
void
initialize
()
throws
Exception
{
if
(
this
.
dataSource
==
null
)
{
if
(
this
.
dataSource
==
null
||
!
this
.
environment
.
getProperty
(
"initialize"
,
Boolean
.
class
,
true
))
{
logger
.
debug
(
"No DataSource found so not initializing"
);
return
;
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java
View file @
09de86fd
...
...
@@ -16,13 +16,19 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
jdbc
;
import
java.sql.Connection
;
import
java.sql.Driver
;
import
java.sql.DriverPropertyInfo
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
import
javax.sql.DataSource
;
import
org.apache.commons.dbcp.BasicDataSource
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.springframework.boot.TestUtils
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
...
...
@@ -73,16 +79,21 @@ public class DataSourceAutoConfigurationTests {
@Test
public
void
testExplicitDriverClassClearsUserName
()
throws
Exception
{
TestUtils
.
addEnviroment
(
this
.
context
,
"spring.datasource.driverClassName:com.mysql.jdbc.Driver"
,
"spring.datasource.url:jdbc:mysql://localhost"
);
TestUtils
.
addEnviroment
(
this
.
context
,
"spring.datasource.driverClassName:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver"
,
"spring.datasource.url:jdbc:foo://localhost"
,
"spring.datasource.initialize:false"
);
this
.
context
.
register
(
DataSourceAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
DataSource
bean
=
this
.
context
.
getBean
(
DataSource
.
class
);
assertNotNull
(
bean
);
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
pool
=
(
org
.
apache
.
tomcat
.
jdbc
.
pool
.
DataSource
)
bean
;
assertEquals
(
"com.mysql.jdbc.Driver"
,
pool
.
getDriverClassName
());
assertEquals
(
"org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfigurationTests$DatabaseDriver"
,
pool
.
getDriverClassName
());
assertNull
(
pool
.
getUsername
());
}
...
...
@@ -196,4 +207,39 @@ public class DataSourceAutoConfigurationTests {
}
public
static
class
DatabaseDriver
implements
Driver
{
@Override
public
Connection
connect
(
String
url
,
Properties
info
)
throws
SQLException
{
return
Mockito
.
mock
(
Connection
.
class
);
}
@Override
public
boolean
acceptsURL
(
String
url
)
throws
SQLException
{
return
true
;
}
@Override
public
DriverPropertyInfo
[]
getPropertyInfo
(
String
url
,
Properties
info
)
throws
SQLException
{
return
new
DriverPropertyInfo
[
0
];
}
@Override
public
int
getMajorVersion
()
{
return
1
;
}
@Override
public
int
getMinorVersion
()
{
return
0
;
}
@Override
public
boolean
jdbcCompliant
()
{
return
false
;
}
}
}
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