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
2577d79f
Commit
2577d79f
authored
Nov 29, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
82a847c8
b618c70e
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
908 additions
and
25 deletions
+908
-25
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+37
-1
SampleTestApplicationWebIntegrationTests.java
...sample/test/SampleTestApplicationWebIntegrationTests.java
+1
-1
UserVehicleControllerApplicationTests.java
...ample/test/web/UserVehicleControllerApplicationTests.java
+1
-1
AutoConfigureJdbc.java
...ework/boot/test/autoconfigure/jdbc/AutoConfigureJdbc.java
+41
-0
AutoConfigureTestDatabase.java
...ot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java
+82
-0
JdbcTest.java
...pringframework/boot/test/autoconfigure/jdbc/JdbcTest.java
+98
-0
JdbcTypeExcludeFilter.java
...k/boot/test/autoconfigure/jdbc/JdbcTypeExcludeFilter.java
+76
-0
TestDatabaseAutoConfiguration.java
...est/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java
+1
-1
AutoConfigureTestDatabase.java
...test/autoconfigure/orm/jpa/AutoConfigureTestDatabase.java
+4
-2
DataJpaTest.java
...ramework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java
+1
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+15
-1
AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests.java
...eTestDatabaseWithMultipleDatasourcesIntegrationTests.java
+2
-16
AutoConfigureTestDatabaseWithNoDatabaseIntegrationTests.java
...oConfigureTestDatabaseWithNoDatabaseIntegrationTests.java
+1
-1
ExampleEntity.java
...framework/boot/test/autoconfigure/jdbc/ExampleEntity.java
+51
-0
ExampleJdbcApplication.java
.../boot/test/autoconfigure/jdbc/ExampleJdbcApplication.java
+41
-0
ExampleRepository.java
...ework/boot/test/autoconfigure/jdbc/ExampleRepository.java
+70
-0
JdbcTestIntegrationTests.java
...oot/test/autoconfigure/jdbc/JdbcTestIntegrationTests.java
+98
-0
JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java
...ureTestDatabaseReplaceAutoConfiguredIntegrationTests.java
+59
-0
JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests.java
...ReplaceAutoConfiguredWithoutOverrideIntegrationTests.java
+51
-0
JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java
...ConfigureTestDatabaseReplaceExplicitIntegrationTests.java
+70
-0
JdbcTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests.java
...AutoConfigureTestDatabaseReplaceNoneIntegrationTests.java
+51
-0
JdbcTestWithIncludeFilterIntegrationTests.java
...igure/jdbc/JdbcTestWithIncludeFilterIntegrationTests.java
+51
-0
TestDatabaseAutoConfigurationTests.java
...utoconfigure/jdbc/TestDatabaseAutoConfigurationTests.java
+1
-1
DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java
...ureTestDatabaseReplaceAutoConfiguredIntegrationTests.java
+1
-0
DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests.java
...ReplaceAutoConfiguredWithoutOverrideIntegrationTests.java
+1
-0
DataJpaTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java
...ConfigureTestDatabaseReplaceExplicitIntegrationTests.java
+1
-0
DataJpaTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests.java
...AutoConfigureTestDatabaseReplaceNoneIntegrationTests.java
+1
-0
schema.sql
...g/springframework/boot/test/autoconfigure/jdbc/schema.sql
+1
-0
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
2577d79f
...
@@ -5294,7 +5294,7 @@ Data JPA repositories. Regular `@Component` beans will not be loaded into the
...
@@ -5294,7 +5294,7 @@ Data JPA repositories. Regular `@Component` beans will not be loaded into the
`ApplicationContext`.
`ApplicationContext`.
Data JPA tests are transactional and rollback at the end of each test by default,
Data JPA tests are transactional and rollback at the end of each test by default,
see the {spring-reference}#testcontext-tx-enabling-transactions
[relevant section] in the
see the {spring-reference}#testcontext-tx-enabling-transactions[relevant section] in the
Spring Reference Documentation for more details. If that's not what you want, you can
Spring Reference Documentation for more details. If that's not what you want, you can
disable transaction management for a test or for the whole class as follows:
disable transaction management for a test or for the whole class as follows:
...
@@ -5372,6 +5372,42 @@ A list of the auto-configuration that is enabled by `@DataJpaTest` can be
...
@@ -5372,6 +5372,42 @@ A list of the auto-configuration that is enabled by `@DataJpaTest` can be
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-jdbc-test]]
==== Auto-configured JDBC tests
`@JdbcTest` is similar to `@DataJpaTest` but for pure jdbc-related tests. By default it
will also configure an in-memory embedded database and a `JdbcTemplate`. Regular
`@Component` beans will not be loaded into the `ApplicationContext`.
JDBC tests are transactional and rollback at the end of each test by default,
see the {spring-reference}#testcontext-tx-enabling-transactions[relevant section] in the
Spring Reference Documentation for more details. If that's not what you want, you can
disable transaction management for a test or for the whole class as follows:
[source,java,indent=0]
----
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@RunWith(SpringRunner.class)
@JdbcTest
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class ExampleNonTransactionalTests {
}
----
If you prefer your test to run against a real database, you can use the
`@AutoConfigureTestDatabase` annotation the same way as for `DataJpaTest`.
A list of the auto-configuration that is enabled by `@JdbcTest` can be
<<appendix-test-auto-configuration#test-auto-configuration,found in the appendix>>.
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-client]]
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-rest-client]]
==== Auto-configured REST clients
==== Auto-configured REST clients
The `@RestClientTest` annotation can be used if you want to test REST clients. By default
The `@RestClientTest` annotation can be used if you want to test REST clients. By default
...
...
spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/SampleTestApplicationWebIntegrationTests.java
View file @
2577d79f
...
@@ -24,7 +24,7 @@ import sample.test.service.VehicleDetails;
...
@@ -24,7 +24,7 @@ import sample.test.service.VehicleDetails;
import
sample.test.service.VehicleDetailsService
;
import
sample.test.service.VehicleDetailsService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.
orm.jpa
.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.
jdbc
.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.context.SpringBootTest.WebEnvironment
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
...
...
spring-boot-samples/spring-boot-sample-test/src/test/java/sample/test/web/UserVehicleControllerApplicationTests.java
View file @
2577d79f
...
@@ -22,7 +22,7 @@ import sample.test.WelcomeCommandLineRunner;
...
@@ -22,7 +22,7 @@ import sample.test.WelcomeCommandLineRunner;
import
sample.test.service.VehicleDetails
;
import
sample.test.service.VehicleDetails
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.
orm.jpa
.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.
jdbc
.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
...
...
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureJdbc.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
/**
* {@link ImportAutoConfiguration Auto-configuration imports} for typical jdbc tests.
* Most tests should consider using {@link JdbcTest @JdbcTest} rather than using
* this annotation directly.
*
* @author Stephane Nicoll
* @since 1.5.0
* @see JdbcTest
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@ImportAutoConfiguration
public
@interface
AutoConfigureJdbc
{
}
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/AutoConfigureTestDatabase.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
javax.sql.DataSource
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.boot.test.autoconfigure.properties.PropertyMapping
;
/**
* Annotation that can be applied to a test class to configure a test database to use
* instead of any application defined or auto-configured {@link DataSource}.
*
* @author Phillip Webb
* @see TestDatabaseAutoConfiguration
*/
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@ImportAutoConfiguration
@PropertyMapping
(
"spring.test.database"
)
public
@interface
AutoConfigureTestDatabase
{
/**
* Determines what type of existing DataSource beans can be replaced.
* @return the type of existing DataSource to replace
*/
Replace
replace
()
default
Replace
.
ANY
;
/**
* The type of connection to be established when {@link #replace() replacing} the data
* source. By default will attempt to detect the connection based on the classpath.
* @return the type of connection to use
*/
EmbeddedDatabaseConnection
connection
()
default
EmbeddedDatabaseConnection
.
NONE
;
/**
* What the test database can replace.
*/
enum
Replace
{
/**
* Replace any DataSource bean (auto-configured or manually defined).
*/
ANY
,
/**
* Only replace auto-configured DataSource.
*/
AUTO_CONFIGURED
,
/**
* Don't replace the application default DataSource.
*/
NONE
}
}
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.springframework.boot.autoconfigure.ImportAutoConfiguration
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.test.context.BootstrapWith
;
import
org.springframework.transaction.annotation.Transactional
;
/**
* Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)}
* for a typical jdbc test. Can be used when a test focuses <strong>only</strong> on
* jdbc-based components.
* <p>
* Using this annotation will disable full auto-configuration and instead apply only
* configuration relevant to jdbc tests.
* <p>
* By default, tests annotated with {@code @JdbcTest} will use an embedded in-memory
* database (replacing any explicit or usually auto-configured DataSource). The
* {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} annotation can be used to
* override these settings.
* <p>
* If you are looking to load your full application configuration, but use an embedded
* database, you should consider {@link SpringBootTest @SpringBootTest} combined with
* {@link AutoConfigureTestDatabase @AutoConfigureTestDatabase} rather than this
* annotation.
*
* @author Stephane Nicoll
* @see AutoConfigureJdbc
* @see AutoConfigureTestDatabase
* @see AutoConfigureCache
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
@BootstrapWith
(
SpringBootTestContextBootstrapper
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@TypeExcludeFilters
(
JdbcTypeExcludeFilter
.
class
)
@Transactional
@AutoConfigureCache
@AutoConfigureJdbc
@AutoConfigureTestDatabase
@ImportAutoConfiguration
public
@interface
JdbcTest
{
/**
* Determines if default filtering should be used with
* {@link SpringBootApplication @SpringBootApplication}. By default no beans are
* included.
* @see #includeFilters()
* @see #excludeFilters()
* @return if default filters should be used
*/
boolean
useDefaultFilters
()
default
true
;
/**
* A set of include filters which can be used to add otherwise filtered beans to the
* application context.
* @return include filters to apply
*/
ComponentScan
.
Filter
[]
includeFilters
()
default
{};
/**
* A set of exclude filters which can be used to filter beans that would otherwise be
* added to the application context.
* @return exclude filters to apply
*/
ComponentScan
.
Filter
[]
excludeFilters
()
default
{};
}
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTypeExcludeFilter.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.Set
;
import
org.springframework.boot.context.TypeExcludeFilter
;
import
org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizableTypeExcludeFilter
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
import
org.springframework.core.type.classreading.MetadataReader
;
import
org.springframework.core.type.classreading.MetadataReaderFactory
;
/**
* {@link TypeExcludeFilter} for {@link JdbcTest @Jdbctest}.
*
* @author Stephane Nicoll
*/
class
JdbcTypeExcludeFilter
extends
AnnotationCustomizableTypeExcludeFilter
{
private
final
JdbcTest
annotation
;
JdbcTypeExcludeFilter
(
Class
<?>
testClass
)
{
this
.
annotation
=
AnnotatedElementUtils
.
getMergedAnnotation
(
testClass
,
JdbcTest
.
class
);
}
@Override
protected
boolean
hasAnnotation
()
{
return
this
.
annotation
!=
null
;
}
@Override
protected
ComponentScan
.
Filter
[]
getFilters
(
FilterType
type
)
{
switch
(
type
)
{
case
INCLUDE:
return
this
.
annotation
.
includeFilters
();
case
EXCLUDE:
return
this
.
annotation
.
excludeFilters
();
}
throw
new
IllegalStateException
(
"Unsupported type "
+
type
);
}
@Override
protected
boolean
isUseDefaultFilters
()
{
return
this
.
annotation
.
useDefaultFilters
();
}
@Override
protected
boolean
defaultInclude
(
MetadataReader
metadataReader
,
MetadataReaderFactory
metadataReaderFactory
)
throws
IOException
{
return
false
;
}
@Override
protected
Set
<
Class
<?>>
getDefaultIncludes
()
{
return
Collections
.
emptySet
();
}
}
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/
orm/jpa
/TestDatabaseAutoConfiguration.java
→
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/
jdbc
/TestDatabaseAutoConfiguration.java
View file @
2577d79f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
orm
.
jpa
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
...
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/AutoConfigureTestDatabase.java
View file @
2577d79f
...
@@ -33,8 +33,8 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
...
@@ -33,8 +33,8 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
* Annotation that can be applied to a test class to configure a test database to use
* Annotation that can be applied to a test class to configure a test database to use
* instead of any application defined or auto-configured {@link DataSource}.
* instead of any application defined or auto-configured {@link DataSource}.
*
*
* @author
Phillip Webb
* @author
Stephane Nicoll
* @
see TestDatabaseAutoConfiguration
* @
deprecated since 1.5 in favour of {@link org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase}
*/
*/
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Target
({
ElementType
.
TYPE
,
ElementType
.
METHOD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
...
@@ -42,6 +42,7 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
...
@@ -42,6 +42,7 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
@Inherited
@Inherited
@ImportAutoConfiguration
@ImportAutoConfiguration
@PropertyMapping
(
"spring.test.database"
)
@PropertyMapping
(
"spring.test.database"
)
@Deprecated
public
@interface
AutoConfigureTestDatabase
{
public
@interface
AutoConfigureTestDatabase
{
/**
/**
...
@@ -60,6 +61,7 @@ public @interface AutoConfigureTestDatabase {
...
@@ -60,6 +61,7 @@ public @interface AutoConfigureTestDatabase {
/**
/**
* What the test database can replace.
* What the test database can replace.
*/
*/
@Deprecated
enum
Replace
{
enum
Replace
{
/**
/**
...
...
spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java
View file @
2577d79f
...
@@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
...
@@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import
org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration
;
import
org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.properties.PropertyMapping
;
import
org.springframework.boot.test.autoconfigure.properties.PropertyMapping
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
...
...
spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
2577d79f
...
@@ -13,6 +13,20 @@ org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
...
@@ -13,6 +13,20 @@ org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
# AutoConfigureJdbc auto-configuration imports
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureJdbc=\
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
# AutoConfigureTestDatabase auto-configuration imports
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase=\
org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
# AutoConfigureJson auto-configuration imports
# AutoConfigureJson auto-configuration imports
org.springframework.boot.test.autoconfigure.json.AutoConfigureJson=\
org.springframework.boot.test.autoconfigure.json.AutoConfigureJson=\
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration,\
...
@@ -39,7 +53,7 @@ org.springframework.boot.test.autoconfigure.restdocs.RestDocsAutoConfiguration
...
@@ -39,7 +53,7 @@ org.springframework.boot.test.autoconfigure.restdocs.RestDocsAutoConfiguration
# AutoConfigureTestDatabase auto-configuration imports
# AutoConfigureTestDatabase auto-configuration imports
org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase=\
org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestDatabase=\
org.springframework.boot.test.autoconfigure.
orm.jpa
.TestDatabaseAutoConfiguration,\
org.springframework.boot.test.autoconfigure.
jdbc
.TestDatabaseAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
# AutoConfigureTestEntityManager auto-configuration imports
# AutoConfigureTestEntityManager auto-configuration imports
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/
orm/jpa
/AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests.java
→
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/
jdbc
/AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests.java
View file @
2577d79f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
orm
.
jpa
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
@@ -39,27 +39,13 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -39,27 +39,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Greg Potter
* @author Greg Potter
*/
*/
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@
DataJpa
Test
@
Jdbc
Test
@AutoConfigureTestDatabase
@AutoConfigureTestDatabase
public
class
AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests
{
public
class
AutoConfigureTestDatabaseWithMultipleDatasourcesIntegrationTests
{
@Autowired
private
TestEntityManager
entities
;
@Autowired
private
ExampleRepository
repository
;
@Autowired
@Autowired
private
DataSource
dataSource
;
private
DataSource
dataSource
;
@Test
public
void
testRepository
()
throws
Exception
{
this
.
entities
.
persist
(
new
ExampleEntity
(
"boot"
,
"124"
));
this
.
entities
.
flush
();
ExampleEntity
found
=
this
.
repository
.
findByReference
(
"124"
);
assertThat
(
found
.
getName
()).
isEqualTo
(
"boot"
);
}
@Test
@Test
public
void
replacesDefinedDataSourceWithExplicit
()
throws
Exception
{
public
void
replacesDefinedDataSourceWithExplicit
()
throws
Exception
{
// Look that the datasource is replaced with an H2 DB.
// Look that the datasource is replaced with an H2 DB.
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/
orm/jpa
/AutoConfigureTestDatabaseWithNoDatabaseIntegrationTests.java
→
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/
jdbc
/AutoConfigureTestDatabaseWithNoDatabaseIntegrationTests.java
View file @
2577d79f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
orm
.
jpa
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleEntity.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
/**
* Example entity used with {@link JdbcTest} tests.
*
* @author Stephane Nicoll
*/
public
class
ExampleEntity
{
private
final
int
id
;
private
String
name
;
public
ExampleEntity
(
int
id
,
String
name
)
{
this
.
id
=
id
;
this
.
name
=
name
;
}
public
ExampleEntity
(
int
id
)
{
this
(
id
,
null
);
}
public
int
getId
()
{
return
this
.
id
;
}
public
String
getName
()
{
return
this
.
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleJdbcApplication.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
/**
* Example {@link SpringBootApplication} used with {@link JdbcTest} tests.
*
* @author Phillip Webb
*/
@SpringBootApplication
public
class
ExampleJdbcApplication
{
@Bean
public
DataSource
dataSource
()
{
EmbeddedDatabaseBuilder
builder
=
new
EmbeddedDatabaseBuilder
()
.
setType
(
EmbeddedDatabaseType
.
HSQL
);
return
builder
.
build
();
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleRepository.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.util.Collection
;
import
javax.transaction.Transactional
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.core.RowMapper
;
import
org.springframework.stereotype.Repository
;
/**
* Example repository used with {@link JdbcTest} tests.
*
* @author Stephane Nicoll
*/
@Repository
public
class
ExampleRepository
{
private
static
final
ExampleEntityRowMapper
ROW_MAPPER
=
new
ExampleEntityRowMapper
();
private
final
JdbcTemplate
jdbcTemplate
;
public
ExampleRepository
(
JdbcTemplate
jdbcTemplate
)
{
this
.
jdbcTemplate
=
jdbcTemplate
;
}
@Transactional
public
void
save
(
ExampleEntity
entity
)
{
this
.
jdbcTemplate
.
update
(
"insert into example (id, name) values (?, ?)"
,
entity
.
getId
(),
entity
.
getName
());
}
public
ExampleEntity
findById
(
int
id
)
{
return
this
.
jdbcTemplate
.
queryForObject
(
"select id, name from example where id =?"
,
new
Object
[]
{
id
},
ROW_MAPPER
);
}
public
Collection
<
ExampleEntity
>
findAll
()
{
return
this
.
jdbcTemplate
.
query
(
"select id, name from example"
,
ROW_MAPPER
);
}
private
static
class
ExampleEntityRowMapper
implements
RowMapper
<
ExampleEntity
>
{
@Override
public
ExampleEntity
mapRow
(
ResultSet
rs
,
int
rowNum
)
throws
SQLException
{
int
id
=
rs
.
getInt
(
"id"
);
String
name
=
rs
.
getString
(
"name"
);
return
new
ExampleEntity
(
id
,
name
);
}
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestIntegrationTests.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
java.util.Collection
;
import
javax.sql.DataSource
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration
;
import
org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.test.context.TestPropertySource
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
springframework
.
boot
.
test
.
autoconfigure
.
AutoConfigurationImportedCondition
.
importedAutoConfiguration
;
/**
* Integration tests for {@link JdbcTest}.
*
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
@TestPropertySource
(
properties
=
"spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql"
)
public
class
JdbcTestIntegrationTests
{
@Rule
public
ExpectedException
thrown
=
ExpectedException
.
none
();
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
DataSource
dataSource
;
@Autowired
private
ApplicationContext
applicationContext
;
@Test
public
void
testJdbcTemplate
()
{
ExampleRepository
repository
=
new
ExampleRepository
(
this
.
jdbcTemplate
);
repository
.
save
(
new
ExampleEntity
(
1
,
"John"
));
Collection
<
ExampleEntity
>
entities
=
repository
.
findAll
();
assertThat
(
entities
).
hasSize
(
1
);
ExampleEntity
entity
=
entities
.
iterator
().
next
();
assertThat
(
entity
.
getId
()).
isEqualTo
(
1
);
assertThat
(
entity
.
getName
()).
isEqualTo
(
"John"
);
}
@Test
public
void
replacesDefinedDataSourceWithEmbeddedDefault
()
throws
Exception
{
String
product
=
this
.
dataSource
.
getConnection
().
getMetaData
()
.
getDatabaseProductName
();
assertThat
(
product
).
isEqualTo
(
"H2"
);
}
@Test
public
void
didNotInjectExampleRepository
()
{
this
.
thrown
.
expect
(
NoSuchBeanDefinitionException
.
class
);
this
.
applicationContext
.
getBean
(
ExampleRepository
.
class
);
}
@Test
public
void
flywayAutoConfigurationWasImported
()
{
assertThat
(
this
.
applicationContext
)
.
has
(
importedAutoConfiguration
(
FlywayAutoConfiguration
.
class
));
}
@Test
public
void
liquibaseAutoConfigurationWasImported
()
{
assertThat
(
this
.
applicationContext
)
.
has
(
importedAutoConfiguration
(
LiquibaseAutoConfiguration
.
class
));
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link JdbcTest}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
@AutoConfigureTestDatabase
(
replace
=
AutoConfigureTestDatabase
.
Replace
.
AUTO_CONFIGURED
,
connection
=
EmbeddedDatabaseConnection
.
HSQL
)
public
class
JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests
{
@Autowired
private
DataSource
dataSource
;
@Test
public
void
replacesAutoConfiguredDataSource
()
throws
Exception
{
String
product
=
this
.
dataSource
.
getConnection
().
getMetaData
()
.
getDatabaseProductName
();
assertThat
(
product
).
startsWith
(
"HSQL"
);
}
@Configuration
@EnableAutoConfiguration
// Will auto-configure H2
static
class
Config
{
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link JdbcTest}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
@AutoConfigureTestDatabase
(
replace
=
AutoConfigureTestDatabase
.
Replace
.
AUTO_CONFIGURED
)
public
class
JdbcTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests
{
@Autowired
private
DataSource
dataSource
;
@Test
public
void
usesDefaultEmbeddedDatabase
()
throws
Exception
{
String
product
=
this
.
dataSource
.
getConnection
().
getMetaData
()
.
getDatabaseProductName
();
// @AutoConfigureTestDatabase would use H2 but HSQL is manually defined
assertThat
(
product
).
startsWith
(
"HSQL"
);
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder
;
import
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link JdbcTest}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
@AutoConfigureTestDatabase
(
connection
=
EmbeddedDatabaseConnection
.
HSQL
)
public
class
JdbcTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests
{
@Autowired
private
DataSource
dataSource
;
@Test
public
void
replacesDefinedDataSourceWithExplicit
()
throws
Exception
{
// H2 is explicitly defined but HSQL is the override.
String
product
=
this
.
dataSource
.
getConnection
().
getMetaData
()
.
getDatabaseProductName
();
assertThat
(
product
).
startsWith
(
"HSQL"
);
}
@Configuration
@EnableAutoConfiguration
static
class
Config
{
@Bean
public
DataSource
dataSource
()
{
EmbeddedDatabaseBuilder
builder
=
new
EmbeddedDatabaseBuilder
()
.
setType
(
EmbeddedDatabaseType
.
H2
);
return
builder
.
build
();
}
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link JdbcTest}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
@AutoConfigureTestDatabase
(
replace
=
AutoConfigureTestDatabase
.
Replace
.
NONE
)
public
class
JdbcTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests
{
@Autowired
private
DataSource
dataSource
;
@Test
public
void
usesDefaultEmbeddedDatabase
()
throws
Exception
{
// HSQL is explicitly defined and should not be replaced
String
product
=
this
.
dataSource
.
getConnection
().
getMetaData
()
.
getDatabaseProductName
();
assertThat
(
product
).
startsWith
(
"HSQL"
);
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestWithIncludeFilterIntegrationTests.java
0 → 100644
View file @
2577d79f
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.test.context.TestPropertySource
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration test with custom include filter for {@link JdbcTest}.
*
* @author Stephane Nicoll
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
(
includeFilters
=
@Filter
(
Repository
.
class
))
@TestPropertySource
(
properties
=
"spring.datasource.schema=classpath:org/springframework/boot/test/autoconfigure/jdbc/schema.sql"
)
public
class
JdbcTestWithIncludeFilterIntegrationTests
{
@Autowired
private
ExampleRepository
repository
;
@Test
public
void
testRepository
()
{
this
.
repository
.
save
(
new
ExampleEntity
(
42
,
"Smith"
));
ExampleEntity
entity
=
this
.
repository
.
findById
(
42
);
assertThat
(
entity
).
isNotNull
();
assertThat
(
entity
.
getName
()).
isEqualTo
(
"Smith"
);
}
}
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/
orm/jpa
/TestDatabaseAutoConfigurationTests.java
→
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/
jdbc
/TestDatabaseAutoConfigurationTests.java
View file @
2577d79f
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
orm
.
jpa
;
package
org
.
springframework
.
boot
.
test
.
autoconfigure
.
jdbc
;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests.java
View file @
2577d79f
...
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
@DataJpaTest
@AutoConfigureTestDatabase
(
replace
=
Replace
.
AUTO_CONFIGURED
,
connection
=
EmbeddedDatabaseConnection
.
HSQL
)
@AutoConfigureTestDatabase
(
replace
=
Replace
.
AUTO_CONFIGURED
,
connection
=
EmbeddedDatabaseConnection
.
HSQL
)
@Deprecated
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests
{
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredIntegrationTests
{
@Autowired
@Autowired
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests.java
View file @
2577d79f
...
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
@DataJpaTest
@AutoConfigureTestDatabase
(
replace
=
Replace
.
AUTO_CONFIGURED
)
@AutoConfigureTestDatabase
(
replace
=
Replace
.
AUTO_CONFIGURED
)
@Deprecated
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests
{
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceAutoConfiguredWithoutOverrideIntegrationTests
{
@Autowired
@Autowired
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests.java
View file @
2577d79f
...
@@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
@DataJpaTest
@AutoConfigureTestDatabase
(
connection
=
EmbeddedDatabaseConnection
.
HSQL
)
@AutoConfigureTestDatabase
(
connection
=
EmbeddedDatabaseConnection
.
HSQL
)
@Deprecated
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests
{
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceExplicitIntegrationTests
{
@Autowired
@Autowired
...
...
spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests.java
View file @
2577d79f
...
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith
(
SpringRunner
.
class
)
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
@DataJpaTest
@AutoConfigureTestDatabase
(
replace
=
Replace
.
NONE
)
@AutoConfigureTestDatabase
(
replace
=
Replace
.
NONE
)
@Deprecated
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests
{
public
class
DataJpaTestWithAutoConfigureTestDatabaseReplaceNoneIntegrationTests
{
@Autowired
@Autowired
...
...
spring-boot-test-autoconfigure/src/test/resources/org/springframework/boot/test/autoconfigure/jdbc/schema.sql
0 → 100644
View file @
2577d79f
create
table
example
(
id
int
,
name
varchar
);
\ 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