Search in sources :

Example 26 with MapPropertySource

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

the class PropertySourceOriginTests method getPropertyNameShouldReturnPropertyName.

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

Example 27 with MapPropertySource

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

the class ResourceBanner method getTitleResolver.

private PropertyResolver getTitleResolver(Class<?> sourceClass) {
    PropertySources sources = new PropertySources();
    String applicationTitle = getApplicationTitle(sourceClass);
    Map<String, Object> titleMap = Collections.singletonMap("application.title", (applicationTitle != null) ? applicationTitle : "");
    sources.addFirst(new MapPropertySource("title", titleMap));
    return new PropertySourcesPropertyResolver(sources);
}
Also used : PropertySourcesPropertyResolver(cn.taketoday.core.env.PropertySourcesPropertyResolver) PropertySources(cn.taketoday.core.env.PropertySources) MapPropertySource(cn.taketoday.core.env.MapPropertySource)

Example 28 with MapPropertySource

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

the class PropertySourceAnnotationTests method orderingDoesntReplaceExisting.

@Test
void orderingDoesntReplaceExisting() throws Exception {
    // SPR-12198: mySource should 'win' as it was registered manually
    AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext();
    MapPropertySource mySource = new MapPropertySource("mine", Collections.singletonMap("testbean.name", "myTestBean"));
    ctxWithoutName.getEnvironment().getPropertySources().addLast(mySource);
    ctxWithoutName.register(ConfigWithFourResourceLocations.class);
    ctxWithoutName.refresh();
    assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("myTestBean");
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) Test(org.junit.jupiter.api.Test)

Example 29 with MapPropertySource

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

the class ValidationBindHandlerTests method validateMapValuesWithNonUniformSource.

@Test
void validateMapValuesWithNonUniformSource() {
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("test.items.itemOne.number", "one");
    map.put("test.items.ITEM2.number", "two");
    this.sources.add(ConfigurationPropertySources.from(new MapPropertySource("test", map)).iterator().next());
    Validator validator = getMapValidator();
    this.handler = new ValidationBindHandler(validator);
    this.binder.bind(ConfigurationPropertyName.of("test"), Bindable.of(ExampleWithMap.class), this.handler);
}
Also used : MapPropertySource(cn.taketoday.core.env.MapPropertySource) Validator(cn.taketoday.validation.Validator) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 30 with MapPropertySource

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

the class PropertySourcesPlaceholdersResolverTests method getPropertySources.

private PropertySources getPropertySources() {
    PropertySources sources = new PropertySources();
    Map<String, Object> source = new HashMap<>();
    source.put("FOO", "hello world");
    sources.addFirst(new MapPropertySource("test", source));
    return sources;
}
Also used : PropertySources(cn.taketoday.core.env.PropertySources) HashMap(java.util.HashMap) MapPropertySource(cn.taketoday.core.env.MapPropertySource)

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