Browse Source
Prior to this commit, if multiple, directly present `@TestPropertySource` annotations declared the same property, the precedence ordering was top-down instead of bottom-up, in contrast to the semantics for class hierarchies. In other words, a subsequent `@TestPropertySource` annotation could not override a property in a previous `@TestPropertySource` annotation. This commit overhauls the internals of `TestPropertySourceUtils` in order to provide proper support for property overrides within local, directly present `@TestPropertySource` declarations. Specifically, the `locations` and `properties` attributes from all `@TestPropertySource` declarations that are directly present or meta-present on a given class are now merged into a single instance of `TestPropertySourceAttributes` internally, with assertions in place to ensure that such "same level" `@TestPropertySource` declarations do not configure different values for the `inheritLocations` and `inheritProperties` flags. Effectively, all "same level" `@TestPropertySource` declarations are treated internally as if there were only one such annotation declared by the user. See gh-23320pull/23382/head
36 changed files with 686 additions and 853 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
/* |
||||
* 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; |
||||
|
||||
import org.junit.platform.runner.JUnitPlatform; |
||||
import org.junit.platform.suite.api.IncludeClassNamePatterns; |
||||
import org.junit.platform.suite.api.IncludeEngines; |
||||
import org.junit.platform.suite.api.SelectPackages; |
||||
import org.junit.platform.suite.api.UseTechnicalNames; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.test.context.TestPropertySource; |
||||
|
||||
/** |
||||
* Test suite for tests that involve {@link TestPropertySource @TestPropertySource}. |
||||
* |
||||
* <p>Note that tests included in this suite will be executed at least twice if |
||||
* run from an automated build process, test runner, etc. that is not configured |
||||
* to exclude tests based on a {@code "*TestSuite.class"} pattern match. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(JUnitPlatform.class) |
||||
@IncludeEngines("junit-vintage") |
||||
@SelectPackages("org.springframework.test.context.env") |
||||
@IncludeClassNamePatterns(".*Tests$") |
||||
@UseTechnicalNames |
||||
public class TestPropertySourceTestSuite { |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
/* |
||||
* 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 |
||||
@TestPropertySource("local.properties") |
||||
public class DefaultPropertiesFileDetectionRepeatedTestPropertySourceTests |
||||
extends AbstractRepeatableTestPropertySourceTests { |
||||
|
||||
@Test |
||||
public void test() { |
||||
assertEnvironmentValue("default.value", "default file"); |
||||
assertEnvironmentValue("key1", "local file"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,45 @@
@@ -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 org.junit.Test; |
||||
|
||||
import org.springframework.test.context.TestPropertySource; |
||||
|
||||
/** |
||||
* Integration tests for {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* <p>Same as {@link ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests}, |
||||
* but with the order of the properties files reversed. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @author Sam Brannen |
||||
* @since 5.2 |
||||
*/ |
||||
@TestPropertySource("first.properties") |
||||
@TestPropertySource("second.properties") |
||||
public class ExplicitPropertiesFilesRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { |
||||
|
||||
@Test |
||||
public void test() { |
||||
assertEnvironmentValue("alpha", "omega"); |
||||
assertEnvironmentValue("first", "1111"); |
||||
assertEnvironmentValue("second", "2222"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
/* |
||||
* 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.junit.Test; |
||||
|
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.env.repeatable.LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests.Key1InlinedTestProperty; |
||||
|
||||
/** |
||||
* Integration tests for {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @author Sam Brannen |
||||
* @since 5.2 |
||||
*/ |
||||
@TestPropertySource(properties = "key1 = local") |
||||
@Key1InlinedTestProperty |
||||
public class LocalInlinedPropertyOverridesInheritedAndMetaInlinedPropertiesTests extends AbstractClassWithTestProperty { |
||||
|
||||
@Test |
||||
public void test() { |
||||
assertEnvironmentValue("key1", "local"); |
||||
} |
||||
|
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@TestPropertySource(properties = "key1 = meta") |
||||
@interface Key1InlinedTestProperty { |
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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 value") |
||||
@TestPropertySource(properties = "second = local override") |
||||
public class LocalInlinedPropertyOverridesInheritedInlinedPropertyTests extends RepeatedTestPropertySourceTests { |
||||
|
||||
@Test |
||||
@Override |
||||
public void test() { |
||||
assertEnvironmentValue("key1", "local value"); |
||||
assertEnvironmentValue("second", "local override"); |
||||
assertEnvironmentValue("first", "repeated override"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
/* |
||||
* 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.junit.Test; |
||||
|
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.env.repeatable.LocalPropertiesFileAndMetaPropertiesFileTests.MetaFileTestProperty; |
||||
|
||||
/** |
||||
* Integration tests for {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* <p>Verify a property value is defined both in the properties file which is declared |
||||
* via {@link MetaFileTestProperty @MetaFileTestProperty} and in the properties file |
||||
* which is declared locally via {@code @TestPropertySource}. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @author Sam Brannen |
||||
* @since 5.2 |
||||
*/ |
||||
@TestPropertySource("local.properties") |
||||
@MetaFileTestProperty |
||||
public class LocalPropertiesFileAndMetaPropertiesFileTests extends AbstractRepeatableTestPropertySourceTests { |
||||
|
||||
@Test |
||||
public void test() { |
||||
assertEnvironmentValue("key1", "local file"); |
||||
assertEnvironmentValue("key2", "meta file"); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Composed annotation that declares a properties file via |
||||
* {@link TestPropertySource @TestPropertySource}. |
||||
*/ |
||||
@Target(ElementType.TYPE) |
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@TestPropertySource("meta.properties") |
||||
@interface MetaFileTestProperty { |
||||
} |
||||
|
||||
} |
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
/* |
||||
* 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.springframework.test.context.TestPropertySource; |
||||
|
||||
|
||||
/** |
||||
* Base class which declare a property by the {@link TestPropertySource} annotation. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@TestPropertySource(properties = "inherited = 12345") |
||||
public abstract class ParentClassWithTestProperties { |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* 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. |
||||
* |
||||
* <p>Tests multiple local {@link TestPropertySource} declarations. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 5.2 |
||||
*/ |
||||
@TestPropertySource(properties = "first = repeated") |
||||
@TestPropertySource(properties = "second = repeated") |
||||
@TestPropertySource(properties = "first = repeated override") |
||||
public class RepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { |
||||
|
||||
@Test |
||||
public void test() { |
||||
assertEnvironmentValue("first", "repeated override"); |
||||
assertEnvironmentValue("second", "repeated"); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,41 @@
@@ -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; |
||||
|
||||
/** |
||||
* Same as {@link ExplicitPropertiesFilesRepeatedTestPropertySourceTests}, but |
||||
* with the order of the properties files reversed. |
||||
* |
||||
* @author Sam Brannen |
||||
* @since 5.2 |
||||
*/ |
||||
@TestPropertySource("second.properties") |
||||
@TestPropertySource("first.properties") |
||||
public class ReversedExplicitPropertiesFilesRepeatedTestPropertySourceTests extends AbstractRepeatableTestPropertySourceTests { |
||||
|
||||
@Test |
||||
public void test() { |
||||
assertEnvironmentValue("alpha", "beta"); |
||||
assertEnvironmentValue("first", "1111"); |
||||
assertEnvironmentValue("second", "1111"); |
||||
} |
||||
|
||||
} |
@ -1,71 +0,0 @@
@@ -1,71 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Test a property definition by the using of {@link TestPropertySource} both in the |
||||
* parent class and locally. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource(properties = "key = 051187") |
||||
public class TestPropertySourceInheritTests extends ParentClassWithTestProperties { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${key}") |
||||
String key; |
||||
|
||||
@Value("${inherited}") |
||||
String inherited; |
||||
|
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertThat(env.getProperty("key")).isEqualTo("051187"); |
||||
assertThat(this.key).isEqualTo("051187"); |
||||
|
||||
assertThat(env.getProperty("inherited")).isEqualTo("12345"); |
||||
assertThat(inherited).isEqualTo("12345"); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,67 +0,0 @@
@@ -1,67 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* This test verifies an overriding of the property value which declared in the |
||||
* meta-annotation by the {@link TestPropertySource} when this property is also defined |
||||
* locally in {@link TestPropertySource}. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource(properties = "meta = local value") |
||||
@AnnotationWithTestProperty |
||||
public class TestPropertySourceInheritedFromMetaAnnotationOverridesLocallyTests { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${meta}") |
||||
String meta; |
||||
|
||||
|
||||
@Test |
||||
public void inlineLocalPropertyAndPropertyFromMetaAnnotation() { |
||||
assertThat(env.getProperty("meta")).isEqualTo("local value"); |
||||
assertThat(meta).isEqualTo("local value"); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* This test verifies a declaration of properties by the {@link TestPropertySource} both |
||||
* locally and in the custom meta-annotation. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource(properties = "key = 051187") |
||||
@AnnotationWithTestProperty |
||||
public class TestPropertySourceInheritedFromMetaAnnotationTests { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${key}") |
||||
String key; |
||||
|
||||
@Value("${meta}") |
||||
String meta; |
||||
|
||||
|
||||
@Test |
||||
public void inlineLocalPropertyAndPropertyFromMetaAnnotation() { |
||||
// local inlined:
|
||||
assertThat(env.getProperty("key")).isEqualTo("051187"); |
||||
assertThat(this.key).isEqualTo("051187"); |
||||
// inlined from meta-annotation:
|
||||
assertThat(env.getProperty("meta")).isEqualTo("value from meta-annotation"); |
||||
assertThat(meta).isEqualTo("value from meta-annotation"); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,76 +0,0 @@
@@ -1,76 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Verify a property value defined both in the properties file which declared in the |
||||
* custom annotation {@link AnnotationWithTestPropertyInPropertiesFile} and a definition |
||||
* of property by the local usage of {@link TestPropertySource} with a properties file |
||||
* name. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource("local.properties") |
||||
@AnnotationWithTestPropertyInPropertiesFile |
||||
public class TestPropertySourceInheritedFromMetaAnnotationWithPropertiesFileTests { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${key}") |
||||
String key; |
||||
|
||||
@Value("${meta}") |
||||
String meta; |
||||
|
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertPropertyValue("key", key, "local value"); |
||||
assertPropertyValue("meta", meta, "a value from file in the meta-annotation"); |
||||
} |
||||
|
||||
private void assertPropertyValue(String name, String value, String expectedValue) { |
||||
assertThat(env.getProperty(name)).isEqualTo(expectedValue); |
||||
assertThat(value).isEqualTo(expectedValue); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Verify the overriding of property which defined both in the parent class and locally in |
||||
* the {@link TestPropertySource} annotation. Also, verify that the value of not |
||||
* conflicted properties is applied from the parent class. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource(properties = "second = local value") |
||||
public class TestPropertySourcePartialOverridesInheritedPropertyTests extends ParentClassWithMultipleTestProperties { |
||||
|
||||
@Value("${first}") |
||||
String first; |
||||
|
||||
@Value("${second}") |
||||
String second; |
||||
|
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertThat(first).isEqualTo("value from parent class"); |
||||
assertThat(second).isEqualTo("local value"); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,58 +0,0 @@
@@ -1,58 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Verify an overriding of a property value which defined both in custom annotation |
||||
* and in the parent class, when this property declares locally by the |
||||
* {@link TestPropertySource}. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@FooTestProperty |
||||
@TestPropertySource(properties = "foo = local value") |
||||
public class TestPropertySourceRepeatableOverridesTests extends FooTestPropertyDeclaration { |
||||
|
||||
@Value("${foo}") |
||||
String foo; |
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertThat(foo).isEqualTo("local value"); |
||||
} |
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Test multiple test property declarations by the using of {@link TestPropertySource} as |
||||
* a repeatable annotation. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource(properties = "first = 1111") |
||||
@TestPropertySource(properties = "second = 2222") |
||||
public class TestPropertySourceRepeatableTests { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${first}") |
||||
String first; |
||||
|
||||
@Value("${second}") |
||||
String second; |
||||
|
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertPropertyValue("first", first, "1111"); |
||||
assertPropertyValue("second", second, "2222"); |
||||
} |
||||
|
||||
private void assertPropertyValue(String name, String value, String expectedValue) { |
||||
assertThat(env.getProperty(name)).isEqualTo(expectedValue); |
||||
assertThat(value).isEqualTo(expectedValue); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Verify a repeatable usage of {@link TestPropertySource} both with a default value of |
||||
* properties file and with a specified properties file name in the |
||||
* {@link TestPropertySource} annotation. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource |
||||
@TestPropertySource("local.properties") |
||||
public class TestPropertySourceRepeatableWithDefaultPropertiesFileTests { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${key}") |
||||
String key; |
||||
|
||||
@Value("${default.value}") |
||||
String defaultValue; |
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertPropertyValue("key", key, "local value"); |
||||
assertPropertyValue("default.value", defaultValue, "a value from default properties file"); |
||||
} |
||||
|
||||
private void assertPropertyValue(String name, String value, String expectedValue) { |
||||
assertThat(env.getProperty(name)).isEqualTo(expectedValue); |
||||
assertThat(value).isEqualTo(expectedValue); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -1,73 +0,0 @@
@@ -1,73 +0,0 @@
|
||||
/* |
||||
* 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.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.beans.factory.annotation.Value; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.Environment; |
||||
import org.springframework.test.context.ContextConfiguration; |
||||
import org.springframework.test.context.TestPropertySource; |
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Integration tests for support {@link TestPropertySource @TestPropertySource} as a |
||||
* repeatable annotation. |
||||
* |
||||
* Test multiple test properties file declarations by the using of {@link TestPropertySource} as |
||||
* a repeatable annotation. |
||||
* |
||||
* @author Anatoliy Korovin |
||||
* @since 5.2 |
||||
*/ |
||||
@RunWith(SpringJUnit4ClassRunner.class) |
||||
@ContextConfiguration |
||||
@TestPropertySource("first.properties") |
||||
@TestPropertySource("second.properties") |
||||
public class TestPropertySourceRepeatableWithPropertiesFileTests { |
||||
|
||||
@Autowired |
||||
Environment env; |
||||
|
||||
@Value("${first}") |
||||
String first; |
||||
|
||||
@Value("${second}") |
||||
String second; |
||||
|
||||
|
||||
@Test |
||||
public void inlinePropertyFromParentClassAndFromLocalTestPropertySourceAnnotation() { |
||||
assertPropertyValue("first", first, "1111"); |
||||
assertPropertyValue("second", second, "2222"); |
||||
} |
||||
|
||||
private void assertPropertyValue(String name, String value, String expectedValue) { |
||||
assertThat(env.getProperty(name)).isEqualTo(expectedValue); |
||||
assertThat(value).isEqualTo(expectedValue); |
||||
} |
||||
|
||||
|
||||
@Configuration |
||||
static class Config { |
||||
} |
||||
} |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
default.value = default file |
@ -1 +0,0 @@
@@ -1 +0,0 @@
|
||||
default.value = a value from default properties file |
@ -1 +1,3 @@
@@ -1 +1,3 @@
|
||||
first = 1111 |
||||
alpha = beta |
||||
first = 1111 |
||||
second = 1111 |
||||
|
@ -1 +1 @@
@@ -1 +1 @@
|
||||
key = local value |
||||
key1 = local file |
||||
|
Loading…
Reference in new issue