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
3b4ff7d7
Commit
3b4ff7d7
authored
May 10, 2019
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable ConfigurationProperties scanning for slice tests
Closes gh-16659
parent
930186e5
Changes
48
Hide whitespace changes
Inline
Side-by-side
Showing
48 changed files
with
1454 additions
and
3 deletions
+1454
-3
OverrideConfigurationPropertiesScan.java
...st/autoconfigure/OverrideConfigurationPropertiesScan.java
+48
-0
OverrideConfigurationPropertiesScanContextCustomizerFactory.java
...eConfigurationPropertiesScanContextCustomizerFactory.java
+76
-0
DataJdbcTest.java
...ework/boot/test/autoconfigure/data/jdbc/DataJdbcTest.java
+2
-0
DataLdapTest.java
...ework/boot/test/autoconfigure/data/ldap/DataLdapTest.java
+2
-0
DataMongoTest.java
...ork/boot/test/autoconfigure/data/mongo/DataMongoTest.java
+2
-0
DataNeo4jTest.java
...ork/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java
+2
-0
DataRedisTest.java
...ork/boot/test/autoconfigure/data/redis/DataRedisTest.java
+2
-0
JdbcTest.java
...pringframework/boot/test/autoconfigure/jdbc/JdbcTest.java
+2
-0
JooqTest.java
...pringframework/boot/test/autoconfigure/jooq/JooqTest.java
+2
-0
JsonTest.java
...pringframework/boot/test/autoconfigure/json/JsonTest.java
+2
-0
DataJpaTest.java
...ramework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java
+2
-0
RestClientTest.java
...rk/boot/test/autoconfigure/web/client/RestClientTest.java
+2
-0
WebFluxTest.java
...ork/boot/test/autoconfigure/web/reactive/WebFluxTest.java
+2
-0
WebMvcTest.java
...ework/boot/test/autoconfigure/web/servlet/WebMvcTest.java
+2
-0
spring.factories
...utoconfigure/src/main/resources/META-INF/spring.factories
+1
-0
OverrideConfigurationPropertiesScanContextCustomizerFactoryTests.java
...igurationPropertiesScanContextCustomizerFactoryTests.java
+90
-0
DataJdbcTestConfigurationPropertiesScanDisabledTests.java
...DataJdbcTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
.../boot/test/autoconfigure/data/jdbc/ExampleProperties.java
+30
-0
DataLdapTestConfigurationPropertiesScanDisabledTests.java
...DataLdapTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
.../boot/test/autoconfigure/data/ldap/ExampleProperties.java
+30
-0
DataMongoTestConfigurationPropertiesScanDisabledTests.java
...ataMongoTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
...boot/test/autoconfigure/data/mongo/ExampleProperties.java
+30
-0
DataNeo4jTestConfigurationPropertiesScanDisabledTests.java
...ataNeo4jTestConfigurationPropertiesScanDisabledTests.java
+73
-0
ExampleProperties.java
...boot/test/autoconfigure/data/neo4j/ExampleProperties.java
+30
-0
DataRedisTestConfigurationPropertiesScanDisabledTests.java
...ataRedisTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
...boot/test/autoconfigure/data/redis/ExampleProperties.java
+30
-0
ExampleProperties.java
...ework/boot/test/autoconfigure/jdbc/ExampleProperties.java
+30
-0
JdbcTestConfigurationPropertiesScanDisabledTests.java
...dbc/JdbcTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
...ework/boot/test/autoconfigure/jooq/ExampleProperties.java
+30
-0
JooqTestConfigurationPropertiesScanDisabledTests.java
...ooq/JooqTestConfigurationPropertiesScanDisabledTests.java
+48
-0
JsonTestConfigurationPropertiesScanDisabledTests.java
...son/JsonTestConfigurationPropertiesScanDisabledTests.java
+52
-0
ExampleProperties.java
...k/boot/test/autoconfigure/json/app/ExampleProperties.java
+31
-0
DataJpaTestConfigurationPropertiesScanDisabledTests.java
.../DataJpaTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
...rk/boot/test/autoconfigure/orm/jpa/ExampleProperties.java
+30
-0
ExampleTestProperties.java
...ot/test/autoconfigure/override/ExampleTestProperties.java
+31
-0
ExampleProperties.java
...t/test/autoconfigure/override/scan/ExampleProperties.java
+31
-0
OverrideConfigurationPropertiesScanApplication.java
.../scan/OverrideConfigurationPropertiesScanApplication.java
+31
-0
OverrideConfigurationPropertiesScanEnabledFalseIntegrationTests.java
...figurationPropertiesScanEnabledFalseIntegrationTests.java
+67
-0
OverrideConfigurationPropertiesScanEnabledTrueIntegrationTests.java
...nfigurationPropertiesScanEnabledTrueIntegrationTests.java
+51
-0
ExampleProperties.java
...boot/test/autoconfigure/web/client/ExampleProperties.java
+30
-0
RestClientTestConfigurationPropertiesScanDisabledTests.java
...stClientTestConfigurationPropertiesScanDisabledTests.java
+48
-0
ExampleProperties.java
...toconfigure/web/reactive/webclient/ExampleProperties.java
+31
-0
WebFluxTestConfigurationPropertiesScanDisabledTests.java
.../WebFluxTestConfigurationPropertiesScanDisabledTests.java
+49
-0
ExampleProperties.java
.../autoconfigure/web/servlet/mockmvc/ExampleProperties.java
+31
-0
WebMvcTestConfigurationPropertiesScanDisabledTests.java
...c/WebMvcTestConfigurationPropertiesScanDisabledTests.java
+49
-0
ConfigurationPropertiesScan.java
.../boot/context/properties/ConfigurationPropertiesScan.java
+5
-0
ConfigurationPropertiesScanRegistrar.java
...text/properties/ConfigurationPropertiesScanRegistrar.java
+11
-2
ConfigurationPropertiesScanRegistrarTests.java
...properties/ConfigurationPropertiesScanRegistrarTests.java
+18
-1
No files found.
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideConfigurationPropertiesScan.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
;
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.context.properties.ConfigurationPropertiesScan
;
/**
* Annotation that can be used to override
* {@link ConfigurationPropertiesScan @ConfigurationPropertiesScan}.
*
* @author Madhura Bhave
* @since 2.2.0
* @see ConfigurationPropertiesScan#CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
*/
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
OverrideConfigurationPropertiesScan
{
/**
* The value of the
* {@link ConfigurationPropertiesScan#CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
* enabled override property}.
* @return the override value
*/
boolean
enabled
();
}
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideConfigurationPropertiesScanContextCustomizerFactory.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
;
import
java.util.List
;
import
org.springframework.boot.context.properties.ConfigurationPropertiesScan
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.core.annotation.MergedAnnotations
;
import
org.springframework.core.annotation.MergedAnnotations.SearchStrategy
;
import
org.springframework.test.context.ContextConfigurationAttributes
;
import
org.springframework.test.context.ContextCustomizer
;
import
org.springframework.test.context.ContextCustomizerFactory
;
import
org.springframework.test.context.MergedContextConfiguration
;
/**
* {@link ContextCustomizerFactory} to support
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan}.
*
* @author Madhura Bhave
*/
class
OverrideConfigurationPropertiesScanContextCustomizerFactory
implements
ContextCustomizerFactory
{
@Override
public
ContextCustomizer
createContextCustomizer
(
Class
<?>
testClass
,
List
<
ContextConfigurationAttributes
>
configurationAttributes
)
{
boolean
enabled
=
MergedAnnotations
.
from
(
testClass
,
SearchStrategy
.
EXHAUSTIVE
)
.
get
(
OverrideConfigurationPropertiesScan
.
class
)
.
getValue
(
"enabled"
,
Boolean
.
class
).
orElse
(
true
);
return
!
enabled
?
new
DisableConfigurationPropertiesContextCustomizer
()
:
null
;
}
/**
* {@link ContextCustomizer} to disable configuration properties scanning.
*/
private
static
class
DisableConfigurationPropertiesContextCustomizer
implements
ContextCustomizer
{
@Override
public
void
customizeContext
(
ConfigurableApplicationContext
context
,
MergedContextConfiguration
mergedConfig
)
{
TestPropertyValues
.
of
(
ConfigurationPropertiesScan
.
CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
+
"=false"
)
.
applyTo
(
context
);
}
@Override
public
boolean
equals
(
Object
obj
)
{
return
(
obj
!=
null
&&
obj
.
getClass
()
==
getClass
());
}
@Override
public
int
hashCode
()
{
return
getClass
().
hashCode
();
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
...
...
@@ -55,6 +56,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@BootstrapWith
(
DataJdbcTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
DataJdbcTypeExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureDataJdbc
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
...
...
@@ -58,6 +59,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@BootstrapWith
(
DataLdapTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
DataLdapTypeExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureDataLdap
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
...
...
@@ -59,6 +60,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@BootstrapWith
(
DataMongoTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
DataMongoTypeExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureDataMongo
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
...
...
@@ -61,6 +62,7 @@ import org.springframework.transaction.annotation.Transactional;
@BootstrapWith
(
DataNeo4jTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
DataNeo4jTypeExcludeFilter
.
class
)
@Transactional
@AutoConfigureCache
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
...
...
@@ -55,6 +56,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@BootstrapWith
(
DataRedisTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
DataRedisTypeExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureDataRedis
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
@@ -69,6 +70,7 @@ import org.springframework.transaction.annotation.Transactional;
@BootstrapWith
(
JdbcTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
JdbcTypeExcludeFilter
.
class
)
@Transactional
@AutoConfigureCache
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
import
org.springframework.context.annotation.ComponentScan.Filter
;
...
...
@@ -62,6 +63,7 @@ import org.springframework.transaction.annotation.Transactional;
@BootstrapWith
(
JooqTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
JooqTypeExcludeFilter
.
class
)
@Transactional
@AutoConfigureJooq
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.json.GsonTester
;
...
...
@@ -67,6 +68,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
@BootstrapWith
(
JsonTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
JsonExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureJson
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
...
...
@@ -72,6 +73,7 @@ import org.springframework.transaction.annotation.Transactional;
@BootstrapWith
(
DataJpaTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
DataJpaTypeExcludeFilter
.
class
)
@Transactional
@AutoConfigureCache
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
...
...
@@ -70,6 +71,7 @@ import org.springframework.web.client.RestTemplate;
@BootstrapWith
(
RestClientTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
RestClientExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureWebClient
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.autoconfigure.json.AutoConfigureJson
;
...
...
@@ -78,6 +79,7 @@ import org.springframework.test.web.reactive.server.WebTestClient;
@BootstrapWith
(
WebFluxTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
WebFluxTypeExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureJson
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java
View file @
3b4ff7d7
...
...
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith;
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.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.core.AutoConfigureCache
;
import
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
@@ -79,6 +80,7 @@ import org.springframework.test.web.servlet.MockMvc;
@BootstrapWith
(
WebMvcTestContextBootstrapper
.
class
)
@ExtendWith
(
SpringExtension
.
class
)
@OverrideAutoConfiguration
(
enabled
=
false
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@TypeExcludeFilters
(
WebMvcTypeExcludeFilter
.
class
)
@AutoConfigureCache
@AutoConfigureWebMvc
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories
View file @
3b4ff7d7
...
...
@@ -160,6 +160,7 @@ org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExe
# Spring Test ContextCustomizerFactories
org.springframework.test.context.ContextCustomizerFactory=\
org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScanContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizerFactory,\
org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory
...
...
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/OverrideConfigurationPropertiesScanContextCustomizerFactoryTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
;
import
org.junit.Test
;
import
org.springframework.boot.context.properties.ConfigurationPropertiesScan
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.test.context.ContextCustomizer
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* @author Madhura Bhave
*/
public
class
OverrideConfigurationPropertiesScanContextCustomizerFactoryTests
{
private
OverrideConfigurationPropertiesScanContextCustomizerFactory
factory
=
new
OverrideConfigurationPropertiesScanContextCustomizerFactory
();
@Test
public
void
getContextCustomizerWhenHasNoAnnotationShouldReturnNull
()
{
ContextCustomizer
customizer
=
this
.
factory
.
createContextCustomizer
(
NoAnnotation
.
class
,
null
);
assertThat
(
customizer
).
isNull
();
}
@Test
public
void
getContextCustomizerWhenHasAnnotationEnabledTrueShouldReturnNull
()
{
ContextCustomizer
customizer
=
this
.
factory
.
createContextCustomizer
(
WithAnnotationEnabledTrue
.
class
,
null
);
assertThat
(
customizer
).
isNull
();
}
@Test
public
void
getContextCustomizerWhenHasAnnotationEnabledFalseShouldReturnCustomizer
()
{
ContextCustomizer
customizer
=
this
.
factory
.
createContextCustomizer
(
WithAnnotationEnabledFalse
.
class
,
null
);
assertThat
(
customizer
).
isNotNull
();
ConfigurableApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
customizer
.
customizeContext
(
context
,
null
);
String
property
=
context
.
getEnvironment
().
getProperty
(
ConfigurationPropertiesScan
.
CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
);
assertThat
(
property
).
isEqualTo
(
"false"
);
}
@Test
public
void
hashCodeAndEquals
()
{
ContextCustomizer
customizer1
=
this
.
factory
.
createContextCustomizer
(
WithAnnotationEnabledFalse
.
class
,
null
);
ContextCustomizer
customizer2
=
this
.
factory
.
createContextCustomizer
(
WithSameAnnotation
.
class
,
null
);
assertThat
(
customizer1
.
hashCode
()).
isEqualTo
(
customizer2
.
hashCode
());
assertThat
(
customizer1
).
isEqualTo
(
customizer1
).
isEqualTo
(
customizer2
);
}
static
class
NoAnnotation
{
}
@OverrideConfigurationPropertiesScan
(
enabled
=
true
)
static
class
WithAnnotationEnabledTrue
{
}
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
static
class
WithAnnotationEnabledFalse
{
}
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
static
class
WithSameAnnotation
{
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/DataJdbcTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
jdbc
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataJdbcTest @DataJdbcTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@DataJdbcTest
public
class
DataJdbcTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/jdbc/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
jdbc
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataJdbcTest @DataJdbcTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
ldap
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataLdapTest @DataLdapTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@DataLdapTest
public
class
DataLdapTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
ldap
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataLdapTest @DataLdapTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
mongo
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataMongoTest @DataMongoTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@DataMongoTest
public
class
DataMongoTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
mongo
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataMongoTest @DataMongoTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
neo4j
;
import
org.junit.jupiter.api.Test
;
import
org.testcontainers.containers.Neo4jContainer
;
import
org.testcontainers.junit.jupiter.Container
;
import
org.testcontainers.junit.jupiter.Testcontainers
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.util.TestPropertyValues
;
import
org.springframework.boot.testsupport.testcontainers.SkippableContainer
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.test.context.ContextConfiguration
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataNeo4jTest @DataNeo4jTest}.
*
* @author Madhura Bhave
*/
@ContextConfiguration
(
initializers
=
DataNeo4jTestConfigurationPropertiesScanDisabledTests
.
Initializer
.
class
)
@Testcontainers
@DataNeo4jTest
public
class
DataNeo4jTestConfigurationPropertiesScanDisabledTests
{
@Container
public
static
SkippableContainer
<
Neo4jContainer
<?>>
neo4j
=
new
SkippableContainer
<>(
()
->
new
Neo4jContainer
<>().
withAdminPassword
(
null
));
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
static
class
Initializer
implements
ApplicationContextInitializer
<
ConfigurableApplicationContext
>
{
@Override
public
void
initialize
(
ConfigurableApplicationContext
configurableApplicationContext
)
{
TestPropertyValues
.
of
(
"spring.data.neo4j.uri="
+
neo4j
.
getContainer
().
getBoltUrl
())
.
applyTo
(
configurableApplicationContext
.
getEnvironment
());
}
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
neo4j
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataNeo4jTest @DataNeo4jTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
redis
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataRedisTest @DataRedisTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@DataRedisTest
public
class
DataRedisTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
data
.
redis
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataRedisTest @DataRedisTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link JdbcTest @JdbcTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link JdbcTest @JdbcTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@JdbcTest
public
class
JdbcTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
jooq
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link JooqTest @JooqTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
jooq
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link JooqTest @JooqTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@JooqTest
public
class
JooqTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
json
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.json.app.ExampleJsonApplication
;
import
org.springframework.boot.test.autoconfigure.json.app.ExampleProperties
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link JsonTest @JsonTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@JsonTest
@ContextConfiguration
(
classes
=
ExampleJsonApplication
.
class
)
public
class
JsonTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/app/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
json
.
app
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.test.autoconfigure.json.JsonTest
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link JsonTest @JsonTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
orm
.
jpa
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link DataJpaTest @DataJpaTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@DataJpaTest
public
class
DataJpaTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
orm
.
jpa
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link DataJpaTest @DataJpaTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/override/ExampleTestProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
override
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleTestProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/override/scan/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
override
.
scan
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/override/scan/OverrideConfigurationPropertiesScanApplication.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
override
.
scan
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan
;
/**
* Example {@link SpringBootApplication @SpringBootApplication} for use with
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} tests.
*
* @author Madhura Bhave
*/
@SpringBootApplication
public
class
OverrideConfigurationPropertiesScanApplication
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/override/scan/OverrideConfigurationPropertiesScanEnabledFalseIntegrationTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
override
.
scan
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.autoconfigure.override.ExampleTestProperties
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.test.context.BootstrapWith
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Integration tests for
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} when
* {@code enabled} is {@code false}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@BootstrapWith
(
SpringBootTestContextBootstrapper
.
class
)
@OverrideConfigurationPropertiesScan
(
enabled
=
false
)
@Import
(
OverrideConfigurationPropertiesScanEnabledFalseIntegrationTests
.
TestConfiguration
.
class
)
public
class
OverrideConfigurationPropertiesScanEnabledFalseIntegrationTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
disabledConfigurationPropertiesScan
()
{
ApplicationContext
context
=
this
.
context
;
assertThat
(
context
.
getBean
(
ExampleTestProperties
.
class
)).
isNotNull
();
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
context
.
getBean
(
ExampleProperties
.
class
));
}
@Configuration
@EnableConfigurationProperties
(
ExampleTestProperties
.
class
)
static
class
TestConfiguration
{
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/override/scan/OverrideConfigurationPropertiesScanEnabledTrueIntegrationTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
override
.
scan
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.OverrideConfigurationPropertiesScan
;
import
org.springframework.boot.test.context.SpringBootTestContextBootstrapper
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.BootstrapWith
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for
* {@link OverrideConfigurationPropertiesScan @OverrideConfigurationPropertiesScan} when
* {@code enabled} is {@code true}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@OverrideConfigurationPropertiesScan
(
enabled
=
true
)
@BootstrapWith
(
SpringBootTestContextBootstrapper
.
class
)
public
class
OverrideConfigurationPropertiesScanEnabledTrueIntegrationTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationPropertiesScanEnabled
()
{
assertThat
(
this
.
context
.
getBean
(
ExampleProperties
.
class
)).
isNotNull
();
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
web
.
client
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link RestClientTest @RestClientTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
web
.
client
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link RestClientTest @RestClientTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@RestClientTest
public
class
RestClientTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
web
.
reactive
.
webclient
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link WebFluxTest @WebFluxTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/webclient/WebFluxTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
web
.
reactive
.
webclient
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link WebFluxTest @WebFluxTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@WebFluxTest
public
class
WebFluxTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/ExampleProperties.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
web
.
servlet
.
mockmvc
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
/**
* Example {@link ConfigurationProperties @ConfigurationProperties} for use with
* {@link WebMvcTest @WebMvcTest} tests.
*
* @author Madhura Bhave
*/
@ConfigurationProperties
(
prefix
=
"example"
)
public
class
ExampleProperties
{
}
spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/mockmvc/WebMvcTestConfigurationPropertiesScanDisabledTests.java
0 → 100644
View file @
3b4ff7d7
/*
* Copyright 2012-2019 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
*
* https://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
.
web
.
servlet
.
mockmvc
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
/**
* Tests to ensure that configuration properties scanning is disabled for
* {@link WebMvcTest @WebMvcTest}.
*
* @author Madhura Bhave
*/
@RunWith
(
SpringRunner
.
class
)
@WebMvcTest
public
class
WebMvcTestConfigurationPropertiesScanDisabledTests
{
@Autowired
private
ApplicationContext
context
;
@Test
public
void
configurationProperiesScanDisabled
()
{
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
context
.
getBean
(
ExampleProperties
.
class
));
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesScan.java
View file @
3b4ff7d7
...
...
@@ -40,6 +40,11 @@ import org.springframework.core.annotation.AliasFor;
@Import
(
ConfigurationPropertiesScanRegistrar
.
class
)
public
@interface
ConfigurationPropertiesScan
{
/**
* Whether configuration properties should be automatically scanned.
*/
String
CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
=
"spring.boot.configurationpropertiesscan.enabled"
;
/**
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
* declarations e.g.: {@code @ConfigurationPropertiesScan("org.my.pkg")} instead of
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrar.java
View file @
3b4ff7d7
...
...
@@ -53,8 +53,17 @@ class ConfigurationPropertiesScanRegistrar
@Override
public
void
registerBeanDefinitions
(
AnnotationMetadata
importingClassMetadata
,
BeanDefinitionRegistry
registry
)
{
Set
<
String
>
packagesToScan
=
getPackagesToScan
(
importingClassMetadata
);
register
(
registry
,
(
ConfigurableListableBeanFactory
)
registry
,
packagesToScan
);
if
(
isEnabled
())
{
Set
<
String
>
packagesToScan
=
getPackagesToScan
(
importingClassMetadata
);
register
(
registry
,
(
ConfigurableListableBeanFactory
)
registry
,
packagesToScan
);
}
}
protected
boolean
isEnabled
()
{
return
this
.
environment
.
getProperty
(
ConfigurationPropertiesScan
.
CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
,
Boolean
.
class
,
true
);
}
private
Set
<
String
>
getPackagesToScan
(
AnnotationMetadata
metadata
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesScanRegistrarTests.java
View file @
3b4ff7d7
...
...
@@ -20,6 +20,7 @@ import java.io.IOException;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.beans.factory.support.GenericBeanDefinition
;
...
...
@@ -44,9 +45,25 @@ public class ConfigurationPropertiesScanRegistrarTests {
private
final
DefaultListableBeanFactory
beanFactory
=
new
DefaultListableBeanFactory
();
private
MockEnvironment
environment
;
@Before
public
void
setup
()
{
this
.
registrar
.
setEnvironment
(
new
MockEnvironment
());
this
.
environment
=
new
MockEnvironment
();
this
.
registrar
.
setEnvironment
(
this
.
environment
);
}
@Test
public
void
scanningDisabled
()
throws
IOException
{
this
.
environment
.
setProperty
(
ConfigurationPropertiesScan
.
CONFIGURATION_PROPERTIES_SCAN_ENABLED_PROPERTY
,
"false"
);
this
.
registrar
.
registerBeanDefinitions
(
getAnnotationMetadata
(
ConfigurationPropertiesScanConfiguration
.
class
),
this
.
beanFactory
);
assertThatExceptionOfType
(
NoSuchBeanDefinitionException
.
class
)
.
isThrownBy
(()
->
this
.
beanFactory
.
getBeanDefinition
(
"bing-org.springframework.boot.context.properties.scan.valid.ConfigurationPropertiesScanConfiguration$BingProperties"
));
}
@Test
...
...
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