public abstract class TestPropertySourceUtils extends Object
@TestPropertySource
and adding test PropertySources
to the Environment
.
Primarily intended for use within the framework.
TestPropertySource
Modifier and Type | Field and Description |
---|---|
static String |
INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
The name of the
MapPropertySource created from inlined properties. |
Constructor and Description |
---|
TestPropertySourceUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context,
String... inlinedProperties)
Add the given inlined properties to the
Environment of the
supplied context . |
static void |
addInlinedPropertiesToEnvironment(ConfigurableEnvironment environment,
String... inlinedProperties)
Add the given inlined properties (in the form of key-value
pairs) to the supplied
environment . |
static void |
addPropertiesFilesToEnvironment(ConfigurableApplicationContext context,
String... locations)
Add the
Properties files from the given resource locations
to the Environment of the supplied context . |
static Map<String,Object> |
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.
|
public static final String INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
MapPropertySource
created from inlined properties.public static void addPropertiesFilesToEnvironment(ConfigurableApplicationContext context, String... locations)
Properties
files from the given resource locations
to the Environment
of the supplied context
.
Property placeholders in resource locations (i.e., ${...}
)
will be resolved
against the Environment
.
Each properties file will be converted to a ResourcePropertySource
that will be added to the PropertySources
of the environment with
highest precedence.
context
- the application context whose environment should be updated;
never null
locations
- the resource locations of Properties
files to add
to the environment; potentially empty but never null
IllegalStateException
- if an error occurs while processing a properties fileResourcePropertySource
,
TestPropertySource.locations()
public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties)
Environment
of the
supplied context
.
This method simply delegates to
addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
.
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
TestPropertySource.properties()
,
addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment environment, String... inlinedProperties)
environment
.
All key-value pairs will be added to the Environment
as a
single MapPropertySource
with the highest precedence.
For details on the parsing of inlined properties, consult the
Javadoc for convertInlinedPropertiesToMap(java.lang.String...)
.
environment
- the environment to update; never null
inlinedProperties
- the inlined properties to add to the environment;
potentially empty but never null
MapPropertySource
,
INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
,
TestPropertySource.properties()
,
convertInlinedPropertiesToMap(java.lang.String...)
public static Map<String,Object> convertInlinedPropertiesToMap(String... inlinedProperties)
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()
.
inlinedProperties
- the inlined properties to convert; potentially empty
but never null
IllegalStateException
- if a given key-value pair cannot be parsed, or if
a given inlined property contains multiple key-value pairsaddInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])