From a37eaf75c4a2a219bc6ddf9b7c4781bef4166aed Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 28 Jul 2019 12:35:57 +0200 Subject: [PATCH] Verify meta @TestPropertySource overrides meta-meta declaration This commit introduces tests which verify that properties configured via @TestPropertySource used as a meta-annotation override those configured via @TestPropertySource used as a meta-meta-annotation. See gh-23320 --- ...edPropertyAndMetaInlinedPropertyTests.java | 2 +- ...opertyAndMetaMetaInlinedPropertyTests.java | 41 +++++++++++++++++ ...ertyOverridesMetaInlinedPropertyTests.java | 4 +- .../repeatable/MetaComposedTestProperty.java | 45 +++++++++++++++++++ ...OverridesMetaMetaInlinedPropertyTests.java | 39 ++++++++++++++++ .../repeatable/MetaInlinedTestProperty.java | 2 +- 6 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaComposedTestProperty.java create mode 100644 spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java index cc2de58efaf..5badcc2bb06 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java @@ -35,7 +35,7 @@ public class LocalInlinedPropertyAndMetaInlinedPropertyTests extends AbstractRep @Test public void test() { assertEnvironmentValue("key1", "local"); - assertEnvironmentValue("meta", "inlined"); + assertEnvironmentValue("enigma", "meta"); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java new file mode 100644 index 00000000000..1f02a961d59 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaMetaInlinedPropertyTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.env.repeatable; + +import org.junit.Test; + +import org.springframework.test.context.TestPropertySource; + +/** + * Integration tests for {@link TestPropertySource @TestPropertySource} as a + * repeatable annotation. + * + * @author Anatoliy Korovin + * @author Sam Brannen + * @since 5.2 + */ +@TestPropertySource(properties = "key1 = local") +@MetaComposedTestProperty +public class LocalInlinedPropertyAndMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { + + @Test + public void test() { + assertEnvironmentValue("key1", "local"); + assertEnvironmentValue("enigma", "meta meta"); + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java index 55c0eec441d..b3d1a79e71d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java @@ -28,13 +28,13 @@ import org.springframework.test.context.TestPropertySource; * @author Sam Brannen * @since 5.2 */ -@TestPropertySource(properties = "meta = local override") +@TestPropertySource(properties = "enigma = local override") @MetaInlinedTestProperty public class LocalInlinedPropertyOverridesMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { @Test public void test() { - assertEnvironmentValue("meta", "local override"); + assertEnvironmentValue("enigma", "local override"); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaComposedTestProperty.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaComposedTestProperty.java new file mode 100644 index 00000000000..e4be7f6df17 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaComposedTestProperty.java @@ -0,0 +1,45 @@ +/* + * Copyright 2002-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.env.repeatable; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.env.repeatable.MetaComposedTestProperty.MetaMetaInlinedTestProperty; + +/** + * Composed annotation that declares a property via + * {@link TestPropertySource @TestPropertySource} used as a meta-meta-annotation. + * + * @author Sam Brannen + * @since 5.2 + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@MetaMetaInlinedTestProperty +@interface MetaComposedTestProperty { + + @Target(ElementType.TYPE) + @Retention(RetentionPolicy.RUNTIME) + @TestPropertySource(properties = "enigma = meta meta") + @interface MetaMetaInlinedTestProperty { + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java new file mode 100644 index 00000000000..eb307400d15 --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.env.repeatable; + +import org.junit.Test; + +import org.springframework.test.context.TestPropertySource; + +/** + * Integration tests for {@link TestPropertySource @TestPropertySource} as a + * repeatable annotation. + * + * @author Sam Brannen + * @since 5.2 + */ +@MetaInlinedTestProperty +@MetaComposedTestProperty +public class MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests { + + @Test + public void test() { + assertEnvironmentValue("enigma", "meta"); + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedTestProperty.java b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedTestProperty.java index 6e52a36bad0..28812d2ec44 100644 --- a/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedTestProperty.java +++ b/spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedTestProperty.java @@ -32,6 +32,6 @@ import org.springframework.test.context.TestPropertySource; */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -@TestPropertySource(properties = "meta = inlined") +@TestPropertySource(properties = "enigma = meta") @interface MetaInlinedTestProperty { }