|
| 1 | +/* |
| 2 | + * Copyright 2012-2024 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.boot.test.context; |
| 18 | + |
| 19 | +import java.lang.annotation.Documented; |
| 20 | +import java.lang.annotation.ElementType; |
| 21 | +import java.lang.annotation.Inherited; |
| 22 | +import java.lang.annotation.Repeatable; |
| 23 | +import java.lang.annotation.Retention; |
| 24 | +import java.lang.annotation.RetentionPolicy; |
| 25 | +import java.lang.annotation.Target; |
| 26 | + |
| 27 | +import org.springframework.core.annotation.AliasFor; |
| 28 | +import org.springframework.test.context.TestPropertySource; |
| 29 | + |
| 30 | +/** |
| 31 | + * {@code @TestYamlPropertySource} is an annotation that can be applied to a test class to |
| 32 | + * configure the locations of YAML files and inlined properties to be added to the |
| 33 | + * Environment's set of PropertySources for an ApplicationContext for integration tests. |
| 34 | + * <p> |
| 35 | + * Provides a convenient alternative for |
| 36 | + * {@code @TestPropertySource(locations = "...", factory = YamlPropertySourceFactory.class)}. |
| 37 | + * <p> |
| 38 | + * {@code @TestYamlPropertySource} should be considered as {@code @TestPropertySource} but |
| 39 | + * for YAML files. It intentionally does not support multi-document YAML files to maintain |
| 40 | + * consistency with the behavior of {@code @TestPropertySource}. |
| 41 | + * |
| 42 | + * @author Dmytro Nosan |
| 43 | + * @since 3.5.0 |
| 44 | + * @see YamlPropertySourceFactory |
| 45 | + * @see TestPropertySource |
| 46 | + */ |
| 47 | +@Target(ElementType.TYPE) |
| 48 | +@Retention(RetentionPolicy.RUNTIME) |
| 49 | +@Documented |
| 50 | +@Inherited |
| 51 | +@TestPropertySource(factory = YamlPropertySourceFactory.class) |
| 52 | +@Repeatable(TestYamlPropertySources.class) |
| 53 | +public @interface TestYamlPropertySource { |
| 54 | + |
| 55 | + /** |
| 56 | + * Alias for {@link TestPropertySource#value()}. |
| 57 | + * @return The resource locations of YAML files. |
| 58 | + * @see TestPropertySource#value() for more details. |
| 59 | + */ |
| 60 | + @AliasFor(attribute = "value", annotation = TestPropertySource.class) |
| 61 | + String[] value() default {}; |
| 62 | + |
| 63 | + /** |
| 64 | + * Alias for {@link TestPropertySource#locations()}. |
| 65 | + * @return The resource locations of YAML files. |
| 66 | + * @see TestPropertySource#locations() for more details. |
| 67 | + */ |
| 68 | + @AliasFor(attribute = "locations", annotation = TestPropertySource.class) |
| 69 | + String[] locations() default {}; |
| 70 | + |
| 71 | + /** |
| 72 | + * Alias for {@link TestPropertySource#inheritLocations()}. |
| 73 | + * @return Whether test property source {@link #locations} from superclasses and |
| 74 | + * enclosing classes should be <em>inherited</em>. |
| 75 | + * @see TestPropertySource#inheritLocations() for more details. |
| 76 | + */ |
| 77 | + @AliasFor(attribute = "inheritLocations", annotation = TestPropertySource.class) |
| 78 | + boolean inheritLocations() default true; |
| 79 | + |
| 80 | + /** |
| 81 | + * Alias for {@link TestPropertySource#properties()}. |
| 82 | + * @return <em>Inlined properties</em> in the form of <em>key-value</em> pairs that |
| 83 | + * should be added to the Environment |
| 84 | + * @see TestPropertySource#properties() for more details. |
| 85 | + */ |
| 86 | + @AliasFor(attribute = "properties", annotation = TestPropertySource.class) |
| 87 | + String[] properties() default {}; |
| 88 | + |
| 89 | + /** |
| 90 | + * Alias for {@link TestPropertySource#inheritProperties()}. |
| 91 | + * @return Whether inlined test {@link #properties} from superclasses and enclosing |
| 92 | + * classes should be <em>inherited</em>. |
| 93 | + * @see TestPropertySource#inheritProperties() for more details. |
| 94 | + */ |
| 95 | + @AliasFor(attribute = "inheritProperties", annotation = TestPropertySource.class) |
| 96 | + boolean inheritProperties() default true; |
| 97 | + |
| 98 | +} |
0 commit comments