Search in sources :

Example 1 with PropertySourceOptions

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);
}
Also used : OriginTrackedResource(org.springframework.boot.origin.OriginTrackedResource) Resource(org.springframework.core.io.Resource) PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) PropertySource(org.springframework.core.env.PropertySource)

Example 2 with PropertySourceOptions

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);
}
Also used : Arrays(java.util.Arrays) PropertySource(org.springframework.core.env.PropertySource) PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) MapPropertySource(org.springframework.core.env.MapPropertySource) Option(org.springframework.boot.context.config.ConfigData.Option) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Collections(java.util.Collections) Options(org.springframework.boot.context.config.ConfigData.Options) Mockito.mock(org.mockito.Mockito.mock) PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) Options(org.springframework.boot.context.config.ConfigData.Options) MapPropertySource(org.springframework.core.env.MapPropertySource) PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 3 with PropertySourceOptions

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);
}
Also used : Arrays(java.util.Arrays) PropertySource(org.springframework.core.env.PropertySource) PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) MapPropertySource(org.springframework.core.env.MapPropertySource) Option(org.springframework.boot.context.config.ConfigData.Option) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) Collections(java.util.Collections) Options(org.springframework.boot.context.config.ConfigData.Options) Mockito.mock(org.mockito.Mockito.mock) MapPropertySource(org.springframework.core.env.MapPropertySource) PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 4 with PropertySourceOptions

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);
}
Also used : PropertySourceOptions(org.springframework.boot.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Aggregations

PropertySourceOptions (org.springframework.boot.context.config.ConfigData.PropertySourceOptions)4 Test (org.junit.jupiter.api.Test)3 PropertySource (org.springframework.core.env.PropertySource)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)2 Mockito.mock (org.mockito.Mockito.mock)2 Option (org.springframework.boot.context.config.ConfigData.Option)2 Options (org.springframework.boot.context.config.ConfigData.Options)2 MapPropertySource (org.springframework.core.env.MapPropertySource)2 OriginTrackedResource (org.springframework.boot.origin.OriginTrackedResource)1 Resource (org.springframework.core.io.Resource)1