Search in sources :

Example 11 with MapPropertySource

use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataActivationContextTests method createKubernetesEnvironment.

private MockEnvironment createKubernetesEnvironment() {
    MockEnvironment environment = new MockEnvironment();
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("KUBERNETES_SERVICE_HOST", "host");
    map.put("KUBERNETES_SERVICE_PORT", "port");
    PropertySource<?> propertySource = new MapPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map);
    environment.getPropertySources().addLast(propertySource);
    return environment;
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with MapPropertySource

use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.

the class ConfigDataTests method getPropertySourcesReturnsCopyOfSources.

@Test
void getPropertySourcesReturnsCopyOfSources() {
    MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
    List<MapPropertySource> sources = new ArrayList<>(Collections.singleton(source));
    ConfigData configData = new ConfigData(sources);
    sources.clear();
    assertThat(configData.getPropertySources()).containsExactly(source);
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 13 with MapPropertySource

use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.

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) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Options(cn.taketoday.framework.context.config.ConfigData.Options) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 14 with MapPropertySource

use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.

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) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Option(cn.taketoday.framework.context.config.ConfigData.Option) Options(cn.taketoday.framework.context.config.ConfigData.Options) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PropertySource(cn.taketoday.core.env.PropertySource) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MapPropertySource(cn.taketoday.core.env.MapPropertySource) PropertySourceOptions(cn.taketoday.framework.context.config.ConfigData.PropertySourceOptions) Test(org.junit.jupiter.api.Test)

Example 15 with MapPropertySource

use of cn.taketoday.core.env.MapPropertySource in project today-infrastructure by TAKETODAY.

the class ApplicationTests method defaultPropertiesShouldBeMerged.

@Test
void defaultPropertiesShouldBeMerged() {
    MockEnvironment environment = new MockEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource(DefaultPropertiesPropertySource.NAME, Collections.singletonMap("bar", "foo")));
    Application application = new ApplicationBuilder(ExampleConfig.class).environment(environment).properties("baz=bing").type(ApplicationType.NONE_WEB).build();
    this.context = application.run();
    assertThat(getEnvironment().getProperty("bar")).isEqualTo("foo");
    assertThat(getEnvironment().getProperty("baz")).isEqualTo("bing");
}
Also used : ApplicationBuilder(cn.taketoday.framework.builder.ApplicationBuilder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

MapPropertySource (cn.taketoday.core.env.MapPropertySource)145 Test (org.junit.jupiter.api.Test)120 PropertySources (cn.taketoday.core.env.PropertySources)78 LinkedHashMap (java.util.LinkedHashMap)67 HashMap (java.util.HashMap)54 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)42 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)20 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)16 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)15 FailureAnalysis (cn.taketoday.framework.diagnostics.FailureAnalysis)12 ArrayList (java.util.ArrayList)8 InvalidConfigurationPropertyValueException (cn.taketoday.context.properties.source.InvalidConfigurationPropertyValueException)6 MutuallyExclusiveConfigurationPropertiesException (cn.taketoday.context.properties.source.MutuallyExclusiveConfigurationPropertiesException)6 PropertySourcesPropertyResolver (cn.taketoday.core.env.PropertySourcesPropertyResolver)6 MockEnvironment (cn.taketoday.mock.env.MockEnvironment)6 Map (java.util.Map)5 BeanCreationException (cn.taketoday.beans.factory.BeanCreationException)4 BindException (cn.taketoday.context.properties.bind.BindException)4 BindValidationException (cn.taketoday.context.properties.bind.validation.BindValidationException)4 Environment (cn.taketoday.core.env.Environment)4