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;
}
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);
}
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);
}
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);
}
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");
}
Aggregations