use of org.springframework.boot.context.config.ConfigData.PropertySourceOptions in project spring-boot by spring-projects.
the class StandardConfigDataLoader method load.
@Override
public ConfigData load(ConfigDataLoaderContext context, StandardConfigDataResource resource) throws IOException, ConfigDataNotFoundException {
if (resource.isEmptyDirectory()) {
return ConfigData.EMPTY;
}
ConfigDataResourceNotFoundException.throwIfDoesNotExist(resource, resource.getResource());
StandardConfigDataReference reference = resource.getReference();
Resource originTrackedResource = OriginTrackedResource.of(resource.getResource(), Origin.from(reference.getConfigDataLocation()));
String name = String.format("Config resource '%s' via location '%s'", resource, reference.getConfigDataLocation());
List<PropertySource<?>> propertySources = reference.getPropertySourceLoader().load(name, originTrackedResource);
PropertySourceOptions options = (resource.getProfile() != null) ? PROFILE_SPECIFIC : NON_PROFILE_SPECIFIC;
return new ConfigData(propertySources, options);
}
use of org.springframework.boot.context.config.ConfigData.PropertySourceOptions in project spring-boot by spring-projects.
the class ConfigDataTests method getOptionsReturnsOptionsFromPropertySourceOptions.
@Test
void getOptionsReturnsOptionsFromPropertySourceOptions() {
MapPropertySource source1 = new MapPropertySource("test", Collections.emptyMap());
MapPropertySource source2 = new MapPropertySource("test", Collections.emptyMap());
Options options1 = Options.of(Option.IGNORE_IMPORTS);
Options options2 = Options.of(Option.IGNORE_PROFILES);
PropertySourceOptions propertySourceOptions = (source) -> (source != source1) ? options2 : options1;
ConfigData configData = new ConfigData(Arrays.asList(source1, source2), propertySourceOptions);
assertThat(configData.getOptions(source1)).isEqualTo(options1);
assertThat(configData.getOptions(source2)).isEqualTo(options2);
}
use of org.springframework.boot.context.config.ConfigData.PropertySourceOptions in project spring-boot by spring-projects.
the class ConfigDataTests method getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone.
@Test
void getOptionsWhenPropertySourceOptionsReturnsNullReturnsNone() {
MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
PropertySourceOptions propertySourceOptions = (propertySource) -> null;
ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
assertThat(configData.getOptions(source)).isEqualTo(Options.NONE);
}
use of org.springframework.boot.context.config.ConfigData.PropertySourceOptions in project spring-boot by spring-projects.
the class ConfigDataTests method propertySourceOptionsAlwaysReturnsSameOptionsEachTime.
@Test
void propertySourceOptionsAlwaysReturnsSameOptionsEachTime() {
PropertySourceOptions options = PropertySourceOptions.always(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
assertThat(options.get(mock(PropertySource.class)).asSet()).containsExactly(Option.IGNORE_IMPORTS, Option.IGNORE_PROFILES);
}
Aggregations