Example usage for org.springframework.beans PropertyBatchUpdateException getExceptionCount

List of usage examples for org.springframework.beans PropertyBatchUpdateException getExceptionCount

Introduction

In this page you can find the example usage for org.springframework.beans PropertyBatchUpdateException getExceptionCount.

Prototype

public final int getExceptionCount() 

Source Link

Document

If this returns 0, no errors were encountered during binding.

Usage

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  .j  a  v a 2s .  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.BeanWrapperTests.java

@Test
public void test2Invalid() {
    TestBean t = new TestBean();
    String newName = "tony";
    String invalidTouchy = ".valid";
    try {/*from   w  w  w  . ja  va2 s .  c o m*/
        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));
    }
}