|
|
@ -35,7 +35,7 @@ import java.util.Map; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.TreeSet; |
|
|
|
import java.util.TreeSet; |
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.InvalidPropertyException; |
|
|
|
import org.springframework.beans.InvalidPropertyException; |
|
|
|
import org.springframework.beans.MutablePropertyValues; |
|
|
|
import org.springframework.beans.MutablePropertyValues; |
|
|
@ -59,13 +59,16 @@ import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Rob Harrop |
|
|
|
* @author Rob Harrop |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DataBinderTests extends TestCase { |
|
|
|
public class DataBinderTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingNoErrors() throws Exception { |
|
|
|
public void testBindingNoErrors() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -99,7 +102,8 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue(!other.equals(binder.getBindingResult())); |
|
|
|
assertTrue(!other.equals(binder.getBindingResult())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testedBindingWithDefaultConversionNoErrors() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void testBindingWithDefaultConversionNoErrors() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
assertTrue(binder.isIgnoreUnknownFields()); |
|
|
|
assertTrue(binder.isIgnoreUnknownFields()); |
|
|
@ -114,7 +118,8 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue(rod.isJedi()); |
|
|
|
assertTrue(rod.isJedi()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testedNestedBindingWithDefaultConversionNoErrors() throws Exception { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void testNestedBindingWithDefaultConversionNoErrors() throws Exception { |
|
|
|
TestBean rod = new TestBean(new TestBean()); |
|
|
|
TestBean rod = new TestBean(new TestBean()); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
assertTrue(binder.isIgnoreUnknownFields()); |
|
|
|
assertTrue(binder.isIgnoreUnknownFields()); |
|
|
@ -129,6 +134,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue(((TestBean) rod.getSpouse()).isJedi()); |
|
|
|
assertTrue(((TestBean) rod.getSpouse()).isJedi()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingNoErrorsNotIgnoreUnknown() throws Exception { |
|
|
|
public void testBindingNoErrorsNotIgnoreUnknown() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -147,6 +153,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingNoErrorsWithInvalidField() throws Exception { |
|
|
|
public void testBindingNoErrorsWithInvalidField() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -163,6 +170,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingNoErrorsWithIgnoreInvalid() throws Exception { |
|
|
|
public void testBindingNoErrorsWithIgnoreInvalid() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -174,6 +182,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithErrors() throws Exception { |
|
|
|
public void testBindingWithErrors() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -235,6 +244,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithSystemFieldError() throws Exception { |
|
|
|
public void testBindingWithSystemFieldError() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -251,6 +261,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithErrorsAndCustomEditors() throws Exception { |
|
|
|
public void testBindingWithErrorsAndCustomEditors() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -317,6 +328,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithCustomEditorOnObjectField() { |
|
|
|
public void testBindingWithCustomEditorOnObjectField() { |
|
|
|
BeanWithObjectProperty tb = new BeanWithObjectProperty(); |
|
|
|
BeanWithObjectProperty tb = new BeanWithObjectProperty(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -327,6 +339,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(new Integer(1), tb.getObject()); |
|
|
|
assertEquals(new Integer(1), tb.getObject()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithFormatter() { |
|
|
|
public void testBindingWithFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -358,6 +371,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingErrorWithFormatter() { |
|
|
|
public void testBindingErrorWithFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -380,12 +394,13 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingErrorWithStringFormatter() { |
|
|
|
public void testBindingErrorWithStringFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
DefaultConversionService.addDefaultConverters(conversionService); |
|
|
|
DefaultConversionService.addDefaultConverters(conversionService); |
|
|
|
conversionService.addFormatterForFieldType(String.class, new Formatter<String>() { |
|
|
|
conversionService.addFormatter(new Formatter<String>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String parse(String text, Locale locale) throws ParseException { |
|
|
|
public String parse(String text, Locale locale) throws ParseException { |
|
|
|
throw new ParseException(text, 0); |
|
|
|
throw new ParseException(text, 0); |
|
|
@ -404,6 +419,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("test", binder.getBindingResult().getFieldValue("name")); |
|
|
|
assertEquals("test", binder.getBindingResult().getFieldValue("name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithFormatterAgainstList() { |
|
|
|
public void testBindingWithFormatterAgainstList() { |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -425,6 +441,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingErrorWithFormatterAgainstList() { |
|
|
|
public void testBindingErrorWithFormatterAgainstList() { |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -447,6 +464,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithFormatterAgainstFields() { |
|
|
|
public void testBindingWithFormatterAgainstFields() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -479,6 +497,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingErrorWithFormatterAgainstFields() { |
|
|
|
public void testBindingErrorWithFormatterAgainstFields() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
@ -502,6 +521,78 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testBindingWithCustomFormatter() { |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
|
|
|
|
binder.addCustomFormatter(new NumberStyleFormatter(), Float.class); |
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("myFloat", "1,2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocaleContextHolder.setLocale(Locale.GERMAN); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
assertEquals(new Float(1.2), tb.getMyFloat()); |
|
|
|
|
|
|
|
assertEquals("1,2", binder.getBindingResult().getFieldValue("myFloat")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class); |
|
|
|
|
|
|
|
assertNotNull(editor); |
|
|
|
|
|
|
|
editor.setValue(new Float(1.4)); |
|
|
|
|
|
|
|
assertEquals("1,4", editor.getAsText()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
editor = binder.getBindingResult().findEditor("myFloat", null); |
|
|
|
|
|
|
|
assertNotNull(editor); |
|
|
|
|
|
|
|
editor.setAsText("1,6"); |
|
|
|
|
|
|
|
assertTrue(((Number) editor.getValue()).floatValue() == 1.6f); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
LocaleContextHolder.resetLocaleContext(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testBindingErrorWithCustomFormatter() { |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
|
|
|
|
binder.addCustomFormatter(new NumberStyleFormatter()); |
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("myFloat", "1x2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LocaleContextHolder.setLocale(Locale.GERMAN); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
assertEquals(new Float(0.0), tb.getMyFloat()); |
|
|
|
|
|
|
|
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat")); |
|
|
|
|
|
|
|
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
|
|
|
|
LocaleContextHolder.resetLocaleContext(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testBindingErrorWithCustomStringFormatter() { |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
|
|
|
|
binder.addCustomFormatter(new Formatter<String>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String parse(String text, Locale locale) throws ParseException { |
|
|
|
|
|
|
|
throw new ParseException(text, 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String print(String object, Locale locale) { |
|
|
|
|
|
|
|
return object; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("name", "test"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
assertTrue(binder.getBindingResult().hasFieldErrors("name")); |
|
|
|
|
|
|
|
assertEquals("test", binder.getBindingResult().getFieldValue("name")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedFields() throws Exception { |
|
|
|
public void testBindingWithAllowedFields() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
@ -516,6 +607,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue("did not change age", rod.getAge() == 0); |
|
|
|
assertTrue("did not change age", rod.getAge() == 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithDisallowedFields() throws Exception { |
|
|
|
public void testBindingWithDisallowedFields() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
@ -533,6 +625,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("age", disallowedFields[0]); |
|
|
|
assertEquals("age", disallowedFields[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedAndDisallowedFields() throws Exception { |
|
|
|
public void testBindingWithAllowedAndDisallowedFields() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
@ -551,6 +644,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("age", disallowedFields[0]); |
|
|
|
assertEquals("age", disallowedFields[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithOverlappingAllowedAndDisallowedFields() throws Exception { |
|
|
|
public void testBindingWithOverlappingAllowedAndDisallowedFields() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
@ -569,6 +663,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("age", disallowedFields[0]); |
|
|
|
assertEquals("age", disallowedFields[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedFieldsUsingAsterisks() throws Exception { |
|
|
|
public void testBindingWithAllowedFieldsUsingAsterisks() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -595,6 +690,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue("Same object", tb.equals(rod)); |
|
|
|
assertTrue("Same object", tb.equals(rod)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedAndDisallowedMapFields() throws Exception { |
|
|
|
public void testBindingWithAllowedAndDisallowedMapFields() throws Exception { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
@ -622,6 +718,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Tests for required field, both null, non-existing and empty strings. |
|
|
|
* Tests for required field, both null, non-existing and empty strings. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithRequiredFields() throws Exception { |
|
|
|
public void testBindingWithRequiredFields() throws Exception { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
@ -652,6 +749,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("", br.getFieldValue("spouse.name")); |
|
|
|
assertEquals("", br.getFieldValue("spouse.name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithRequiredMapFields() throws Exception { |
|
|
|
public void testBindingWithRequiredMapFields() throws Exception { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
@ -671,6 +769,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("required", br.getFieldError("someMap[key4]").getCode()); |
|
|
|
assertEquals("required", br.getFieldError("someMap[key4]").getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithNestedObjectCreation() throws Exception { |
|
|
|
public void testBindingWithNestedObjectCreation() throws Exception { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
|
|
|
@ -691,6 +790,32 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("test", tb.getSpouse().getName()); |
|
|
|
assertEquals("test", tb.getSpouse().getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testCustomEditorWithOldValueAccess() { |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binder.registerCustomEditor(String.class, null, new PropertyEditorSupport() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
|
|
|
|
if (getValue() == null || !text.equalsIgnoreCase(getValue().toString())) { |
|
|
|
|
|
|
|
setValue(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("name", "value"); |
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
assertEquals("value", tb.getName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("name", "vaLue"); |
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
assertEquals("value", tb.getName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCustomEditorForSingleProperty() { |
|
|
|
public void testCustomEditorForSingleProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
@ -730,6 +855,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("spouse.name", binder.getBindingResult().getFieldError("spouse.*").getField()); |
|
|
|
assertEquals("spouse.name", binder.getBindingResult().getFieldError("spouse.*").getField()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCustomEditorForPrimitiveProperty() { |
|
|
|
public void testCustomEditorForPrimitiveProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -739,6 +865,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
setValue(new Integer(99)); |
|
|
|
setValue(new Integer(99)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getAsText() { |
|
|
|
public String getAsText() { |
|
|
|
return "argh"; |
|
|
|
return "argh"; |
|
|
@ -753,6 +880,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCustomEditorForAllStringProperties() { |
|
|
|
public void testCustomEditorForAllStringProperties() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -762,6 +890,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
setValue("prefix" + text); |
|
|
|
setValue("prefix" + text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String getAsText() { |
|
|
|
public String getAsText() { |
|
|
|
return ((String) getValue()).substring(6); |
|
|
|
return ((String) getValue()).substring(6); |
|
|
@ -784,30 +913,104 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("prefixvalue", tb.getTouchy()); |
|
|
|
assertEquals("prefixvalue", tb.getTouchy()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCustomEditorWithOldValueAccess() { |
|
|
|
@Test |
|
|
|
|
|
|
|
public void testCustomFormatterForSingleProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
binder.registerCustomEditor(String.class, null, new PropertyEditorSupport() { |
|
|
|
binder.addCustomFormatter(new Formatter<String>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void setAsText(String text) throws IllegalArgumentException { |
|
|
|
public String parse(String text, Locale locale) throws ParseException { |
|
|
|
if (getValue() == null || !text.equalsIgnoreCase(getValue().toString())) { |
|
|
|
return "prefix" + text; |
|
|
|
setValue(text); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
@Override |
|
|
|
|
|
|
|
public String print(String object, Locale locale) { |
|
|
|
|
|
|
|
return object.substring(6); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, "name"); |
|
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("name", "value"); |
|
|
|
pvs.add("name", "value"); |
|
|
|
|
|
|
|
pvs.add("touchy", "value"); |
|
|
|
|
|
|
|
pvs.add("spouse.name", "sue"); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
assertEquals("value", tb.getName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pvs = new MutablePropertyValues(); |
|
|
|
binder.getBindingResult().rejectValue("name", "someCode", "someMessage"); |
|
|
|
pvs.add("name", "vaLue"); |
|
|
|
binder.getBindingResult().rejectValue("touchy", "someCode", "someMessage"); |
|
|
|
|
|
|
|
binder.getBindingResult().rejectValue("spouse.name", "someCode", "someMessage"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("", binder.getBindingResult().getNestedPath()); |
|
|
|
|
|
|
|
assertEquals("value", binder.getBindingResult().getFieldValue("name")); |
|
|
|
|
|
|
|
assertEquals("prefixvalue", binder.getBindingResult().getFieldError("name").getRejectedValue()); |
|
|
|
|
|
|
|
assertEquals("prefixvalue", tb.getName()); |
|
|
|
|
|
|
|
assertEquals("value", binder.getBindingResult().getFieldValue("touchy")); |
|
|
|
|
|
|
|
assertEquals("value", binder.getBindingResult().getFieldError("touchy").getRejectedValue()); |
|
|
|
|
|
|
|
assertEquals("value", tb.getTouchy()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(binder.getBindingResult().hasFieldErrors("spouse.*")); |
|
|
|
|
|
|
|
assertEquals(1, binder.getBindingResult().getFieldErrorCount("spouse.*")); |
|
|
|
|
|
|
|
assertEquals("spouse.name", binder.getBindingResult().getFieldError("spouse.*").getField()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testCustomFormatterForPrimitiveProperty() { |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binder.addCustomFormatter(new Formatter<Integer>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Integer parse(String text, Locale locale) throws ParseException { |
|
|
|
|
|
|
|
return 99; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String print(Integer object, Locale locale) { |
|
|
|
|
|
|
|
return "argh"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, "age"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("age", ""); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
assertEquals("value", tb.getName()); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("argh", binder.getBindingResult().getFieldValue("age")); |
|
|
|
|
|
|
|
assertEquals(99, tb.getAge()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testCustomFormatterForAllStringProperties() { |
|
|
|
|
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binder.addCustomFormatter(new Formatter<String>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String parse(String text, Locale locale) throws ParseException { |
|
|
|
|
|
|
|
return "prefix" + text; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public String print(String object, Locale locale) { |
|
|
|
|
|
|
|
return object.substring(6); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
|
|
|
|
pvs.add("name", "value"); |
|
|
|
|
|
|
|
pvs.add("touchy", "value"); |
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binder.getBindingResult().rejectValue("name", "someCode", "someMessage"); |
|
|
|
|
|
|
|
binder.getBindingResult().rejectValue("touchy", "someCode", "someMessage"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("value", binder.getBindingResult().getFieldValue("name")); |
|
|
|
|
|
|
|
assertEquals("prefixvalue", binder.getBindingResult().getFieldError("name").getRejectedValue()); |
|
|
|
|
|
|
|
assertEquals("prefixvalue", tb.getName()); |
|
|
|
|
|
|
|
assertEquals("value", binder.getBindingResult().getFieldValue("touchy")); |
|
|
|
|
|
|
|
assertEquals("prefixvalue", binder.getBindingResult().getFieldError("touchy").getRejectedValue()); |
|
|
|
|
|
|
|
assertEquals("prefixvalue", tb.getTouchy()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testJavaBeanPropertyConventions() { |
|
|
|
public void testJavaBeanPropertyConventions() { |
|
|
|
Book book = new Book(); |
|
|
|
Book book = new Book(); |
|
|
|
DataBinder binder = new DataBinder(book); |
|
|
|
DataBinder binder = new DataBinder(book); |
|
|
@ -831,6 +1034,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(0, book.getNInStock()); |
|
|
|
assertEquals(0, book.getNInStock()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testValidatorNoErrors() { |
|
|
|
public void testValidatorNoErrors() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setAge(33); |
|
|
|
tb.setAge(33); |
|
|
@ -894,6 +1098,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue(!errors.hasFieldErrors("name")); |
|
|
|
assertTrue(!errors.hasFieldErrors("name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testValidatorWithErrors() { |
|
|
|
public void testValidatorWithErrors() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
@ -962,6 +1167,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(new Integer(0), (errors.getFieldErrors("spouse.age").get(0)).getRejectedValue()); |
|
|
|
assertEquals(new Integer(0), (errors.getFieldErrors("spouse.age").get(0)).getRejectedValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testValidatorWithErrorsAndCodesPrefix() { |
|
|
|
public void testValidatorWithErrorsAndCodesPrefix() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
@ -1033,6 +1239,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(new Integer(0), (errors.getFieldErrors("spouse.age").get(0)).getRejectedValue()); |
|
|
|
assertEquals(new Integer(0), (errors.getFieldErrors("spouse.age").get(0)).getRejectedValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testValidatorWithNestedObjectNull() { |
|
|
|
public void testValidatorWithNestedObjectNull() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
Errors errors = new BeanPropertyBindingResult(tb, "tb"); |
|
|
|
Errors errors = new BeanPropertyBindingResult(tb, "tb"); |
|
|
@ -1051,6 +1258,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(null, (errors.getFieldErrors("spouse").get(0)).getRejectedValue()); |
|
|
|
assertEquals(null, (errors.getFieldErrors("spouse").get(0)).getRejectedValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNestedValidatorWithoutNestedPath() { |
|
|
|
public void testNestedValidatorWithoutNestedPath() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setName("XXX"); |
|
|
|
tb.setName("XXX"); |
|
|
@ -1064,6 +1272,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("tb", (errors.getGlobalErrors().get(0)).getObjectName()); |
|
|
|
assertEquals("tb", (errors.getGlobalErrors().get(0)).getObjectName()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingStringArrayToIntegerSet() { |
|
|
|
public void testBindingStringArrayToIntegerSet() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1091,6 +1300,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertNull(tb.getSet()); |
|
|
|
assertNull(tb.getSet()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingNullToEmptyCollection() { |
|
|
|
public void testBindingNullToEmptyCollection() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1103,6 +1313,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertTrue(tb.getSet().isEmpty()); |
|
|
|
assertTrue(tb.getSet().isEmpty()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingToIndexedField() { |
|
|
|
public void testBindingToIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1141,6 +1352,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("NOT_ROD", errors.getFieldError("map[key1].name").getCodes()[6]); |
|
|
|
assertEquals("NOT_ROD", errors.getFieldError("map[key1].name").getCodes()[6]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingToNestedIndexedField() { |
|
|
|
public void testBindingToNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
@ -1178,6 +1390,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("NOT_ROD", errors.getFieldError("array[0].nestedIndexedBean.list[0].name").getCodes()[8]); |
|
|
|
assertEquals("NOT_ROD", errors.getFieldError("array[0].nestedIndexedBean.list[0].name").getCodes()[8]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testEditorForNestedIndexedField() { |
|
|
|
public void testEditorForNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
@ -1203,6 +1416,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name")); |
|
|
|
assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSpecificEditorForNestedIndexedField() { |
|
|
|
public void testSpecificEditorForNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
@ -1228,6 +1442,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name")); |
|
|
|
assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testInnerSpecificEditorForNestedIndexedField() { |
|
|
|
public void testInnerSpecificEditorForNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
@ -1253,6 +1468,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name")); |
|
|
|
assertEquals("test2", binder.getBindingResult().getFieldValue("array[1].nestedIndexedBean.list[1].name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDirectBindingToIndexedField() { |
|
|
|
public void testDirectBindingToIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1305,6 +1521,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[4]); |
|
|
|
assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[4]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() { |
|
|
|
public void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1335,6 +1552,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[5]); |
|
|
|
assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[5]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() { |
|
|
|
public void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1365,6 +1583,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[5]); |
|
|
|
assertEquals("NOT_NULL", errors.getFieldError("map[key0]").getCodes()[5]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCustomEditorWithSubclass() { |
|
|
|
public void testCustomEditorWithSubclass() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1398,6 +1617,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("arraya", errors.getFieldValue("array[0]")); |
|
|
|
assertEquals("arraya", errors.getFieldValue("array[0]")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindToStringArrayWithArrayEditor() { |
|
|
|
public void testBindToStringArrayWithArrayEditor() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1416,6 +1636,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("b2", tb.getStringArray()[1]); |
|
|
|
assertEquals("b2", tb.getStringArray()[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindToStringArrayWithComponentEditor() { |
|
|
|
public void testBindToStringArrayWithComponentEditor() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1434,6 +1655,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("Xb2", tb.getStringArray()[1]); |
|
|
|
assertEquals("Xb2", tb.getStringArray()[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingErrors() { |
|
|
|
public void testBindingErrors() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -1460,6 +1682,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("Field Person Age did not have correct type", msg); |
|
|
|
assertEquals("Field Person Age did not have correct type", msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAddAllErrors() { |
|
|
|
public void testAddAllErrors() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
@ -1478,6 +1701,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("badName", nameError.getCode()); |
|
|
|
assertEquals("badName", nameError.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindingWithResortedList() { |
|
|
|
public void testBindingWithResortedList() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
@ -1495,6 +1719,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(tb1.getName(), binder.getBindingResult().getFieldValue("list[1].name")); |
|
|
|
assertEquals(tb1.getName(), binder.getBindingResult().getFieldValue("list[1].name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testRejectWithoutDefaultMessage() throws Exception { |
|
|
|
public void testRejectWithoutDefaultMessage() throws Exception { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setName("myName"); |
|
|
|
tb.setName("myName"); |
|
|
@ -1512,6 +1737,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US)); |
|
|
|
assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testBindExceptionSerializable() throws Exception { |
|
|
|
public void testBindExceptionSerializable() throws Exception { |
|
|
|
SerializablePerson tb = new SerializablePerson(); |
|
|
|
SerializablePerson tb = new SerializablePerson(); |
|
|
|
tb.setName("myName"); |
|
|
|
tb.setName("myName"); |
|
|
@ -1540,6 +1766,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("myName", ex2.getFieldValue("name")); |
|
|
|
assertEquals("myName", ex2.getFieldValue("name")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testTrackDisallowedFields() throws Exception { |
|
|
|
public void testTrackDisallowedFields() throws Exception { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
@ -1559,6 +1786,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals("beanName", disallowedFields[0]); |
|
|
|
assertEquals("beanName", disallowedFields[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAutoGrowWithinDefaultLimit() throws Exception { |
|
|
|
public void testAutoGrowWithinDefaultLimit() throws Exception { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
@ -1570,6 +1798,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(5, testBean.getFriends().size()); |
|
|
|
assertEquals(5, testBean.getFriends().size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAutoGrowBeyondDefaultLimit() throws Exception { |
|
|
|
public void testAutoGrowBeyondDefaultLimit() throws Exception { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
@ -1586,6 +1815,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAutoGrowWithinCustomLimit() throws Exception { |
|
|
|
public void testAutoGrowWithinCustomLimit() throws Exception { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
@ -1598,6 +1828,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(5, testBean.getFriends().size()); |
|
|
|
assertEquals(5, testBean.getFriends().size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAutoGrowBeyondCustomLimit() throws Exception { |
|
|
|
public void testAutoGrowBeyondCustomLimit() throws Exception { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
@ -1615,6 +1846,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNestedGrowingList() { |
|
|
|
public void testNestedGrowingList() { |
|
|
|
Form form = new Form(); |
|
|
|
Form form = new Form(); |
|
|
|
DataBinder binder = new DataBinder(form, "form"); |
|
|
|
DataBinder binder = new DataBinder(form, "form"); |
|
|
@ -1630,6 +1862,7 @@ public class DataBinderTests extends TestCase { |
|
|
|
assertEquals(2, list.size()); |
|
|
|
assertEquals(2, list.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
public void testFieldErrorAccessVariations() throws Exception { |
|
|
|
public void testFieldErrorAccessVariations() throws Exception { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|