Search in sources :

Example 66 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToImmutableCollectionShouldReturnPopulatedCollection.

@Test
void bindToImmutableCollectionShouldReturnPopulatedCollection() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.values", "a,b,c");
    this.sources.add(source);
    Set<String> result = this.binder.bind("foo.values", STRING_SET.withExistingValue(Collections.emptySet())).get();
    assertThat(result).hasSize(3);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 67 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToBeanWithClonedArray.

@Test
void bindToBeanWithClonedArray() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.bar[0]", "hello");
    this.sources.add(source);
    Bindable<ClonedArrayBean> target = Bindable.of(ClonedArrayBean.class);
    ClonedArrayBean bean = this.binder.bind("foo", target).get();
    assertThat(bean.getBar()).containsExactly("hello");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 68 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToCollectionWhenNestedShouldReturnPopulatedCollection.

@Test
void bindToCollectionWhenNestedShouldReturnPopulatedCollection() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo[0][0]", "1");
    source.put("foo[0][1]", "2");
    source.put("foo[1][0]", "3");
    source.put("foo[1][1]", "4");
    this.sources.add(source);
    Bindable<List<List<Integer>>> target = Bindable.of(ResolvableType.forClassWithGenerics(List.class, INTEGER_LIST.getType()));
    List<List<Integer>> result = this.binder.bind("foo", target).get();
    assertThat(result).hasSize(2);
    assertThat(result.get(0)).containsExactly(1, 2);
    assertThat(result.get(1)).containsExactly(3, 4);
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 69 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToSetShouldNotAllowDuplicateValues.

@Test
void bindToSetShouldNotAllowDuplicateValues() {
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.items-set", "a,b,c,c");
    this.sources.add(source);
    ExampleCollectionBean result = this.binder.bind("foo", ExampleCollectionBean.class).get();
    assertThat(result.getItemsSet()).hasSize(3);
    assertThat(result.getItemsSet()).containsExactly("a", "b", "c");
}
Also used : MockConfigurationPropertySource(org.springframework.boot.context.properties.source.MockConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 70 with MockConfigurationPropertySource

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

the class CollectionBinderTests method bindToCollectionWhenCommaListShouldReturnPopulatedCollection.

@Test
void bindToCollectionWhenCommaListShouldReturnPopulatedCollection() {
    this.sources.add(new MockConfigurationPropertySource("foo", "1,2,3"));
    List<Integer> result = this.binder.bind("foo", INTEGER_LIST).get();
    assertThat(result).containsExactly(1, 2, 3);
}
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