Search in sources :

Example 26 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ConfigDataPropertiesTests method getImportOriginWhenCommaListReturnsOrigin.

@Test
void getImportOriginWhenCommaListReturnsOrigin() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("spring.config.import", "one,two,three");
    Binder binder = new Binder(source);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    assertThat(properties.getImports().get(1).getOrigin()).hasToString("\"spring.config.import\" from property source \"source\"");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 27 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ConfigDataPropertiesTests method isActiveAgainstBoundDataWhenCloudPlatformDoesntMatch.

@Test
void isActiveAgainstBoundDataWhenCloudPlatformDoesntMatch() {
    MapConfigurationPropertySource source = new MapConfigurationPropertySource();
    source.put("spring.config.activate.on-cloud-platform", "cloud-foundry");
    source.put("spring.config.activate.on-profile", "a | b");
    Binder binder = new Binder(source);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    ConfigDataActivationContext context = new ConfigDataActivationContext(CloudPlatform.KUBERNETES, createTestProfiles());
    assertThat(properties.isActive(context)).isFalse();
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 28 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ProfilesTests method getDefaultWhenDefaultEnvironmentProfileAndBinderProperty.

@Test
void getDefaultWhenDefaultEnvironmentProfileAndBinderProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("spring.profiles.default", "default");
    List<ConfigurationPropertySource> sources = new ArrayList<>();
    ConfigurationPropertySources.get(environment).forEach(sources::add);
    sources.add(new MapConfigurationPropertySource(Collections.singletonMap("spring.profiles.default", "a,b,c")));
    Binder binder = new Binder(sources);
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getDefault()).containsExactly("default");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockEnvironment(org.springframework.mock.env.MockEnvironment) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) ArrayList(java.util.ArrayList) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 29 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ProfilesTests method getActiveWhenEnvironmentProfilesAndBinderProperty.

@Test
void getActiveWhenEnvironmentProfilesAndBinderProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setActiveProfiles("a", "b", "c");
    Binder binder = new Binder(new MapConfigurationPropertySource(Collections.singletonMap("spring.profiles.active", "d,e,f")));
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getActive()).containsExactly("a", "b", "c", "d", "e", "f");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockEnvironment(org.springframework.mock.env.MockEnvironment) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 30 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-boot by spring-projects.

the class ProfilesTests method getActiveWhenNoEnvironmentProfilesAndBinderProperty.

@Test
void getActiveWhenNoEnvironmentProfilesAndBinderProperty() {
    Environment environment = new MockEnvironment();
    Binder binder = new Binder(new MapConfigurationPropertySource(Collections.singletonMap("spring.profiles.active", "a,b,c")));
    Profiles profiles = new Profiles(environment, binder, null);
    assertThat(profiles.getActive()).containsExactly("a", "b", "c");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) MockEnvironment(org.springframework.mock.env.MockEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)35 Binder (org.springframework.boot.context.properties.bind.Binder)32 Test (org.junit.jupiter.api.Test)21 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)11 MockEnvironment (org.springframework.mock.env.MockEnvironment)7 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 LinkedHashMap (java.util.LinkedHashMap)3 Environment (org.springframework.core.env.Environment)3 ArrayList (java.util.ArrayList)2 ApolloClientProperties (com.ctrip.framework.apollo.config.data.extension.properties.ApolloClientProperties)1 DataSourceBeanCreationException (org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException)1 ConfigurationPropertyNameAliases (org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases)1 Catalog (org.springframework.cloud.servicebroker.model.catalog.Catalog)1 Binder (org.springframework.cloud.stream.binder.Binder)1 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)1 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1 BindException (org.springframework.validation.BindException)1