Skip to content

Commit a37eaf7

Browse files
committed
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
1 parent 1954861 commit a37eaf7

6 files changed

+129
-4
lines changed

spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyAndMetaInlinedPropertyTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class LocalInlinedPropertyAndMetaInlinedPropertyTests extends AbstractRep
3535
@Test
3636
public void test() {
3737
assertEnvironmentValue("key1", "local");
38-
assertEnvironmentValue("meta", "inlined");
38+
assertEnvironmentValue("enigma", "meta");
3939
}
4040

4141
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2002-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.test.context.env.repeatable;
18+
19+
import org.junit.Test;
20+
21+
import org.springframework.test.context.TestPropertySource;
22+
23+
/**
24+
* Integration tests for {@link TestPropertySource @TestPropertySource} as a
25+
* repeatable annotation.
26+
*
27+
* @author Anatoliy Korovin
28+
* @author Sam Brannen
29+
* @since 5.2
30+
*/
31+
@TestPropertySource(properties = "key1 = local")
32+
@MetaComposedTestProperty
33+
public class LocalInlinedPropertyAndMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests {
34+
35+
@Test
36+
public void test() {
37+
assertEnvironmentValue("key1", "local");
38+
assertEnvironmentValue("enigma", "meta meta");
39+
}
40+
41+
}

spring-test/src/test/java/org/springframework/test/context/env/repeatable/LocalInlinedPropertyOverridesMetaInlinedPropertyTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
* @author Sam Brannen
2929
* @since 5.2
3030
*/
31-
@TestPropertySource(properties = "meta = local override")
31+
@TestPropertySource(properties = "enigma = local override")
3232
@MetaInlinedTestProperty
3333
public class LocalInlinedPropertyOverridesMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests {
3434

3535
@Test
3636
public void test() {
37-
assertEnvironmentValue("meta", "local override");
37+
assertEnvironmentValue("enigma", "local override");
3838
}
3939

4040
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2002-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.test.context.env.repeatable;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
import org.springframework.test.context.TestPropertySource;
25+
import org.springframework.test.context.env.repeatable.MetaComposedTestProperty.MetaMetaInlinedTestProperty;
26+
27+
/**
28+
* Composed annotation that declares a property via
29+
* {@link TestPropertySource @TestPropertySource} used as a meta-meta-annotation.
30+
*
31+
* @author Sam Brannen
32+
* @since 5.2
33+
*/
34+
@Target(ElementType.TYPE)
35+
@Retention(RetentionPolicy.RUNTIME)
36+
@MetaMetaInlinedTestProperty
37+
@interface MetaComposedTestProperty {
38+
39+
@Target(ElementType.TYPE)
40+
@Retention(RetentionPolicy.RUNTIME)
41+
@TestPropertySource(properties = "enigma = meta meta")
42+
@interface MetaMetaInlinedTestProperty {
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2002-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.test.context.env.repeatable;
18+
19+
import org.junit.Test;
20+
21+
import org.springframework.test.context.TestPropertySource;
22+
23+
/**
24+
* Integration tests for {@link TestPropertySource @TestPropertySource} as a
25+
* repeatable annotation.
26+
*
27+
* @author Sam Brannen
28+
* @since 5.2
29+
*/
30+
@MetaInlinedTestProperty
31+
@MetaComposedTestProperty
32+
public class MetaInlinedPropertyOverridesMetaMetaInlinedPropertyTests extends AbstractRepeatableTestPropertySourceTests {
33+
34+
@Test
35+
public void test() {
36+
assertEnvironmentValue("enigma", "meta");
37+
}
38+
39+
}

spring-test/src/test/java/org/springframework/test/context/env/repeatable/MetaInlinedTestProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
*/
3333
@Target(ElementType.TYPE)
3434
@Retention(RetentionPolicy.RUNTIME)
35-
@TestPropertySource(properties = "meta = inlined")
35+
@TestPropertySource(properties = "enigma = meta")
3636
@interface MetaInlinedTestProperty {
3737
}

0 commit comments

Comments
 (0)