Search in sources :

Example 1 with StringTrimmerEditor

use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-infrastructure by TAKETODAY.

the class DataBinderTests method conversionWithInappropriateStringEditor.

@Test
void conversionWithInappropriateStringEditor() {
    DataBinder dataBinder = new DataBinder(null);
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    dataBinder.setConversionService(conversionService);
    dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    NameBean bean = new NameBean("Fred");
    assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
    conversionService.addConverter(new NameBeanConverter());
    assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("Type converter should have been used").isEqualTo("[Fred]");
}
Also used : StringTrimmerEditor(cn.taketoday.beans.propertyeditors.StringTrimmerEditor) DefaultFormattingConversionService(cn.taketoday.format.support.DefaultFormattingConversionService) Test(org.junit.jupiter.api.Test)

Example 2 with StringTrimmerEditor

use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-infrastructure by TAKETODAY.

the class DataBinderTests method setAutoGrowCollectionLimitAfterInitialization.

@Test
// SPR-14888
void setAutoGrowCollectionLimitAfterInitialization() {
    DataBinder binder = new DataBinder(new BeanWithIntegerList());
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    assertThatIllegalStateException().isThrownBy(() -> binder.setAutoGrowCollectionLimit(257)).withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
}
Also used : StringTrimmerEditor(cn.taketoday.beans.propertyeditors.StringTrimmerEditor) Test(org.junit.jupiter.api.Test)

Example 3 with StringTrimmerEditor

use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-infrastructure by TAKETODAY.

the class AbstractPropertyAccessorTests method propertyTypeIndexedProperty.

@Test
void propertyTypeIndexedProperty() {
    IndexedTestBean target = new IndexedTestBean();
    AbstractPropertyAccessor accessor = createAccessor(target);
    assertThat(accessor.getPropertyType("map[key0]")).isNull();
    accessor = createAccessor(target);
    accessor.setPropertyValue("map[key0]", "my String");
    assertThat(accessor.getPropertyType("map[key0]")).isEqualTo(String.class);
    accessor = createAccessor(target);
    accessor.registerCustomEditor(String.class, "map[key0]", new StringTrimmerEditor(false));
    assertThat(accessor.getPropertyType("map[key0]")).isEqualTo(String.class);
}
Also used : IndexedTestBean(cn.taketoday.beans.testfixture.beans.IndexedTestBean) StringTrimmerEditor(cn.taketoday.beans.propertyeditors.StringTrimmerEditor) Test(org.junit.jupiter.api.Test)

Example 4 with StringTrimmerEditor

use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-framework by TAKETODAY.

the class DataBinderTests method testSetAutoGrowCollectionLimitAfterInitialization.

@Test
// SPR-14888
void testSetAutoGrowCollectionLimitAfterInitialization() {
    DataBinder binder = new DataBinder(new BeanWithIntegerList());
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    assertThatIllegalStateException().isThrownBy(() -> binder.setAutoGrowCollectionLimit(257)).withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
}
Also used : StringTrimmerEditor(cn.taketoday.beans.propertyeditors.StringTrimmerEditor) DataBinder(cn.taketoday.validation.DataBinder) Test(org.junit.jupiter.api.Test)

Example 5 with StringTrimmerEditor

use of cn.taketoday.beans.propertyeditors.StringTrimmerEditor in project today-framework by TAKETODAY.

the class DataBinderTests method conversionWithInappropriateStringEditor.

@Test
void conversionWithInappropriateStringEditor() {
    DataBinder dataBinder = new DataBinder(null);
    DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
    dataBinder.setConversionService(conversionService);
    dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
    NameBean bean = new NameBean("Fred");
    assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
    conversionService.addConverter(new NameBeanConverter());
    assertThat(dataBinder.convertIfNecessary(bean, String.class)).as("Type converter should have been used").isEqualTo("[Fred]");
}
Also used : StringTrimmerEditor(cn.taketoday.beans.propertyeditors.StringTrimmerEditor) DefaultFormattingConversionService(cn.taketoday.format.support.DefaultFormattingConversionService) Test(org.junit.jupiter.api.Test)

Aggregations

StringTrimmerEditor (cn.taketoday.beans.propertyeditors.StringTrimmerEditor)16 Test (org.junit.jupiter.api.Test)16 IndexedTestBean (cn.taketoday.beans.testfixture.beans.IndexedTestBean)4 DefaultFormattingConversionService (cn.taketoday.format.support.DefaultFormattingConversionService)3 MethodInvokingFactoryBean (cn.taketoday.beans.factory.config.MethodInvokingFactoryBean)2 GenericBean (cn.taketoday.beans.testfixture.beans.GenericBean)2 DataBinder (cn.taketoday.validation.DataBinder)2 BindingContext (cn.taketoday.web.BindingContext)2 RequestContextDataBinder (cn.taketoday.web.bind.RequestContextDataBinder)2 ResolvableMethodParameter (cn.taketoday.web.handler.method.ResolvableMethodParameter)2 ServletRequestContext (cn.taketoday.web.servlet.ServletRequestContext)2 MockHttpServletResponse (cn.taketoday.web.testfixture.servlet.MockHttpServletResponse)2 ArrayList (java.util.ArrayList)2 RequestParam (cn.taketoday.web.annotation.RequestParam)1 MissingRequestParameterException (cn.taketoday.web.bind.MissingRequestParameterException)1