List of usage examples for org.springframework.beans PropertyBatchUpdateException getPropertyAccessException
@Nullable
public PropertyAccessException getPropertyAccessException(String propertyName)
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testMapAccessWithTypeConversion() { IndexedTestBean bean = new IndexedTestBean(); BeanWrapper bw = new JuffrouSpringBeanWrapper(bean); bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() { @Override//w w w.ja va2s . c o m public void setAsText(String text) throws IllegalArgumentException { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(); } setValue(new TestBean(text)); } }); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("map[key1]", "rod"); pvs.add("map[key2]", "rob"); bw.setPropertyValues(pvs); assertEquals("rod", ((TestBean) bean.getMap().get("key1")).getName()); assertEquals("rob", ((TestBean) bean.getMap().get("key2")).getName()); pvs = new MutablePropertyValues(); pvs.add("map[key1]", "rod"); pvs.add("map[key2]", ""); try { bw.setPropertyValues(pvs); fail("Should have thrown TypeMismatchException"); } catch (PropertyBatchUpdateException ex) { PropertyAccessException pae = ex.getPropertyAccessException("map[key2]"); assertTrue(pae instanceof TypeMismatchException); } }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void test2Invalid() { TestBean t = new TestBean(); String newName = "tony"; String invalidTouchy = ".valid"; try {/*from w ww .ja va2 s. c om*/ BeanWrapper bw = new JuffrouSpringBeanWrapper(t); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("age", "foobar")); pvs.addPropertyValue(new PropertyValue("name", newName)); pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy)); bw.setPropertyValues(pvs); fail("Should throw exception when everything is valid"); } catch (PropertyBatchUpdateException ex) { assertTrue("Must contain 2 exceptions", ex.getExceptionCount() == 2); // Test validly set property matches assertTrue("Validly set property must stick", t.getName().equals(newName)); assertTrue("Invalidly set property must retain old value", t.getAge() == 0); assertTrue("New value of dodgy setter must be available through exception", ex.getPropertyAccessException("touchy").getPropertyChangeEvent().getNewValue() .equals(invalidTouchy)); } }
From source file:org.springframework.beans.AbstractPropertyAccessorTests.java
@Test public void setMapPropertyWithTypeConversion() { IndexedTestBean target = new IndexedTestBean(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(TestBean.class, new PropertyEditorSupport() { @Override/*from w w w . jav a2 s.c o m*/ public void setAsText(String text) throws IllegalArgumentException { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(); } setValue(new TestBean(text)); } }); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("map[key1]", "rod"); pvs.add("map[key2]", "rob"); accessor.setPropertyValues(pvs); assertEquals("rod", ((TestBean) target.getMap().get("key1")).getName()); assertEquals("rob", ((TestBean) target.getMap().get("key2")).getName()); pvs = new MutablePropertyValues(); pvs.add("map[key1]", "rod"); pvs.add("map[key2]", ""); try { accessor.setPropertyValues(pvs); fail("Should have thrown TypeMismatchException"); } catch (PropertyBatchUpdateException ex) { PropertyAccessException pae = ex.getPropertyAccessException("map[key2]"); assertTrue(pae instanceof TypeMismatchException); } }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void test2Invalid() { TestBean t = new TestBean(); String newName = "tony"; String invalidTouchy = ".valid"; try {/*www .j av a2s . c om*/ BeanWrapper bw = new BeanWrapperImpl(t); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.addPropertyValue(new PropertyValue("age", "foobar")); pvs.addPropertyValue(new PropertyValue("name", newName)); pvs.addPropertyValue(new PropertyValue("touchy", invalidTouchy)); bw.setPropertyValues(pvs); fail("Should throw exception when everything is valid"); } catch (PropertyBatchUpdateException ex) { assertTrue("Must contain 2 exceptions", ex.getExceptionCount() == 2); // Test validly set property matches assertTrue("Validly set property must stick", t.getName().equals(newName)); assertTrue("Invalidly set property must retain old value", t.getAge() == 0); assertTrue("New value of dodgy setter must be available through exception", ex.getPropertyAccessException("touchy").getPropertyChangeEvent().getNewValue() .equals(invalidTouchy)); } }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void testMapAccessWithTypeConversion() { IndexedTestBean bean = new IndexedTestBean(); BeanWrapper bw = new BeanWrapperImpl(bean); bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() { @Override// w ww. j a va2 s. c om public void setAsText(String text) throws IllegalArgumentException { if (!StringUtils.hasLength(text)) { throw new IllegalArgumentException(); } setValue(new TestBean(text)); } }); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("map[key1]", "rod"); pvs.add("map[key2]", "rob"); bw.setPropertyValues(pvs); assertEquals("rod", ((TestBean) bean.getMap().get("key1")).getName()); assertEquals("rob", ((TestBean) bean.getMap().get("key2")).getName()); pvs = new MutablePropertyValues(); pvs.add("map[key1]", "rod"); pvs.add("map[key2]", ""); try { bw.setPropertyValues(pvs); fail("Should have thrown TypeMismatchException"); } catch (PropertyBatchUpdateException ex) { PropertyAccessException pae = ex.getPropertyAccessException("map[key2]"); assertTrue(pae instanceof TypeMismatchException); } }