spring-framework / org.springframework.test.context.support / TestPropertySourceUtils

TestPropertySourceUtils

abstract class TestPropertySourceUtils

Utility methods for working with TestPropertySource and adding test PropertySource to the Environment.

Primarily intended for use within the framework.

Author
Sam Brannen

Since
4.1

See Also
TestPropertySource

Constructors

<init>

TestPropertySourceUtils()

Utility methods for working with TestPropertySource and adding test PropertySource to the Environment.

Primarily intended for use within the framework.

Properties

INLINED_PROPERTIES_PROPERTY_SOURCE_NAME

static val INLINED_PROPERTIES_PROPERTY_SOURCE_NAME: String

The name of the MapPropertySource created from inlined properties.

Functions

addInlinedPropertiesToEnvironment

open static fun addInlinedPropertiesToEnvironment(context: ConfigurableApplicationContext, vararg inlinedProperties: String): Unit

Add the given inlined properties to the Environment of the supplied context.

This method simply delegates to #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[]).

open static fun addInlinedPropertiesToEnvironment(environment: ConfigurableEnvironment, vararg inlinedProperties: String): Unit

Add the given inlined properties (in the form of key-value pairs) to the supplied ConfigurableEnvironment.

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.

addPropertiesFilesToEnvironment

open static fun addPropertiesFilesToEnvironment(context: ConfigurableApplicationContext, vararg locations: String): Unit

Add the Properties files from the given resource locations to the Environment of the supplied context.

This method simply delegates to #addPropertiesFilesToEnvironment(ConfigurableEnvironment, ResourceLoader, String...).

open static fun addPropertiesFilesToEnvironment(environment: ConfigurableEnvironment, resourceLoader: ResourceLoader, vararg locations: String): Unit

Add the Properties files from the given resource locations to the supplied ConfigurableEnvironment.

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.

convertInlinedPropertiesToMap

open static fun convertInlinedPropertiesToMap(vararg inlinedProperties: String): MutableMap<String, Any>

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.

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.