Class TestPropertySourceUtils
@TestPropertySource
 and adding test PropertySources to the Environment.
 Primarily intended for use within the framework.
- Since:
- 4.1
- Author:
- Sam Brannen, Anatoliy Korovin, Phillip Webb
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe name of theMapPropertySourcecreated from inlined properties.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidaddInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties) Add the given inlined properties to theEnvironmentof the suppliedcontext.static voidaddInlinedPropertiesToEnvironment(ConfigurableEnvironment environment, String... inlinedProperties) Add the given inlined properties (in the form of key-value pairs) to the suppliedenvironment.static voidaddPropertiesFilesToEnvironment(ConfigurableApplicationContext context, String... locations) Add thePropertiesfiles from the given resourcelocationsto theEnvironmentof the suppliedcontext.static voidaddPropertiesFilesToEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader, String... locations) convertInlinedPropertiesToMap(String... inlinedProperties) Convert the supplied inlined properties (in the form of key-value pairs) into a map keyed by property name, preserving the ordering of property names in the returned map.
- 
Field Details- 
INLINED_PROPERTIES_PROPERTY_SOURCE_NAMEThe name of theMapPropertySourcecreated from inlined properties.
 
- 
- 
Constructor Details- 
TestPropertySourceUtilspublic TestPropertySourceUtils()
 
- 
- 
Method Details- 
addPropertiesFilesToEnvironmentpublic static void addPropertiesFilesToEnvironment(ConfigurableApplicationContext context, String... locations) Add thePropertiesfiles from the given resourcelocationsto theEnvironmentof the suppliedcontext.This method simply delegates to addPropertiesFilesToEnvironment(ConfigurableEnvironment, ResourceLoader, String...).- Parameters:
- context- the application context whose environment should be updated; never- null
- locations- the resource locations of- Propertiesfiles to add to the environment; potentially empty but never- null
- Throws:
- IllegalStateException- if an error occurs while processing a properties file
- Since:
- 4.1.5
- See Also:
 
- 
addPropertiesFilesToEnvironmentpublic static void addPropertiesFilesToEnvironment(ConfigurableEnvironment environment, 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.- Parameters:
- environment- the environment to update; never- null
- resourceLoader- the- ResourceLoaderto use to load each resource; never- null
- locations- the resource locations of- Propertiesfiles to add to the environment; potentially empty but never- null
- Throws:
- IllegalStateException- if an error occurs while processing a properties file
- Since:
- 4.3
- See Also:
 
- 
addInlinedPropertiesToEnvironmentpublic static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties) Add the given inlined properties to theEnvironmentof the suppliedcontext.This method simply delegates to addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]).- Parameters:
- context- the application context whose environment should be updated; never- null
- inlinedProperties- the inlined properties to add to the environment; potentially empty but never- null
- Since:
- 4.1.5
- See Also:
 
- 
addInlinedPropertiesToEnvironmentpublic static void addInlinedPropertiesToEnvironment(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...).- Parameters:
- environment- the environment to update; never- null
- inlinedProperties- the inlined properties to add to the environment; potentially empty but never- null
- Since:
- 4.1.5
- See Also:
 
- 
convertInlinedPropertiesToMapConvert the supplied inlined properties (in the form of key-value pairs) into a map keyed by property name, preserving the ordering of property names in the returned map.Parsing of the key-value pairs is achieved by converting all pairs into virtual properties files in memory and delegating to Properties.load(java.io.Reader)to parse each virtual file.For a full discussion of inlined properties, consult the Javadoc for TestPropertySource.properties().- Parameters:
- inlinedProperties- the inlined properties to convert; potentially empty but never- null
- Returns:
- a new, ordered map containing the converted properties
- Throws:
- IllegalStateException- if a given key-value pair cannot be parsed, or if a given inlined property contains multiple key-value pairs
- Since:
- 4.1.5
- See Also:
 
 
-