From 0cf1749e8583d42af92d57d9cf9736f8db40b840 Mon Sep 17 00:00:00 2001 From: artsiom Date: Sun, 12 Aug 2018 15:53:05 +0300 Subject: [PATCH 1/2] Allow properties to be configured using slice test annotations See gh-14052 --- .../autoconfigure/data/ldap/DataLdapTest.java | 12 +++- .../ldap/DataLdapTestContextBootstrapper.java | 40 +++++++++++ .../data/mongo/DataMongoTest.java | 12 +++- .../DataMongoTestContextBootstrapper.java | 40 +++++++++++ .../data/neo4j/DataNeo4jTest.java | 12 +++- .../DataNeo4jTestContextBootstrapper.java | 40 +++++++++++ .../data/redis/DataRedisTest.java | 12 +++- .../DataRedisTestContextBootstrapper.java | 40 +++++++++++ .../test/autoconfigure/jdbc/JdbcTest.java | 12 +++- .../jdbc/JdbcTestContextBootstrapper.java | 40 +++++++++++ .../test/autoconfigure/jooq/JooqTest.java | 12 +++- .../jooq/JooqTestContextBootstrapper.java | 40 +++++++++++ .../test/autoconfigure/json/JsonTest.java | 11 ++- .../json/JsonTestContextBootstrapper.java | 40 +++++++++++ .../autoconfigure/orm/jpa/DataJpaTest.java | 12 +++- .../jpa/DataJpaTestContextBootstrapper.java | 40 +++++++++++ .../web/client/RestClientTest.java | 12 +++- .../RestClientTestContextBootstrapper.java | 40 +++++++++++ .../web/reactive/WebFluxTest.java | 9 +++ .../WebFluxTestContextBootstrapper.java | 14 +++- .../autoconfigure/web/servlet/WebMvcTest.java | 9 +++ .../WebMvcTestContextBootstrapper.java | 14 +++- ...ataLdapTestEnvironmentPropertiesTests.java | 46 +++++++++++++ ...taMongoTestEnvironmentPropertiesTests.java | 46 +++++++++++++ ...taNeo4jTestEnvironmentPropertiesTests.java | 69 +++++++++++++++++++ ...taRedisTestEnvironmentPropertiesTests.java | 68 ++++++++++++++++++ .../JdbcTestEnvironmentPropertiesTests.java | 46 +++++++++++++ .../JooqTestEnvironmentPropertiesTests.java | 46 +++++++++++++ .../JsonTestEnvironmentPropertiesTests.java | 46 +++++++++++++ ...DataJpaTestEnvironmentPropertiesTests.java | 46 +++++++++++++ ...tClientTestEnvironmentPropertiesTests.java | 46 +++++++++++++ ...WebFluxTestEnvironmentPropertiesTests.java | 46 +++++++++++++ .../WebMvcTestEnvironmentPropertiesTests.java | 46 +++++++++++++ 33 files changed, 1044 insertions(+), 20 deletions(-) create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java create mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java index 1f1d3d349e..d891d2f3c8 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java @@ -30,9 +30,9 @@ 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.SpringBootTestContextBootstrapper; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -48,13 +48,14 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * LDAP process (if available). * * @author Eddú Meléndez + * @author Artsiom Yudovin * @since 2.0.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(DataLdapTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(DataLdapTypeExcludeFilter.class) @@ -63,6 +64,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ImportAutoConfiguration public @interface DataLdapTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default no beans are diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java new file mode 100644 index 0000000000..dd42e90d47 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.data.ldap; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link DataLdapTest @DataLdapTest} support. + * + * @author Artsiom Yudovin + */ +public class DataLdapTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + DataLdapTest annotation = getDataLdapTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private DataLdapTest getDataLdapTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, DataLdapTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java index 8e2d7603f3..df9033ebbb 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java @@ -30,9 +30,9 @@ 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.SpringBootTestContextBootstrapper; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -49,13 +49,14 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * * @author Michael Simons * @author Stephane Nicoll + * @author Artsiom Yudovin * @since 1.5.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(DataMongoTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(DataMongoTypeExcludeFilter.class) @@ -64,6 +65,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ImportAutoConfiguration public @interface DataMongoTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default no beans are diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java new file mode 100644 index 0000000000..2078a307f6 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.data.mongo; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link DataMongoTest @DataMongoTest} support. + * + * @author Artsiom Yudovin + */ +public class DataMongoTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + DataMongoTest annotation = getDataMongoTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private DataMongoTest getDataMongoTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, DataMongoTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java index c31164d431..1a5cf582d6 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java @@ -30,9 +30,9 @@ 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.SpringBootTestContextBootstrapper; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; @@ -51,13 +51,14 @@ import org.springframework.transaction.annotation.Transactional; * * @author Eddú Meléndez * @author Stephane Nicoll + * @author Artsiom Yudovin * @since 2.0.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(DataNeo4jTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(DataNeo4jTypeExcludeFilter.class) @@ -67,6 +68,13 @@ import org.springframework.transaction.annotation.Transactional; @ImportAutoConfiguration public @interface DataNeo4jTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default no beans are diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java new file mode 100644 index 0000000000..ff6e1bfda6 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.data.neo4j; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link DataNeo4jTest @DataNeo4jTest} support. + * + * @author Artsiom Yudovin + */ +public class DataNeo4jTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + DataNeo4jTest annotation = getDataNeo4jTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private DataNeo4jTest getDataNeo4jTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, DataNeo4jTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java index 2fa21a9010..fe2c06a65b 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java @@ -30,9 +30,9 @@ 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.SpringBootTestContextBootstrapper; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -45,13 +45,14 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * configuration relevant to Redis tests. * * @author Jayaram Pradhan + * @author Artsiom Yudovin * @since 2.0.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(DataRedisTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(DataRedisTypeExcludeFilter.class) @@ -60,6 +61,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ImportAutoConfiguration public @interface DataRedisTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default no beans are diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java new file mode 100644 index 0000000000..9a102ba36c --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.data.redis; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link DataRedisTest @DataRedisTest} support. + * + * @author Artsiom Yudovin + */ +public class DataRedisTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + DataRedisTest annotation = getDataRedisTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private DataRedisTest getDataRedisTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, DataRedisTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java index 39b0747fae..d5d876f0ee 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java @@ -31,9 +31,9 @@ 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.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; @@ -57,6 +57,7 @@ import org.springframework.transaction.annotation.Transactional; * annotation. * * @author Stephane Nicoll + * @author Artsiom Yudovin * @see AutoConfigureJdbc * @see AutoConfigureTestDatabase * @see AutoConfigureCache @@ -65,7 +66,7 @@ import org.springframework.transaction.annotation.Transactional; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(JdbcTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(JdbcTypeExcludeFilter.class) @@ -76,6 +77,13 @@ import org.springframework.transaction.annotation.Transactional; @ImportAutoConfiguration public @interface JdbcTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default no beans are diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java new file mode 100644 index 0000000000..35fbf276e8 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link JdbcTest @JdbcTest} support. + * + * @author Artsiom Yudovin + */ +public class JdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + JdbcTest annotation = getJdbcAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private JdbcTest getJdbcAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, JdbcTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java index 5821db890a..41d6e289e7 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java @@ -30,9 +30,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; @@ -52,13 +52,14 @@ import org.springframework.transaction.annotation.Transactional; * * @author Michael Simons * @author Stephane Nicoll + * @author Artsiom Yudovin * @since 2.0.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(JooqTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(JooqTypeExcludeFilter.class) @@ -67,6 +68,13 @@ import org.springframework.transaction.annotation.Transactional; @ImportAutoConfiguration public @interface JooqTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default no beans are diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java new file mode 100644 index 0000000000..46f1767524 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.jooq; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link JooqTest @JooqTest} support. + * + * @author Artsiom Yudovin + */ +public class JooqTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + JooqTest annotation = getJooqTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private JooqTest getJooqTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, JooqTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java index d1eb9048fb..ebeebc51fb 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java @@ -28,12 +28,12 @@ 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.SpringBootTestContextBootstrapper; import org.springframework.boot.test.json.GsonTester; import org.springframework.boot.test.json.JacksonTester; import org.springframework.boot.test.json.JsonbTester; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; /** @@ -60,7 +60,7 @@ import org.springframework.test.context.BootstrapWith; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(JsonTestContextBootstrapper.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(JsonExcludeFilter.class) @AutoConfigureCache @@ -69,6 +69,13 @@ import org.springframework.test.context.BootstrapWith; @ImportAutoConfiguration public @interface JsonTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Determines if default filtering should be used with * {@link SpringBootApplication @SpringBootApplication}. By default only diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java new file mode 100644 index 0000000000..72f885beb7 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.json; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link JsonTest @JsonTest} support. + * + * @author Artsiom Yudovin + */ +public class JsonTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + JsonTest annotation = getJsonTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private JsonTest getJsonTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, JsonTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java index c3f935f286..f7a24b3797 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java @@ -33,9 +33,9 @@ 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.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; @@ -59,6 +59,7 @@ import org.springframework.transaction.annotation.Transactional; * annotation. * * @author Phillip Webb + * @author Artsiom Yudovin * @see AutoConfigureDataJpa * @see AutoConfigureTestDatabase * @see AutoConfigureTestEntityManager @@ -68,7 +69,7 @@ import org.springframework.transaction.annotation.Transactional; @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(DataJpaTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(DataJpaTypeExcludeFilter.class) @@ -80,6 +81,13 @@ import org.springframework.transaction.annotation.Transactional; @ImportAutoConfiguration public @interface DataJpaTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * If SQL output should be logged. * @return if SQL is logged diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java new file mode 100644 index 0000000000..49727fc87d --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.orm.jpa; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link DataJpaTest @DataJpaTest} support. + * + * @author Artsiom Yudovin + */ +public class DataJpaTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + DataJpaTest annotation = getDataJpaAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private DataJpaTest getDataJpaAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, DataJpaTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java index 853b44fc4b..2d21bb4e72 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java @@ -30,10 +30,10 @@ 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.SpringBootTestContextBootstrapper; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -60,13 +60,14 @@ import org.springframework.web.client.RestTemplate; * * @author Stephane Nicoll * @author Phillip Webb + * @author Artsiom Yudovin * @since 1.4.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@BootstrapWith(SpringBootTestContextBootstrapper.class) +@BootstrapWith(RestClientTestContextBootstrapper.class) @ExtendWith(SpringExtension.class) @OverrideAutoConfiguration(enabled = false) @TypeExcludeFilters(RestClientExcludeFilter.class) @@ -76,6 +77,13 @@ import org.springframework.web.client.RestTemplate; @ImportAutoConfiguration public @interface RestClientTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Specifies the components to test. This is an alias of {@link #components()} which * can be used for brevity if no other attributes are defined. See diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java new file mode 100644 index 0000000000..f9c55c5f9b --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java @@ -0,0 +1,40 @@ +/* + * Copyright 2012-2017 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.web.client; + +import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; +import org.springframework.test.context.TestContextBootstrapper; + +/** + * {@link TestContextBootstrapper} for {@link RestClientTest @RestClientTest} support. + * + * @author Artsiom Yudovin + */ +public class RestClientTestContextBootstrapper extends SpringBootTestContextBootstrapper { + + @Override + protected String[] getProperties(Class testClass) { + RestClientTest annotation = getRestClientAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private RestClientTest getRestClientAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, RestClientTest.class); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java index bcc1be8a6b..d339b2cdc1 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java @@ -35,6 +35,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Import; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.reactive.server.WebTestClient; @@ -64,6 +65,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; * annotation. * * @author Stephane Nicoll + * @author Artsiom Yudovin * @since 2.0.0 * @see AutoConfigureWebFlux * @see AutoConfigureWebTestClient @@ -82,6 +84,13 @@ import org.springframework.test.web.reactive.server.WebTestClient; @ImportAutoConfiguration public @interface WebFluxTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Specifies the controllers to test. This is an alias of {@link #controllers()} which * can be used for brevity if no other attributes are defined. See diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java index 95f44f5877..e423c0b77e 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java @@ -18,6 +18,7 @@ package org.springframework.boot.test.autoconfigure.web.reactive; import org.springframework.boot.test.context.ReactiveWebMergedContextConfiguration; import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestContextBootstrapper; @@ -25,8 +26,9 @@ import org.springframework.test.context.TestContextBootstrapper; * {@link TestContextBootstrapper} for {@link WebFluxTest @WebFluxTest} support. * * @author Stephane Nicoll + * @author Artsiom Yudovin */ -class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper { +public class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected MergedContextConfiguration processMergedContextConfiguration( @@ -35,4 +37,14 @@ class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper { super.processMergedContextConfiguration(mergedConfig)); } + @Override + protected String[] getProperties(Class testClass) { + WebFluxTest annotation = getWebFluxTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private WebFluxTest getWebFluxTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, WebFluxTest.class); + } + } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java index f00702adc6..dcca84531a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java @@ -35,6 +35,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Import; import org.springframework.core.annotation.AliasFor; +import org.springframework.core.env.Environment; import org.springframework.test.context.BootstrapWith; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; @@ -65,6 +66,7 @@ import org.springframework.test.web.servlet.MockMvc; * {@link AutoConfigureMockMvc @AutoConfigureMockMvc} rather than this annotation. * * @author Phillip Webb + * @author Artsiom Yudovin * @see AutoConfigureWebMvc * @see AutoConfigureMockMvc * @see AutoConfigureCache @@ -84,6 +86,13 @@ import org.springframework.test.web.servlet.MockMvc; @ImportAutoConfiguration public @interface WebMvcTest { + /** + * Properties in form {@literal key=value} that should be added to the Spring + * {@link Environment} before the test runs. + * @return the properties to add + */ + String[] properties() default {}; + /** * Specifies the controllers to test. This is an alias of {@link #controllers()} which * can be used for brevity if no other attributes are defined. See diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java index cac57002a6..6ca7e383b8 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java @@ -17,6 +17,7 @@ package org.springframework.boot.test.autoconfigure.web.servlet; import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestContextBootstrapper; import org.springframework.test.context.web.WebMergedContextConfiguration; @@ -25,8 +26,9 @@ import org.springframework.test.context.web.WebMergedContextConfiguration; * {@link TestContextBootstrapper} for {@link WebMvcTest @WebMvcTest} support. * * @author Phillip Webb + * @author Artsiom Yudovin */ -class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper { +public class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected MergedContextConfiguration processMergedContextConfiguration( @@ -35,4 +37,14 @@ class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper { super.processMergedContextConfiguration(mergedConfig), ""); } + @Override + protected String[] getProperties(Class testClass) { + WebMvcTest annotation = getWebMvcTestAnnotation(testClass); + return (annotation != null) ? annotation.properties() : null; + } + + private WebMvcTest getWebMvcTestAnnotation(Class testClass) { + return AnnotatedElementUtils.getMergedAnnotation(testClass, WebMvcTest.class); + } + } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..cef246846e --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.data.ldap; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link DataLdapTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@DataLdapTest(properties = "spring.profiles.active=test") +public class DataLdapTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..59814b6ff7 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.data.mongo; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link DataMongoTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@DataMongoTest(properties = "spring.profiles.active=test") +public class DataMongoTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..1a7130e49b --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java @@ -0,0 +1,69 @@ +/* + * Copyright 2012-2017 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.data.neo4j; + +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.testcontainers.Neo4jContainer; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link DataNeo4jTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = DataNeo4jTestEnvironmentPropertiesTests.Initializer.class) +@DataNeo4jTest(properties = "spring.profiles.active=test") +public class DataNeo4jTestEnvironmentPropertiesTests { + + @ClassRule + public static Neo4jContainer neo4j = new Neo4jContainer(); + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + + static class Initializer + implements ApplicationContextInitializer { + + @Override + public void initialize( + ConfigurableApplicationContext configurableApplicationContext) { + TestPropertyValues + .of("spring.data.neo4j.uri=bolt://localhost:" + neo4j.getMappedPort()) + .applyTo(configurableApplicationContext.getEnvironment()); + } + + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..e06d837bdb --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2017 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.data.redis; + +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.testcontainers.RedisContainer; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link DataRedisTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(initializers = DataRedisTestEnvironmentPropertiesTests.Initializer.class) +@DataRedisTest(properties = "spring.profiles.active=test") +public class DataRedisTestEnvironmentPropertiesTests { + + @ClassRule + public static RedisContainer redis = new RedisContainer(); + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + + static class Initializer + implements ApplicationContextInitializer { + + @Override + public void initialize( + ConfigurableApplicationContext configurableApplicationContext) { + TestPropertyValues.of("spring.redis.port=" + redis.getMappedPort()) + .applyTo(configurableApplicationContext.getEnvironment()); + } + + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..98546a9de0 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link JdbcTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@JdbcTest(properties = "spring.profiles.active=test") +public class JdbcTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..8fca87a662 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.jooq; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link JooqTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@JooqTest(properties = "spring.profiles.active=test") +public class JooqTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..42426e01d9 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.json; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link JsonTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@JsonTest(properties = "spring.profiles.active=test") +public class JsonTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..12e6dcb2c4 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.orm.jpa; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link DataJpaTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@DataJpaTest(properties = "spring.profiles.active=test") +public class DataJpaTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..b839e61cfe --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.web.client; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link RestClientTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@RestClientTest(properties = "spring.profiles.active=test") +public class RestClientTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..7cb4133ace --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.web.reactive; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link WebFluxTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@WebFluxTest(properties = "spring.profiles.active=test") +public class WebFluxTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java new file mode 100644 index 0000000000..136b178e26 --- /dev/null +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 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.web.servlet; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Add properties to {@link Environment} via {@link WebMvcTest}. + * + * @author Artsiom Yudovin + */ +@RunWith(SpringRunner.class) +@WebMvcTest(properties = "spring.profiles.active=test") +public class WebMvcTestEnvironmentPropertiesTests { + + @Autowired + private Environment environment; + + @Test + public void environmentWitNewProfile() { + String profile = this.environment.getActiveProfiles()[0]; + assertThat(profile).isEqualTo("test"); + } + +} From 075a745e32af7d2928289cac16dadacca0a9b41a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 16 Aug 2018 11:27:09 +0100 Subject: [PATCH 2/2] Polish "Allow properties to be configured using slice test annotations" Closes gh-14052 --- .../src/main/asciidoc/spring-boot-features.adoc | 6 ++++-- .../test/autoconfigure/data/ldap/DataLdapTest.java | 1 + .../data/ldap/DataLdapTestContextBootstrapper.java | 11 ++++------- .../test/autoconfigure/data/mongo/DataMongoTest.java | 1 + .../data/mongo/DataMongoTestContextBootstrapper.java | 11 ++++------- .../test/autoconfigure/data/neo4j/DataNeo4jTest.java | 1 + .../data/neo4j/DataNeo4jTestContextBootstrapper.java | 11 ++++------- .../test/autoconfigure/data/redis/DataRedisTest.java | 1 + .../data/redis/DataRedisTestContextBootstrapper.java | 11 ++++------- .../boot/test/autoconfigure/jdbc/JdbcTest.java | 1 + .../jdbc/JdbcTestContextBootstrapper.java | 11 ++++------- .../boot/test/autoconfigure/jooq/JooqTest.java | 1 + .../jooq/JooqTestContextBootstrapper.java | 11 ++++------- .../boot/test/autoconfigure/json/JsonTest.java | 4 +++- .../json/JsonTestContextBootstrapper.java | 11 ++++------- .../boot/test/autoconfigure/orm/jpa/DataJpaTest.java | 1 + .../orm/jpa/DataJpaTestContextBootstrapper.java | 11 ++++------- .../test/autoconfigure/web/client/RestClientTest.java | 1 + .../web/client/RestClientTestContextBootstrapper.java | 11 ++++------- .../test/autoconfigure/web/reactive/WebFluxTest.java | 1 + .../web/reactive/WebFluxTestContextBootstrapper.java | 11 ++++------- .../test/autoconfigure/web/servlet/WebMvcTest.java | 1 + .../web/servlet/WebMvcTestContextBootstrapper.java | 11 ++++------- ...va => DataLdapTestPropertiesIntegrationTests.java} | 7 ++++--- ...a => DataMongoTestPropertiesIntegrationTests.java} | 7 ++++--- ...a => DataNeo4jTestPropertiesIntegrationTests.java} | 9 +++++---- ...a => DataRedisTestPropertiesIntegrationTests.java} | 9 +++++---- ...s.java => JdbcTestPropertiesIntegrationTests.java} | 7 ++++--- ...s.java => JooqTestPropertiesIntegrationTests.java} | 7 ++++--- ...s.java => JsonTestPropertiesIntegrationTests.java} | 7 ++++--- ...ava => DataJpaTestPropertiesIntegrationTests.java} | 7 ++++--- ... => RestClientTestPropertiesIntegrationTests.java} | 7 ++++--- ...ava => WebFluxTestPropertiesIntegrationTests.java} | 7 ++++--- ...java => WebMvcTestPropertiesIntegrationTests.java} | 7 ++++--- 34 files changed, 107 insertions(+), 115 deletions(-) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/{DataLdapTestEnvironmentPropertiesTests.java => DataLdapTestPropertiesIntegrationTests.java} (84%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/{DataMongoTestEnvironmentPropertiesTests.java => DataMongoTestPropertiesIntegrationTests.java} (84%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/{DataNeo4jTestEnvironmentPropertiesTests.java => DataNeo4jTestPropertiesIntegrationTests.java} (86%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/{DataRedisTestEnvironmentPropertiesTests.java => DataRedisTestPropertiesIntegrationTests.java} (86%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/{JdbcTestEnvironmentPropertiesTests.java => JdbcTestPropertiesIntegrationTests.java} (85%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/{JooqTestEnvironmentPropertiesTests.java => JooqTestPropertiesIntegrationTests.java} (85%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/{JsonTestEnvironmentPropertiesTests.java => JsonTestPropertiesIntegrationTests.java} (85%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/{DataJpaTestEnvironmentPropertiesTests.java => DataJpaTestPropertiesIntegrationTests.java} (85%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/{RestClientTestEnvironmentPropertiesTests.java => RestClientTestPropertiesIntegrationTests.java} (84%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/{WebFluxTestEnvironmentPropertiesTests.java => WebFluxTestPropertiesIntegrationTests.java} (85%) rename spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/{WebMvcTestEnvironmentPropertiesTests.java => WebMvcTestPropertiesIntegrationTests.java} (85%) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 3788b7230b..0fbe182686 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -403,8 +403,10 @@ sensible overriding of values. Properties are considered in the following order: on your home directory (`~/.spring-boot-devtools.properties` when devtools is active). . {spring-javadoc}/test/context/TestPropertySource.{dc-ext}[`@TestPropertySource`] annotations on your tests. -. {dc-spring-boot-test}/context/SpringBootTest.{dc-ext}[`@SpringBootTest#properties`] -annotation attribute on your tests. +. `properties` attribute on your tests. Available on +{dc-spring-boot-test}/context/SpringBootTest.{dc-ext}[`@SpringBootTest`] and the +<>. . Command line arguments. . Properties from `SPRING_APPLICATION_JSON` (inline JSON embedded in an environment variable or system property). diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java index d891d2f3c8..97fc119581 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTest.java @@ -68,6 +68,7 @@ public @interface DataLdapTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java index dd42e90d47..f73a8648ba 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class DataLdapTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class DataLdapTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - DataLdapTest annotation = getDataLdapTestAnnotation(testClass); + DataLdapTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + DataLdapTest.class); return (annotation != null) ? annotation.properties() : null; } - private DataLdapTest getDataLdapTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, DataLdapTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java index df9033ebbb..ac56ab7845 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTest.java @@ -69,6 +69,7 @@ public @interface DataMongoTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java index 2078a307f6..f926cee182 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class DataMongoTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class DataMongoTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - DataMongoTest annotation = getDataMongoTestAnnotation(testClass); + DataMongoTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + DataMongoTest.class); return (annotation != null) ? annotation.properties() : null; } - private DataMongoTest getDataMongoTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, DataMongoTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java index 1a5cf582d6..953ce18eff 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTest.java @@ -72,6 +72,7 @@ public @interface DataNeo4jTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java index ff6e1bfda6..658f523e4b 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class DataNeo4jTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class DataNeo4jTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - DataNeo4jTest annotation = getDataNeo4jTestAnnotation(testClass); + DataNeo4jTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + DataNeo4jTest.class); return (annotation != null) ? annotation.properties() : null; } - private DataNeo4jTest getDataNeo4jTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, DataNeo4jTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java index fe2c06a65b..5f940ca15b 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTest.java @@ -65,6 +65,7 @@ public @interface DataRedisTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java index 9a102ba36c..fdf6d80083 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class DataRedisTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class DataRedisTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - DataRedisTest annotation = getDataRedisTestAnnotation(testClass); + DataRedisTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + DataRedisTest.class); return (annotation != null) ? annotation.properties() : null; } - private DataRedisTest getDataRedisTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, DataRedisTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java index d5d876f0ee..5ad15c0ffa 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTest.java @@ -81,6 +81,7 @@ public @interface JdbcTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java index 35fbf276e8..d51cec257d 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class JdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class JdbcTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - JdbcTest annotation = getJdbcAnnotation(testClass); + JdbcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + JdbcTest.class); return (annotation != null) ? annotation.properties() : null; } - private JdbcTest getJdbcAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, JdbcTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java index 41d6e289e7..9eec1a00e2 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTest.java @@ -72,6 +72,7 @@ public @interface JooqTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java index 46f1767524..b35b5c4af6 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class JooqTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class JooqTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - JooqTest annotation = getJooqTestAnnotation(testClass); + JooqTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + JooqTest.class); return (annotation != null) ? annotation.properties() : null; } - private JooqTest getJooqTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, JooqTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java index ebeebc51fb..d66e1a542a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -51,6 +51,7 @@ import org.springframework.test.context.BootstrapWith; * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters} annotation. * * @author Phillip Webb + * @author Artsiom Yudovin * @see AutoConfigureJson * @see AutoConfigureJsonTesters * @see AutoConfigureCache @@ -73,6 +74,7 @@ public @interface JsonTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java index 72f885beb7..d2bffb667e 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class JsonTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class JsonTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - JsonTest annotation = getJsonTestAnnotation(testClass); + JsonTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + JsonTest.class); return (annotation != null) ? annotation.properties() : null; } - private JsonTest getJsonTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, JsonTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java index f7a24b3797..9255b0bb60 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTest.java @@ -85,6 +85,7 @@ public @interface DataJpaTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java index 49727fc87d..c49ca01c9f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class DataJpaTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class DataJpaTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - DataJpaTest annotation = getDataJpaAnnotation(testClass); + DataJpaTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + DataJpaTest.class); return (annotation != null) ? annotation.properties() : null; } - private DataJpaTest getDataJpaAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, DataJpaTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java index 2d21bb4e72..9d27fb3398 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTest.java @@ -81,6 +81,7 @@ public @interface RestClientTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java index f9c55c5f9b..4679afa6d7 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -25,16 +25,13 @@ import org.springframework.test.context.TestContextBootstrapper; * * @author Artsiom Yudovin */ -public class RestClientTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class RestClientTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected String[] getProperties(Class testClass) { - RestClientTest annotation = getRestClientAnnotation(testClass); + RestClientTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + RestClientTest.class); return (annotation != null) ? annotation.properties() : null; } - private RestClientTest getRestClientAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, RestClientTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java index d339b2cdc1..3d403cfa7f 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTest.java @@ -88,6 +88,7 @@ public @interface WebFluxTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java index e423c0b77e..6ee1e41fcb 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -28,7 +28,7 @@ import org.springframework.test.context.TestContextBootstrapper; * @author Stephane Nicoll * @author Artsiom Yudovin */ -public class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected MergedContextConfiguration processMergedContextConfiguration( @@ -39,12 +39,9 @@ public class WebFluxTestContextBootstrapper extends SpringBootTestContextBootstr @Override protected String[] getProperties(Class testClass) { - WebFluxTest annotation = getWebFluxTestAnnotation(testClass); + WebFluxTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + WebFluxTest.class); return (annotation != null) ? annotation.properties() : null; } - private WebFluxTest getWebFluxTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, WebFluxTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java index dcca84531a..49550a6c53 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTest.java @@ -90,6 +90,7 @@ public @interface WebMvcTest { * Properties in form {@literal key=value} that should be added to the Spring * {@link Environment} before the test runs. * @return the properties to add + * @since 2.1.0 */ String[] properties() default {}; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java index 6ca7e383b8..ed8cde0e7a 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestContextBootstrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -28,7 +28,7 @@ import org.springframework.test.context.web.WebMergedContextConfiguration; * @author Phillip Webb * @author Artsiom Yudovin */ -public class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper { +class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstrapper { @Override protected MergedContextConfiguration processMergedContextConfiguration( @@ -39,12 +39,9 @@ public class WebMvcTestContextBootstrapper extends SpringBootTestContextBootstra @Override protected String[] getProperties(Class testClass) { - WebMvcTest annotation = getWebMvcTestAnnotation(testClass); + WebMvcTest annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, + WebMvcTest.class); return (annotation != null) ? annotation.properties() : null; } - private WebMvcTest getWebMvcTestAnnotation(Class testClass) { - return AnnotatedElementUtils.getMergedAnnotation(testClass, WebMvcTest.class); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestPropertiesIntegrationTests.java similarity index 84% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestPropertiesIntegrationTests.java index cef246846e..3eaa4334d1 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/ldap/DataLdapTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link DataLdapTest}. + * Tests for the {@link DataLdapTest#properties properties} attribute of + * {@link DataLdapTest @DataLdapTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @DataLdapTest(properties = "spring.profiles.active=test") -public class DataLdapTestEnvironmentPropertiesTests { +public class DataLdapTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestPropertiesIntegrationTests.java similarity index 84% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestPropertiesIntegrationTests.java index 59814b6ff7..78016e0323 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/mongo/DataMongoTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link DataMongoTest}. + * Tests for the {@link DataMongoTest#properties properties} attribute of + * {@link DataMongoTest @DataMongoTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @DataMongoTest(properties = "spring.profiles.active=test") -public class DataMongoTestEnvironmentPropertiesTests { +public class DataMongoTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java similarity index 86% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java index 1a7130e49b..592bc8500e 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/neo4j/DataNeo4jTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -32,14 +32,15 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link DataNeo4jTest}. + * Tests for the {@link DataNeo4jTest#properties properties} attribute of + * {@link DataNeo4jTest @DataNeo4jTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = DataNeo4jTestEnvironmentPropertiesTests.Initializer.class) +@ContextConfiguration(initializers = DataNeo4jTestPropertiesIntegrationTests.Initializer.class) @DataNeo4jTest(properties = "spring.profiles.active=test") -public class DataNeo4jTestEnvironmentPropertiesTests { +public class DataNeo4jTestPropertiesIntegrationTests { @ClassRule public static Neo4jContainer neo4j = new Neo4jContainer(); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java similarity index 86% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java index e06d837bdb..e6520c6fd2 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/data/redis/DataRedisTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -32,14 +32,15 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link DataRedisTest}. + * Tests for the {@link DataRedisTest#properties properties} attribute of + * {@link DataRedisTest @DataRedisTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) -@ContextConfiguration(initializers = DataRedisTestEnvironmentPropertiesTests.Initializer.class) +@ContextConfiguration(initializers = DataRedisTestPropertiesIntegrationTests.Initializer.class) @DataRedisTest(properties = "spring.profiles.active=test") -public class DataRedisTestEnvironmentPropertiesTests { +public class DataRedisTestPropertiesIntegrationTests { @ClassRule public static RedisContainer redis = new RedisContainer(); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestPropertiesIntegrationTests.java similarity index 85% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestPropertiesIntegrationTests.java index 98546a9de0..0b1b9cea09 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jdbc/JdbcTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link JdbcTest}. + * Tests for the {@link JdbcTest#properties properties} attribute of + * {@link JdbcTest @JdbcTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @JdbcTest(properties = "spring.profiles.active=test") -public class JdbcTestEnvironmentPropertiesTests { +public class JdbcTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestPropertiesIntegrationTests.java similarity index 85% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestPropertiesIntegrationTests.java index 8fca87a662..ef2174d7b3 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/jooq/JooqTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link JooqTest}. + * Tests for the {@link JooqTest#properties properties} attribute of + * {@link JooqTest @JooqTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @JooqTest(properties = "spring.profiles.active=test") -public class JooqTestEnvironmentPropertiesTests { +public class JooqTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestPropertiesIntegrationTests.java similarity index 85% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestPropertiesIntegrationTests.java index 42426e01d9..a991712458 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link JsonTest}. + * Tests for the {@link JsonTest#properties properties} attribute of + * {@link JsonTest @JsonTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @JsonTest(properties = "spring.profiles.active=test") -public class JsonTestEnvironmentPropertiesTests { +public class JsonTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestPropertiesIntegrationTests.java similarity index 85% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestPropertiesIntegrationTests.java index 12e6dcb2c4..622eccabe5 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/orm/jpa/DataJpaTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link DataJpaTest}. + * Tests for the {@link DataJpaTest#properties properties} attribute of + * {@link DataJpaTest @DataJpaTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @DataJpaTest(properties = "spring.profiles.active=test") -public class DataJpaTestEnvironmentPropertiesTests { +public class DataJpaTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestPropertiesIntegrationTests.java similarity index 84% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestPropertiesIntegrationTests.java index b839e61cfe..6f27c25489 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link RestClientTest}. + * Tests for the {@link RestClientTest#properties properties} attribute of + * {@link RestClientTest @RestClientTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @RestClientTest(properties = "spring.profiles.active=test") -public class RestClientTestEnvironmentPropertiesTests { +public class RestClientTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestPropertiesIntegrationTests.java similarity index 85% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestPropertiesIntegrationTests.java index 7cb4133ace..420ea0db86 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link WebFluxTest}. + * Tests for the {@link WebFluxTest#properties properties} attribute of + * {@link WebFluxTest @WebFluxTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @WebFluxTest(properties = "spring.profiles.active=test") -public class WebFluxTestEnvironmentPropertiesTests { +public class WebFluxTestPropertiesIntegrationTests { @Autowired private Environment environment; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestPropertiesIntegrationTests.java similarity index 85% rename from spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java rename to spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestPropertiesIntegrationTests.java index 136b178e26..67cbbb6ce4 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestEnvironmentPropertiesTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestPropertiesIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -26,13 +26,14 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.Assertions.assertThat; /** - * Add properties to {@link Environment} via {@link WebMvcTest}. + * Tests for the {@link WebMvcTest#properties properties} attribute of + * {@link WebMvcTest @WebMvcTest}. * * @author Artsiom Yudovin */ @RunWith(SpringRunner.class) @WebMvcTest(properties = "spring.profiles.active=test") -public class WebMvcTestEnvironmentPropertiesTests { +public class WebMvcTestPropertiesIntegrationTests { @Autowired private Environment environment;