use of org.springframework.beans.propertyeditors.StringTrimmerEditor in project spring-framework by spring-projects.
the class RequestParamMethodArgumentResolverTests method missingRequestParamEmptyValueConvertedToNull.
// SPR-10578
@Test
public void missingRequestParamEmptyValueConvertedToNull() throws Exception {
WebDataBinder binder = new WebRequestDataBinder(null);
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
given(binderFactory.createBinder(webRequest, null, "stringNotAnnot")).willReturn(binder);
this.request.addParameter("stringNotAnnot", "");
MethodParameter param = this.testMethod.annotNotPresent(RequestParam.class).arg(String.class);
Object arg = resolver.resolveArgument(param, null, webRequest, binderFactory);
assertNull(arg);
}
use of org.springframework.beans.propertyeditors.StringTrimmerEditor in project spring-framework by spring-projects.
the class AbstractPropertyAccessorTests method setPrimitiveArrayPropertyLargeMatching.
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));
PrimitiveArrayBean target = new PrimitiveArrayBean();
AbstractPropertyAccessor accessor = createAccessor(target);
int[] input = new int[1024];
StopWatch sw = new StopWatch();
sw.start("array1");
for (int i = 0; i < 1000; i++) {
accessor.setPropertyValue("array", input);
}
sw.stop();
assertEquals(1024, target.getArray().length);
assertEquals(0, target.getArray()[0]);
long time1 = sw.getLastTaskTimeMillis();
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);
accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
sw.start("array2");
for (int i = 0; i < 1000; i++) {
accessor.setPropertyValue("array", input);
}
sw.stop();
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);
accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
sw.start("array3");
for (int i = 0; i < 1000; i++) {
accessor.setPropertyValue("array", input);
}
sw.stop();
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);
accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
sw.start("array3");
for (int i = 0; i < 1000; i++) {
accessor.setPropertyValue("array", input);
}
sw.stop();
assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);
accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
sw.start("array4");
for (int i = 0; i < 100; i++) {
accessor.setPropertyValue("array", input);
}
sw.stop();
assertEquals(1024, target.getArray().length);
assertEquals(0, target.getArray()[0]);
assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}
use of org.springframework.beans.propertyeditors.StringTrimmerEditor in project spring-framework by spring-projects.
the class BeanWrapperGenericsTests method testGenericListOfArraysWithElementConversion.
@Test
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
GenericBean<String> gb = new GenericBean<>();
ArrayList<String[]> list = new ArrayList<>();
list.add(new String[] { "str1", "str2" });
gb.setListOfArrays(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
assertEquals("str3", gb.getListOfArrays().get(0)[1]);
}
use of org.springframework.beans.propertyeditors.StringTrimmerEditor in project spring-framework by spring-projects.
the class DataBinderTests method testSetAutoGrowCollectionLimitAfterInitialization.
// SPR-14888
@Test
public void testSetAutoGrowCollectionLimitAfterInitialization() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
DataBinder binder = new DataBinder(new BeanWithIntegerList());
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
binder.setAutoGrowCollectionLimit(257);
}
use of org.springframework.beans.propertyeditors.StringTrimmerEditor in project spring-framework by spring-projects.
the class DataBinderTests method testConversionWithInappropriateStringEditor.
@Test
public void testConversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
dataBinder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
NameBean bean = new NameBean("Fred");
assertEquals("ConversionService should have invoked toString()", "Fred", dataBinder.convertIfNecessary(bean, String.class));
conversionService.addConverter(new NameBeanConverter());
assertEquals("Type converter should have been used", "[Fred]", dataBinder.convertIfNecessary(bean, String.class));
}
Aggregations