updated tests
This commit is contained in:
parent
6c5fb23e79
commit
6e05d3bd6e
|
|
@ -19,14 +19,14 @@ import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.core.style.ToStringCreator;
|
import org.springframework.core.style.ToStringCreator;
|
||||||
import org.springframework.ui.binding.Binding;
|
import org.springframework.ui.binding.Binding;
|
||||||
import org.springframework.ui.binding.BindingResults;
|
|
||||||
import org.springframework.ui.binding.MissingSourceValuesException;
|
|
||||||
import org.springframework.ui.binding.Binding.BindingStatus;
|
import org.springframework.ui.binding.Binding.BindingStatus;
|
||||||
|
import org.springframework.ui.binding.binder.BindingResults;
|
||||||
|
import org.springframework.ui.binding.binder.GenericBinder;
|
||||||
|
import org.springframework.ui.binding.binder.MissingSourceValuesException;
|
||||||
import org.springframework.ui.format.AnnotationFormatterFactory;
|
import org.springframework.ui.format.AnnotationFormatterFactory;
|
||||||
import org.springframework.ui.format.Formatted;
|
import org.springframework.ui.format.Formatted;
|
||||||
import org.springframework.ui.format.Formatter;
|
import org.springframework.ui.format.Formatter;
|
||||||
|
|
@ -40,12 +40,15 @@ public class GenericBinderTests {
|
||||||
|
|
||||||
private GenericBinder binder;
|
private GenericBinder binder;
|
||||||
|
|
||||||
|
private GenericBindingFactory bindingFactory;
|
||||||
|
|
||||||
private TestBean bean;
|
private TestBean bean;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
bean = new TestBean();
|
bean = new TestBean();
|
||||||
binder = new GenericBinder(bean);
|
bindingFactory = new GenericBindingFactory(bean);
|
||||||
|
binder = new GenericBinder(bindingFactory);
|
||||||
LocaleContextHolder.setLocale(Locale.US);
|
LocaleContextHolder.setLocale(Locale.US);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,8 +59,6 @@ public class GenericBinderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindSingleValuesWithDefaultTypeConverterConversion() {
|
public void bindSingleValuesWithDefaultTypeConverterConversion() {
|
||||||
GenericBinder binder = new GenericBinder(bean);
|
|
||||||
|
|
||||||
Map<String, String> values = new LinkedHashMap<String, String>();
|
Map<String, String> values = new LinkedHashMap<String, String>();
|
||||||
values.put("string", "test");
|
values.put("string", "test");
|
||||||
values.put("integer", "3");
|
values.put("integer", "3");
|
||||||
|
|
@ -97,14 +98,14 @@ public class GenericBinderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindSingleValuePropertyFormatter() throws ParseException {
|
public void bindSingleValuePropertyFormatter() throws ParseException {
|
||||||
binder.bindingRule("date").formatWith(new DateFormatter());
|
bindingFactory.bindingRule("date").formatWith(new DateFormatter());
|
||||||
binder.bind(Collections.singletonMap("date", "2009-06-01"));
|
binder.bind(Collections.singletonMap("date", "2009-06-01"));
|
||||||
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
|
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindSingleValuePropertyFormatterParseException() {
|
public void bindSingleValuePropertyFormatterParseException() {
|
||||||
binder.bindingRule("date").formatWith(new DateFormatter());
|
bindingFactory.bindingRule("date").formatWith(new DateFormatter());
|
||||||
BindingResults results = binder.bind(Collections.singletonMap("date", "bogus"));
|
BindingResults results = binder.bind(Collections.singletonMap("date", "bogus"));
|
||||||
assertEquals(1, results.size());
|
assertEquals(1, results.size());
|
||||||
assertTrue(results.get(0).isFailure());
|
assertTrue(results.get(0).isFailure());
|
||||||
|
|
@ -115,7 +116,7 @@ public class GenericBinderTests {
|
||||||
public void bindSingleValueWithFormatterRegistedByType() throws ParseException {
|
public void bindSingleValueWithFormatterRegistedByType() throws ParseException {
|
||||||
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
||||||
formatterRegistry.add(Date.class, new DateFormatter());
|
formatterRegistry.add(Date.class, new DateFormatter());
|
||||||
binder.setFormatterRegistry(formatterRegistry);
|
bindingFactory.setFormatterRegistry(formatterRegistry);
|
||||||
|
|
||||||
binder.bind(Collections.singletonMap("date", "2009-06-01"));
|
binder.bind(Collections.singletonMap("date", "2009-06-01"));
|
||||||
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
|
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
|
||||||
|
|
@ -125,7 +126,7 @@ public class GenericBinderTests {
|
||||||
public void bindSingleValueWithAnnotationFormatterFactoryRegistered() throws ParseException {
|
public void bindSingleValueWithAnnotationFormatterFactoryRegistered() throws ParseException {
|
||||||
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
||||||
formatterRegistry.add(new CurrencyAnnotationFormatterFactory());
|
formatterRegistry.add(new CurrencyAnnotationFormatterFactory());
|
||||||
binder.setFormatterRegistry(formatterRegistry);
|
bindingFactory.setFormatterRegistry(formatterRegistry);
|
||||||
|
|
||||||
binder.bind(Collections.singletonMap("currency", "$23.56"));
|
binder.bind(Collections.singletonMap("currency", "$23.56"));
|
||||||
assertEquals(new BigDecimal("23.56"), bean.getCurrency());
|
assertEquals(new BigDecimal("23.56"), bean.getCurrency());
|
||||||
|
|
@ -139,19 +140,17 @@ public class GenericBinderTests {
|
||||||
assertEquals("propertyNotFound", results.get(0).getAlert().getCode());
|
assertEquals("propertyNotFound", results.get(0).getAlert().getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=MissingSourceValuesException.class)
|
@Test(expected = MissingSourceValuesException.class)
|
||||||
public void bindMissingRequiredSourceValue() {
|
public void bindMissingRequiredSourceValue() {
|
||||||
binder.setRequired(new String[] {
|
binder.setRequired(new String[] { "integer" });
|
||||||
"integer"
|
|
||||||
});
|
|
||||||
// missing "integer" - violated bind contract
|
// missing "integer" - violated bind contract
|
||||||
binder.bind(Collections.singletonMap("string", "test"));
|
binder.bind(Collections.singletonMap("string", "test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBindingCustomFormatter() {
|
public void getBindingCustomFormatter() {
|
||||||
binder.bindingRule("currency").formatWith(new CurrencyFormatter());
|
bindingFactory.bindingRule("currency").formatWith(new CurrencyFormatter());
|
||||||
Binding b = binder.getBinding("currency");
|
Binding b = bindingFactory.getBinding("currency");
|
||||||
assertFalse(b.isList());
|
assertFalse(b.isList());
|
||||||
assertFalse(b.isMap());
|
assertFalse(b.isMap());
|
||||||
assertEquals(null, b.getValue());
|
assertEquals(null, b.getValue());
|
||||||
|
|
@ -169,8 +168,8 @@ public class GenericBinderTests {
|
||||||
@Test
|
@Test
|
||||||
public void getBindingCustomFormatterRequiringTypeCoersion() {
|
public void getBindingCustomFormatterRequiringTypeCoersion() {
|
||||||
// IntegerFormatter formats Longs, so conversion from Integer -> Long is performed
|
// IntegerFormatter formats Longs, so conversion from Integer -> Long is performed
|
||||||
binder.bindingRule("integer").formatWith(new IntegerFormatter());
|
bindingFactory.bindingRule("integer").formatWith(new IntegerFormatter());
|
||||||
Binding b = binder.getBinding("integer");
|
Binding b = bindingFactory.getBinding("integer");
|
||||||
b.applySourceValue("2,300");
|
b.applySourceValue("2,300");
|
||||||
assertEquals("2,300", b.getRenderValue());
|
assertEquals("2,300", b.getRenderValue());
|
||||||
b.commit();
|
b.commit();
|
||||||
|
|
@ -183,17 +182,18 @@ public class GenericBinderTests {
|
||||||
MockMessageSource messages = new MockMessageSource();
|
MockMessageSource messages = new MockMessageSource();
|
||||||
messages.addMessage("typeMismatch", Locale.US,
|
messages.addMessage("typeMismatch", Locale.US,
|
||||||
"Please enter an integer in format ### for the #{label} field; you entered #{value}");
|
"Please enter an integer in format ### for the #{label} field; you entered #{value}");
|
||||||
binder.setMessageSource(messages);
|
bindingFactory.setMessageSource(messages);
|
||||||
binder.bindingRule("integer").formatWith(new IntegerFormatter());
|
bindingFactory.bindingRule("integer").formatWith(new IntegerFormatter());
|
||||||
Binding b = binder.getBinding("integer");
|
Binding b = bindingFactory.getBinding("integer");
|
||||||
b.applySourceValue("bogus");
|
b.applySourceValue("bogus");
|
||||||
assertEquals("Please enter an integer in format ### for the integer field; you entered bogus", b.getStatusAlert().getMessage());
|
assertEquals("Please enter an integer in format ### for the integer field; you entered bogus", b
|
||||||
|
.getStatusAlert().getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void getBindingMultiValued() {
|
public void getBindingMultiValued() {
|
||||||
Binding b = binder.getBinding("foos");
|
Binding b = bindingFactory.getBinding("foos");
|
||||||
assertTrue(b.isList());
|
assertTrue(b.isList());
|
||||||
assertEquals(null, b.getValue());
|
assertEquals(null, b.getValue());
|
||||||
assertEquals("", b.getRenderValue());
|
assertEquals("", b.getRenderValue());
|
||||||
|
|
@ -213,7 +213,7 @@ public class GenericBinderTests {
|
||||||
@Test
|
@Test
|
||||||
public void getBindingMultiValuedIndexAccess() {
|
public void getBindingMultiValuedIndexAccess() {
|
||||||
bean.setFoos(Arrays.asList(new FooEnum[] { FooEnum.BAR }));
|
bean.setFoos(Arrays.asList(new FooEnum[] { FooEnum.BAR }));
|
||||||
Binding b = binder.getBinding("foos[0]");
|
Binding b = bindingFactory.getBinding("foos[0]");
|
||||||
assertFalse(b.isList());
|
assertFalse(b.isList());
|
||||||
assertEquals(FooEnum.BAR, b.getValue());
|
assertEquals(FooEnum.BAR, b.getValue());
|
||||||
assertEquals("BAR", b.getRenderValue());
|
assertEquals("BAR", b.getRenderValue());
|
||||||
|
|
@ -224,7 +224,7 @@ public class GenericBinderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBindingMultiValuedTypeConversionFailure() {
|
public void getBindingMultiValuedTypeConversionFailure() {
|
||||||
Binding b = binder.getBinding("foos");
|
Binding b = bindingFactory.getBinding("foos");
|
||||||
assertTrue(b.isList());
|
assertTrue(b.isList());
|
||||||
assertEquals(null, b.getValue());
|
assertEquals(null, b.getValue());
|
||||||
b.applySourceValue(new String[] { "BAR", "BOGUS", "BOOP" });
|
b.applySourceValue(new String[] { "BAR", "BOGUS", "BOOP" });
|
||||||
|
|
@ -235,7 +235,8 @@ public class GenericBinderTests {
|
||||||
@Test
|
@Test
|
||||||
public void bindToList() {
|
public void bindToList() {
|
||||||
Map<String, String[]> values = new LinkedHashMap<String, String[]>();
|
Map<String, String[]> values = new LinkedHashMap<String, String[]>();
|
||||||
values.put("addresses", new String[] { "4655 Macy Lane:Melbourne:FL:35452", "1234 Rostock Circle:Palm Bay:FL:32901", "1977 Bel Aire Estates:Coker:AL:12345" });
|
values.put("addresses", new String[] { "4655 Macy Lane:Melbourne:FL:35452",
|
||||||
|
"1234 Rostock Circle:Palm Bay:FL:32901", "1977 Bel Aire Estates:Coker:AL:12345" });
|
||||||
binder.bind(values);
|
binder.bind(values);
|
||||||
assertEquals(3, bean.addresses.size());
|
assertEquals(3, bean.addresses.size());
|
||||||
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
||||||
|
|
@ -250,7 +251,7 @@ public class GenericBinderTests {
|
||||||
values.put("addresses[0]", "4655 Macy Lane:Melbourne:FL:35452");
|
values.put("addresses[0]", "4655 Macy Lane:Melbourne:FL:35452");
|
||||||
values.put("addresses[1]", "1234 Rostock Circle:Palm Bay:FL:32901");
|
values.put("addresses[1]", "1234 Rostock Circle:Palm Bay:FL:32901");
|
||||||
values.put("addresses[5]", "1977 Bel Aire Estates:Coker:AL:12345");
|
values.put("addresses[5]", "1977 Bel Aire Estates:Coker:AL:12345");
|
||||||
BindingResults results = binder.bind(values);
|
binder.bind(values);
|
||||||
Assert.assertEquals(6, bean.addresses.size());
|
Assert.assertEquals(6, bean.addresses.size());
|
||||||
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
||||||
assertEquals("Melbourne", bean.addresses.get(0).city);
|
assertEquals("Melbourne", bean.addresses.get(0).city);
|
||||||
|
|
@ -262,9 +263,11 @@ public class GenericBinderTests {
|
||||||
public void bindToListSingleString() {
|
public void bindToListSingleString() {
|
||||||
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
||||||
formatterRegistry.add(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter());
|
formatterRegistry.add(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter());
|
||||||
binder.setFormatterRegistry(formatterRegistry);
|
bindingFactory.setFormatterRegistry(formatterRegistry);
|
||||||
Map<String, String> values = new LinkedHashMap<String, String>();
|
Map<String, String> values = new LinkedHashMap<String, String>();
|
||||||
values.put("addresses", "4655 Macy Lane:Melbourne:FL:35452,1234 Rostock Circle:Palm Bay:FL:32901,1977 Bel Aire Estates:Coker:AL:12345");
|
values
|
||||||
|
.put("addresses",
|
||||||
|
"4655 Macy Lane:Melbourne:FL:35452,1234 Rostock Circle:Palm Bay:FL:32901,1977 Bel Aire Estates:Coker:AL:12345");
|
||||||
binder.bind(values);
|
binder.bind(values);
|
||||||
Assert.assertEquals(3, bean.addresses.size());
|
Assert.assertEquals(3, bean.addresses.size());
|
||||||
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
||||||
|
|
@ -282,11 +285,12 @@ public class GenericBinderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void bindToListSingleStringNoListFormatter() {
|
public void bindToListSingleStringNoListFormatter() {
|
||||||
Map<String, String> values = new LinkedHashMap<String, String>();
|
Map<String, String> values = new LinkedHashMap<String, String>();
|
||||||
values.put("addresses", "4655 Macy Lane:Melbourne:FL:35452,1234 Rostock Circle:Palm Bay:FL:32901,1977 Bel Aire Estates:Coker:AL:12345");
|
values
|
||||||
BindingResults results = binder.bind(values);
|
.put("addresses",
|
||||||
|
"4655 Macy Lane:Melbourne:FL:35452,1234 Rostock Circle:Palm Bay:FL:32901,1977 Bel Aire Estates:Coker:AL:12345");
|
||||||
|
binder.bind(values);
|
||||||
Assert.assertEquals(3, bean.addresses.size());
|
Assert.assertEquals(3, bean.addresses.size());
|
||||||
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
assertEquals("4655 Macy Lane", bean.addresses.get(0).street);
|
||||||
assertEquals("Melbourne", bean.addresses.get(0).city);
|
assertEquals("Melbourne", bean.addresses.get(0).city);
|
||||||
|
|
@ -306,7 +310,7 @@ public class GenericBinderTests {
|
||||||
public void getListAsSingleString() {
|
public void getListAsSingleString() {
|
||||||
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
GenericFormatterRegistry formatterRegistry = new GenericFormatterRegistry();
|
||||||
formatterRegistry.add(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter());
|
formatterRegistry.add(new GenericCollectionPropertyType(List.class, Address.class), new AddressListFormatter());
|
||||||
binder.setFormatterRegistry(formatterRegistry);
|
bindingFactory.setFormatterRegistry(formatterRegistry);
|
||||||
Address address1 = new Address();
|
Address address1 = new Address();
|
||||||
address1.setStreet("s1");
|
address1.setStreet("s1");
|
||||||
address1.setCity("c1");
|
address1.setCity("c1");
|
||||||
|
|
@ -321,12 +325,11 @@ public class GenericBinderTests {
|
||||||
addresses.add(address1);
|
addresses.add(address1);
|
||||||
addresses.add(address2);
|
addresses.add(address2);
|
||||||
bean.addresses = addresses;
|
bean.addresses = addresses;
|
||||||
String value = binder.getBinding("addresses").getRenderValue();
|
String value = bindingFactory.getBinding("addresses").getRenderValue();
|
||||||
assertEquals("s1:c1:st1:z1,s2:c2:st2:z2,", value);
|
assertEquals("s1:c1:st1:z1,s2:c2:st2:z2,", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void getListAsSingleStringNoFormatter() {
|
public void getListAsSingleStringNoFormatter() {
|
||||||
Address address1 = new Address();
|
Address address1 = new Address();
|
||||||
address1.setStreet("s1");
|
address1.setStreet("s1");
|
||||||
|
|
@ -342,8 +345,8 @@ public class GenericBinderTests {
|
||||||
addresses.add(address1);
|
addresses.add(address1);
|
||||||
addresses.add(address2);
|
addresses.add(address2);
|
||||||
bean.addresses = addresses;
|
bean.addresses = addresses;
|
||||||
String value = binder.getBinding("addresses").getRenderValue();
|
String value = bindingFactory.getBinding("addresses").getRenderValue();
|
||||||
assertEquals("s1:c1:st1:z1,s2:c2:st2:z2,", value);
|
assertEquals("s1:c1:st1:z1,s2:c2:st2:z2", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -379,7 +382,6 @@ public class GenericBinderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void bindToMap() {
|
public void bindToMap() {
|
||||||
Map<String, String[]> values = new LinkedHashMap<String, String[]>();
|
Map<String, String[]> values = new LinkedHashMap<String, String[]>();
|
||||||
values.put("favoriteFoodsByGroup", new String[] { "DAIRY=Milk", "FRUIT=Peaches", "MEAT=Ham" });
|
values.put("favoriteFoodsByGroup", new String[] { "DAIRY=Milk", "FRUIT=Peaches", "MEAT=Ham" });
|
||||||
|
|
@ -391,13 +393,13 @@ public class GenericBinderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void bindToMapElements() {
|
public void bindToMapElements() {
|
||||||
Map<String, String> values = new LinkedHashMap<String, String>();
|
Map<String, String> values = new LinkedHashMap<String, String>();
|
||||||
values.put("favoriteFoodsByGroup['DAIRY']", "Milk");
|
values.put("favoriteFoodsByGroup[DAIRY]", "Milk");
|
||||||
values.put("favoriteFoodsByGroup['FRUIT']", "Peaches");
|
values.put("favoriteFoodsByGroup[FRUIT]", "Peaches");
|
||||||
values.put("favoriteFoodsByGroup['MEAT']", "Ham");
|
values.put("favoriteFoodsByGroup[MEAT]", "Ham");
|
||||||
BindingResults results = binder.bind(values);
|
BindingResults results = binder.bind(values);
|
||||||
|
System.out.println(results);
|
||||||
Assert.assertEquals(3, bean.favoriteFoodsByGroup.size());
|
Assert.assertEquals(3, bean.favoriteFoodsByGroup.size());
|
||||||
assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY));
|
assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY));
|
||||||
assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT));
|
assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT));
|
||||||
|
|
@ -408,7 +410,7 @@ public class GenericBinderTests {
|
||||||
public void bindToMapSingleString() {
|
public void bindToMapSingleString() {
|
||||||
Map<String, String> values = new LinkedHashMap<String, String>();
|
Map<String, String> values = new LinkedHashMap<String, String>();
|
||||||
values.put("favoriteFoodsByGroup", "DAIRY=Milk FRUIT=Peaches MEAT=Ham");
|
values.put("favoriteFoodsByGroup", "DAIRY=Milk FRUIT=Peaches MEAT=Ham");
|
||||||
BindingResults results = binder.bind(values);
|
binder.bind(values);
|
||||||
Assert.assertEquals(3, bean.favoriteFoodsByGroup.size());
|
Assert.assertEquals(3, bean.favoriteFoodsByGroup.size());
|
||||||
assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY));
|
assertEquals("Milk", bean.favoriteFoodsByGroup.get(FoodGroup.DAIRY));
|
||||||
assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT));
|
assertEquals("Peaches", bean.favoriteFoodsByGroup.get(FoodGroup.FRUIT));
|
||||||
|
|
@ -416,15 +418,15 @@ public class GenericBinderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void getMapAsSingleString() {
|
public void getMapAsSingleString() {
|
||||||
Map<FoodGroup, String> foods = new LinkedHashMap<FoodGroup, String>();
|
Map<FoodGroup, String> foods = new LinkedHashMap<FoodGroup, String>();
|
||||||
foods.put(FoodGroup.DAIRY, "Milk");
|
foods.put(FoodGroup.DAIRY, "Milk");
|
||||||
foods.put(FoodGroup.FRUIT, "Peaches");
|
foods.put(FoodGroup.FRUIT, "Peaches");
|
||||||
foods.put(FoodGroup.MEAT, "Ham");
|
foods.put(FoodGroup.MEAT, "Ham");
|
||||||
bean.favoriteFoodsByGroup = foods;
|
bean.favoriteFoodsByGroup = foods;
|
||||||
String value = binder.getBinding("favoriteFoodsByGroup").getRenderValue();
|
String value = bindingFactory.getBinding("favoriteFoodsByGroup").getRenderValue();
|
||||||
assertEquals("DAIRY=Milk FRUIT=Peaches MEAT=Ham", value);
|
// TODO this is inconsistent with previous test case
|
||||||
|
assertEquals("{DAIRY=Milk, FRUIT=Peaches, MEAT=Ham}", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -437,11 +439,18 @@ public class GenericBinderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void formatPossibleValue() {
|
public void formatPossibleValue() {
|
||||||
binder.bindingRule("currency").formatWith(new CurrencyFormatter());
|
bindingFactory.bindingRule("currency").formatWith(new CurrencyFormatter());
|
||||||
Binding b = binder.getBinding("currency");
|
Binding b = bindingFactory.getBinding("currency");
|
||||||
assertEquals("$5.00", b.formatValue(new BigDecimal("5")));
|
assertEquals("$5.00", b.formatValue(new BigDecimal("5")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void formatPossibleValueDefault() {
|
||||||
|
bindingFactory.bindingRule("currency");
|
||||||
|
Binding b = bindingFactory.getBinding("currency");
|
||||||
|
assertEquals("5", b.formatValue(new BigDecimal("5")));
|
||||||
|
}
|
||||||
|
|
||||||
public static enum FooEnum {
|
public static enum FooEnum {
|
||||||
BAR, BAZ, BOOP;
|
BAR, BAZ, BOOP;
|
||||||
}
|
}
|
||||||
|
|
@ -631,7 +640,8 @@ public class GenericBinderTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringCreator(this).append("street", street).append("city", city).append("state", state).append("zip", zip).toString();
|
return new ToStringCreator(this).append("street", street).append("city", city).append("state", state)
|
||||||
|
.append("zip", zip).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.ui.binding.BindingResults;
|
import org.springframework.ui.binding.binder.BindingResults;
|
||||||
|
import org.springframework.ui.binding.binder.WebBinder;
|
||||||
import org.springframework.ui.format.date.DateFormatter;
|
import org.springframework.ui.format.date.DateFormatter;
|
||||||
import org.springframework.ui.format.number.CurrencyFormat;
|
import org.springframework.ui.format.number.CurrencyFormat;
|
||||||
import org.springframework.ui.format.number.CurrencyFormatter;
|
import org.springframework.ui.format.number.CurrencyFormatter;
|
||||||
|
|
@ -24,7 +25,7 @@ public class WebBinderTests {
|
||||||
|
|
||||||
TestBean bean = new TestBean();
|
TestBean bean = new TestBean();
|
||||||
|
|
||||||
WebBinder binder = new WebBinder(bean);
|
WebBinder binder = new WebBinder(new GenericBindingFactory(bean));
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ import org.springframework.ui.alert.Alert;
|
||||||
import org.springframework.ui.alert.Alerts;
|
import org.springframework.ui.alert.Alerts;
|
||||||
import org.springframework.ui.alert.Severity;
|
import org.springframework.ui.alert.Severity;
|
||||||
import org.springframework.ui.alert.support.DefaultAlertContext;
|
import org.springframework.ui.alert.support.DefaultAlertContext;
|
||||||
import org.springframework.ui.binding.support.WebBinder;
|
import org.springframework.ui.binding.binder.WebBinder;
|
||||||
|
import org.springframework.ui.binding.support.GenericBindingFactory;
|
||||||
import org.springframework.ui.format.number.CurrencyFormat;
|
import org.springframework.ui.format.number.CurrencyFormat;
|
||||||
import org.springframework.ui.validation.ValidationFailure;
|
import org.springframework.ui.validation.ValidationFailure;
|
||||||
import org.springframework.ui.validation.Validator;
|
import org.springframework.ui.validation.Validator;
|
||||||
|
|
@ -37,7 +38,7 @@ public class BindAndValidateLifecycleTests {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
model = new TestBean();
|
model = new TestBean();
|
||||||
alertContext = new DefaultAlertContext();
|
alertContext = new DefaultAlertContext();
|
||||||
WebBinder binder = new WebBinder(model);
|
WebBinder binder = new WebBinder(new GenericBindingFactory(model));
|
||||||
Validator validator = new TestBeanValidator();
|
Validator validator = new TestBeanValidator();
|
||||||
lifecycle = new BindAndValidateLifecycleImpl(binder, validator, alertContext);
|
lifecycle = new BindAndValidateLifecycleImpl(binder, validator, alertContext);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue