Search in sources :

Example 26 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.

the class BeanWrapperEnumTests method testStandardEnumSetWithMultipleValues.

@Test
public void testStandardEnumSetWithMultipleValues() {
    GenericBean<?> gb = new GenericBean<>();
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.setConversionService(new DefaultConversionService());
    assertNull(gb.getStandardEnumSet());
    bw.setPropertyValue("standardEnumSet", new String[] { "VALUE_1", "VALUE_2" });
    assertEquals(2, gb.getStandardEnumSet().size());
    assertTrue(gb.getStandardEnumSet().contains(CustomEnum.VALUE_1));
    assertTrue(gb.getStandardEnumSet().contains(CustomEnum.VALUE_2));
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) GenericBean(org.springframework.tests.sample.beans.GenericBean) Test(org.junit.Test)

Example 27 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-framework by spring-projects.

the class BeanWrapperEnumTests method testStandardEnumMapWithMultipleValues.

@Test
public void testStandardEnumMapWithMultipleValues() {
    GenericBean<?> gb = new GenericBean<>();
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.setConversionService(new DefaultConversionService());
    assertNull(gb.getStandardEnumMap());
    Map<String, Integer> map = new LinkedHashMap<>();
    map.put("VALUE_1", 1);
    map.put("VALUE_2", 2);
    bw.setPropertyValue("standardEnumMap", map);
    assertEquals(2, gb.getStandardEnumMap().size());
    assertEquals(new Integer(1), gb.getStandardEnumMap().get(CustomEnum.VALUE_1));
    assertEquals(new Integer(2), gb.getStandardEnumMap().get(CustomEnum.VALUE_2));
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) GenericBean(org.springframework.tests.sample.beans.GenericBean) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 28 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.

the class RelaxedDataBinderTests method testBindNestedMapOfEnumRelaxedNames.

@Test
public void testBindNestedMapOfEnumRelaxedNames() throws Exception {
    this.conversionService = new DefaultConversionService();
    TargetWithNestedMapOfEnum target = new TargetWithNestedMapOfEnum();
    bind(target, "nested.the-other: bar\n" + "nested.that_other: 123");
    assertThat(target.getNested().get(Bingo.THE_OTHER)).isEqualTo("bar");
    assertThat(target.getNested().get(Bingo.THAT_OTHER)).isEqualTo("123");
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.Test)

Example 29 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.

the class RelaxedDataBinderTests method testBindNestedSetCommaDelimitedOnly.

@Test
public void testBindNestedSetCommaDelimitedOnly() throws Exception {
    TargetWithNestedSet target = new TargetWithNestedSet();
    this.conversionService = new DefaultConversionService();
    bind(target, "nested: bar,foo");
    assertThat(target.getNested().toString()).isEqualTo("[bar, foo]");
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.Test)

Example 30 with DefaultConversionService

use of org.springframework.core.convert.support.DefaultConversionService in project spring-boot by spring-projects.

the class RelaxedDataBinderTests method testBindNestedMapOfEnum.

@Test
public void testBindNestedMapOfEnum() throws Exception {
    this.conversionService = new DefaultConversionService();
    TargetWithNestedMapOfEnum target = new TargetWithNestedMapOfEnum();
    bind(target, "nested.this: bar\n" + "nested.ThAt: 123");
    assertThat(target.getNested().get(Bingo.THIS)).isEqualTo("bar");
    assertThat(target.getNested().get(Bingo.THAT)).isEqualTo("123");
}
Also used : DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Test(org.junit.Test)

Aggregations

DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)37 Test (org.junit.Test)30 MethodParameter (org.springframework.core.MethodParameter)7 ConfigurableWebBindingInitializer (org.springframework.web.bind.support.ConfigurableWebBindingInitializer)7 WebDataBinderFactory (org.springframework.web.bind.support.WebDataBinderFactory)7 DefaultDataBinderFactory (org.springframework.web.bind.support.DefaultDataBinderFactory)6 Before (org.junit.Before)5 ConversionService (org.springframework.core.convert.ConversionService)5 RequestParam (org.springframework.web.bind.annotation.RequestParam)4 Method (java.lang.reflect.Method)3 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 DefaultParameterNameDiscoverer (org.springframework.core.DefaultParameterNameDiscoverer)2 SynthesizingMethodParameter (org.springframework.core.annotation.SynthesizingMethodParameter)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 GenericBean (org.springframework.tests.sample.beans.GenericBean)2 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)2