Search in sources :

Example 21 with MapPropertySource

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

the class DefaultIterableConfigurationPropertySourceTests method containsDescendantOfShouldCheckSourceNames.

@Test
void containsDescendantOfShouldCheckSourceNames() {
    Map<String, Object> source = new LinkedHashMap<>();
    source.put("foo.bar", "value");
    source.put("faf", "value");
    EnumerablePropertySource<?> propertySource = new OriginCapablePropertySource<>(new MapPropertySource("test", source));
    DefaultIterableConfigurationPropertySource adapter = new DefaultIterableConfigurationPropertySource(propertySource, DefaultPropertyMapper.INSTANCE);
    assertThat(adapter.containsDescendantOf(ConfigurationPropertyName.of("foo"))).isEqualTo(ConfigurationPropertyState.PRESENT);
    assertThat(adapter.containsDescendantOf(ConfigurationPropertyName.of("faf"))).isEqualTo(ConfigurationPropertyState.ABSENT);
    assertThat(adapter.containsDescendantOf(ConfigurationPropertyName.of("fof"))).isEqualTo(ConfigurationPropertyState.ABSENT);
}
Also used : OriginTrackedMapPropertySource(cn.taketoday.framework.env.OriginTrackedMapPropertySource) MapPropertySource(cn.taketoday.core.env.MapPropertySource) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 22 with MapPropertySource

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

the class ConfigurationPropertyCachingTests method setup.

@BeforeEach
void setup() {
    this.environment = new StandardEnvironment();
    this.propertySource = new MapPropertySource("test", Collections.singletonMap("spring", "boot"));
    this.environment.getPropertySources().addLast(this.propertySource);
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with MapPropertySource

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

the class PropertySourceOriginTests method toStringShouldShowDetails.

@Test
void toStringShouldShowDetails() {
    MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
    PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
    assertThat(origin.toString()).isEqualTo("\"foo\" from property source \"test\"");
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 24 with MapPropertySource

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

the class PropertySourceOriginTests method getWhenPropertySourceIsNotOriginAwareShouldWrap.

@Test
void getWhenPropertySourceIsNotOriginAwareShouldWrap() {
    MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
    PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
    assertThat(origin.getPropertySource()).isEqualTo(propertySource);
    assertThat(origin.getPropertyName()).isEqualTo("foo");
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 25 with MapPropertySource

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

the class PropertySourceOriginTests method getPropertySourceShouldReturnPropertySource.

@Test
void getPropertySourceShouldReturnPropertySource() {
    MapPropertySource propertySource = new MapPropertySource("test", new HashMap<>());
    PropertySourceOrigin origin = new PropertySourceOrigin(propertySource, "foo");
    assertThat(origin.getPropertySource()).isEqualTo(propertySource);
}
Also used : 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