Search in sources :

Example 46 with MockConfigurationPropertySource

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

the class JavaBeanBinderTests method bindToClassShouldBindToCollectionWithDelimiter.

@Test
void bindToClassShouldBindToCollectionWithDelimiter() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.collection", "foo-bar|bar-baz");
    this.sources.add(source);
    ExampleCollectionBeanWithDelimiter bean = this.binder.bind("foo", Bindable.of(ExampleCollectionBeanWithDelimiter.class)).get();
    assertThat(bean.getCollection()).containsExactly(ExampleEnum.FOO_BAR, ExampleEnum.BAR_BAZ);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 47 with MockConfigurationPropertySource

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

the class JavaBeanBinderTests method bindToClassWithOverriddenPropertyShouldSetSubclassProperty.

@Test
void bindToClassWithOverriddenPropertyShouldSetSubclassProperty() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.value-bean.int-value", "123");
    source.put("foo.value-bean.sub-int-value", "456");
    this.sources.add(source);
    ExampleNestedSubclassBean bean = this.binder.bind("foo", Bindable.of(ExampleNestedSubclassBean.class)).get();
    assertThat(bean.getValueBean()).isNotNull();
    assertThat(bean.getValueBean().getIntValue()).isEqualTo(123);
    assertThat(bean.getValueBean().getSubIntValue()).isEqualTo(456);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 48 with MockConfigurationPropertySource

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

the class JavaBeanBinderTests method bindToClassShouldBindNested.

@Test
void bindToClassShouldBindNested() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.value-bean.int-value", "123");
    source.put("foo.value-bean.string-value", "foo");
    this.sources.add(source);
    ExampleNestedBean bean = this.binder.bind("foo", Bindable.of(ExampleNestedBean.class)).get();
    assertThat(bean.getValueBean().getIntValue()).isEqualTo(123);
    assertThat(bean.getValueBean().getStringValue()).isEqualTo("foo");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 49 with MockConfigurationPropertySource

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

the class JavaBeanBinderTests method bindToClassShouldIgnoreInvalidAccessors.

@Test
void bindToClassShouldIgnoreInvalidAccessors() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.name", "something");
    this.sources.add(source);
    ExampleWithInvalidAccessors bean = this.binder.bind("foo", Bindable.of(ExampleWithInvalidAccessors.class)).get();
    assertThat(bean.getName()).isEqualTo("something");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 50 with MockConfigurationPropertySource

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

the class JavaBeanBinderTests method bindToClassWhenHasNoSetterShouldBindToMap.

@Test
void bindToClassWhenHasNoSetterShouldBindToMap() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.map.foo-bar", "1");
    source.put("foo.map.bar-baz", "2");
    this.sources.add(source);
    ExampleMapBeanWithoutSetter bean = this.binder.bind("foo", Bindable.of(ExampleMapBeanWithoutSetter.class)).get();
    assertThat(bean.getMap()).containsExactly(entry(ExampleEnum.FOO_BAR, 1), entry(ExampleEnum.BAR_BAZ, 2));
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Aggregations

MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)207 Test (org.junit.jupiter.api.Test)204 Map (java.util.Map)18 HashMap (java.util.HashMap)17 LinkedHashMap (java.util.LinkedHashMap)17 ArrayList (java.util.ArrayList)16 List (java.util.List)16 Binder (org.springframework.boot.context.properties.bind.Binder)15 InOrder (org.mockito.InOrder)8 LinkedList (java.util.LinkedList)7 ResolvableType (org.springframework.core.ResolvableType)7 ValidationBindHandler (org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)5 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)5 StandardEnvironment (org.springframework.core.env.StandardEnvironment)5 ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)4 LocalDate (java.time.LocalDate)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 BindException (org.springframework.boot.context.properties.bind.BindException)3