类 TestPropertySourceUtils
@TestPropertySource
and adding test PropertySources to the Environment.
Primarily intended for use within the framework.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Anatoliy Korovin, Phillip Webb, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static classExtension ofPropertiesthat mimics aSequencedMapby tracking all added properties with aStringkey in aLinkedHashMap. -
字段概要
字段修饰符和类型字段说明private static final cn.taketoday.core.io.PropertySourceFactorystatic final StringThe name of theMapPropertySourcecreated from inlined properties.private static final cn.taketoday.logging.Loggerprivate static Comparator<cn.taketoday.core.annotation.MergedAnnotation<? extends Annotation>> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static voidaddInlinedPropertiesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext context, String... inlinedProperties) Add the given inlined properties to theEnvironmentof the suppliedcontext.static voidaddInlinedPropertiesToEnvironment(cn.taketoday.core.env.ConfigurableEnvironment environment, String... inlinedProperties) Add the given inlined properties (in the form of key-value pairs) to the suppliedenvironment.static voidaddPropertiesFilesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext context, String... locations) Add thePropertiesfiles from the given resourcelocationsto theEnvironmentof the suppliedcontext.static voidaddPropertiesFilesToEnvironment(cn.taketoday.core.env.ConfigurableEnvironment environment, cn.taketoday.core.io.ResourceLoader resourceLoader, String... locations) static voidaddPropertySourcesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext context, List<cn.taketoday.core.io.PropertySourceDescriptor> descriptors) Add property sources for the givendescriptorsto theEnvironmentof the suppliedcontext.static voidaddPropertySourcesToEnvironment(cn.taketoday.core.env.ConfigurableEnvironment environment, cn.taketoday.core.io.ResourceLoader resourceLoader, List<cn.taketoday.core.io.PropertySourceDescriptor> descriptors) Add property sources for the givendescriptorsto the suppliedenvironment.(专用程序包) static MergedTestPropertySourcesbuildMergedTestPropertySources(Class<?> testClass) convertInlinedPropertiesToMap(String... inlinedProperties) Convert the supplied inlined properties (in the form of key-value pairs) into a map keyed by property name.private static booleanduplicationDetected(TestPropertySourceAttributes currentAttributes, TestPropertySourceAttributes previousAttributes) private static <T extends Annotation>
List<List<cn.taketoday.core.annotation.MergedAnnotation<T>>>findRepeatableAnnotations(Class<?> clazz, Class<T> annotationType) private static <T extends Annotation>
voidfindRepeatableAnnotations(Class<?> clazz, Class<T> annotationType, List<List<cn.taketoday.core.annotation.MergedAnnotation<T>>> listOfLists, int[] aggregateIndex) private static List<cn.taketoday.core.io.PropertySourceDescriptor>mergeLocations(List<TestPropertySourceAttributes> attributesList) private static String[]mergeProperties(List<TestPropertySourceAttributes> attributesList) private static TestPropertySourceAttributesmergeTestPropertySourceAttributes(List<TestPropertySourceAttributes> aggregatedAttributesList)
-
字段详细资料
-
INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
The name of theMapPropertySourcecreated from inlined properties. -
defaultPropertySourceFactory
private static final cn.taketoday.core.io.PropertySourceFactory defaultPropertySourceFactory -
reversedMetaDistance
private static Comparator<cn.taketoday.core.annotation.MergedAnnotation<? extends Annotation>> reversedMetaDistance -
logger
private static final cn.taketoday.logging.Logger logger
-
-
构造器详细资料
-
TestPropertySourceUtils
public TestPropertySourceUtils()
-
-
方法详细资料
-
buildMergedTestPropertySources
-
mergeTestPropertySourceAttributes
@Nullable private static TestPropertySourceAttributes mergeTestPropertySourceAttributes(List<TestPropertySourceAttributes> aggregatedAttributesList) -
duplicationDetected
private static boolean duplicationDetected(TestPropertySourceAttributes currentAttributes, @Nullable TestPropertySourceAttributes previousAttributes) -
mergeLocations
private static List<cn.taketoday.core.io.PropertySourceDescriptor> mergeLocations(List<TestPropertySourceAttributes> attributesList) -
mergeProperties
-
addPropertiesFilesToEnvironment
public static void addPropertiesFilesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext context, String... locations) Add thePropertiesfiles from the given resourcelocationsto theEnvironmentof the suppliedcontext.This method simply delegates to
addPropertiesFilesToEnvironment(ConfigurableEnvironment, ResourceLoader, String...).- 参数:
context- the application context whose environment should be updated; nevernulllocations- the resource locations ofPropertiesfiles to add to the environment; potentially empty but nevernull- 抛出:
IllegalStateException- if an error occurs while processing a properties file- 另请参阅:
-
addPropertiesFilesToEnvironment
public static void addPropertiesFilesToEnvironment(cn.taketoday.core.env.ConfigurableEnvironment environment, cn.taketoday.core.io.ResourceLoader resourceLoader, String... locations) Add thePropertiesfiles from the given resourcelocationsto the suppliedenvironment.Property placeholders in resource locations (i.e.,
${...}) will be resolved against theEnvironment.Each properties file will be converted to a
ResourcePropertySourcethat will be added to thePropertySourcesof the environment with the highest precedence.- 参数:
environment- the environment to update; nevernullresourceLoader- theResourceLoaderto use to load each resource; nevernulllocations- the resource locations ofPropertiesfiles to add to the environment; potentially empty but nevernull- 抛出:
IllegalStateException- if an error occurs while processing a properties file- 另请参阅:
-
addPropertySourcesToEnvironment
public static void addPropertySourcesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext context, List<cn.taketoday.core.io.PropertySourceDescriptor> descriptors) Add property sources for the givendescriptorsto theEnvironmentof the suppliedcontext.This method delegates to
addPropertySourcesToEnvironment(ConfigurableEnvironment, ResourceLoader, List).- 参数:
context- the application context whose environment should be updated; nevernulldescriptors- the property source descriptors to process; potentially empty but nevernull- 抛出:
IllegalStateException- if an error occurs while processing the descriptors and registering property sources- 另请参阅:
-
addPropertySourcesToEnvironment
public static void addPropertySourcesToEnvironment(cn.taketoday.core.env.ConfigurableEnvironment environment, cn.taketoday.core.io.ResourceLoader resourceLoader, List<cn.taketoday.core.io.PropertySourceDescriptor> descriptors) Add property sources for the givendescriptorsto the suppliedenvironment.Property placeholders in resource locations (i.e.,
${...}) will be resolved against theEnvironment.A
PatternResourceLoaderwill be used to resolve resource location patterns into multiple resource locations.Each
PropertySourcewill be created via the configuredPropertySourceFactory(or theDefaultPropertySourceFactoryif no factory is configured) and added to thePropertySourcesof the environment with the highest precedence.- 参数:
environment- the environment to update; nevernullresourceLoader- theResourceLoaderto use to load resources; nevernulldescriptors- the property source descriptors to process; potentially empty but nevernull- 抛出:
IllegalStateException- if an error occurs while processing the descriptors and registering property sources- 另请参阅:
-
TestPropertySource.locations()TestPropertySource.encoding()TestPropertySource.factory()PropertySourceFactory
-
addInlinedPropertiesToEnvironment
public static void addInlinedPropertiesToEnvironment(cn.taketoday.context.ConfigurableApplicationContext context, String... inlinedProperties) Add the given inlined properties to theEnvironmentof the suppliedcontext.This method simply delegates to
addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]).- 参数:
context- the application context whose environment should be updated; nevernullinlinedProperties- the inlined properties to add to the environment; potentially empty but nevernull- 另请参阅:
-
addInlinedPropertiesToEnvironment
public static void addInlinedPropertiesToEnvironment(cn.taketoday.core.env.ConfigurableEnvironment environment, String... inlinedProperties) Add the given inlined properties (in the form of key-value pairs) to the suppliedenvironment.All key-value pairs will be added to the
Environmentas a singleMapPropertySourcewith the highest precedence.For details on the parsing of inlined properties, consult the Javadoc for
convertInlinedPropertiesToMap(java.lang.String...).- 参数:
environment- the environment to update; nevernullinlinedProperties- the inlined properties to add to the environment; potentially empty but nevernull- 另请参阅:
-
convertInlinedPropertiesToMap
Convert the supplied inlined properties (in the form of key-value pairs) into a map keyed by property name.Parsing of the key-value pairs is achieved by converting all supplied strings into virtual properties files in memory and delegating to
Properties.load(java.io.Reader)to parse each virtual file.The ordering of property names will be preserved in the returned map, analogous to the order in which the key-value pairs are supplied to this method. This also applies if a single string contains multiple key-value pairs separated by newlines — for example, when supplied by a user via a text block.
For a full discussion of inlined properties, consult the Javadoc for
TestPropertySource.properties().- 参数:
inlinedProperties- the inlined properties to convert; potentially empty but nevernull- 返回:
- a new, ordered map containing the converted properties
- 抛出:
IllegalStateException- if a given key-value pair cannot be parsed- 另请参阅:
-
findRepeatableAnnotations
private static <T extends Annotation> List<List<cn.taketoday.core.annotation.MergedAnnotation<T>>> findRepeatableAnnotations(Class<?> clazz, Class<T> annotationType) -
findRepeatableAnnotations
private static <T extends Annotation> void findRepeatableAnnotations(Class<?> clazz, Class<T> annotationType, List<List<cn.taketoday.core.annotation.MergedAnnotation<T>>> listOfLists, int[] aggregateIndex)
-