List of usage examples for org.springframework.beans NotWritablePropertyException getPossibleMatches
@Nullable
public String[] getPossibleMatches()
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testPossibleMatches() { TestBean tb = new TestBean(); try {//from w w w . j a v a 2 s . c o m BeanWrapper bw = new JuffrouSpringBeanWrapper(tb); bw.setPropertyValue("ag", "foobar"); fail("Should throw exception on invalid property"); } catch (NotWritablePropertyException ex) { // expected assertEquals(1, ex.getPossibleMatches().length); assertEquals("age", ex.getPossibleMatches()[0]); } }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testAlternativesForTypo() { IntelliBean ib = new IntelliBean(); BeanWrapper bw = new JuffrouSpringBeanWrapper(ib); try {/*ww w . j a v a 2 s. co m*/ bw.setPropertyValue("names", "Alef"); } catch (NotWritablePropertyException ex) { assertNotNull("Possible matches not determined", ex.getPossibleMatches()); assertEquals("Invalid amount of alternatives", 1, ex.getPossibleMatches().length); } }
From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java
@Test public void testAlternativesForTypos() { IntelliBean ib = new IntelliBean(); BeanWrapper bw = new JuffrouSpringBeanWrapper(ib); try {/*from w w w. ja v a 2 s.c om*/ bw.setPropertyValue("mystring", "Arjen"); } catch (NotWritablePropertyException ex) { assertNotNull("Possible matches not determined", ex.getPossibleMatches()); assertEquals("Invalid amount of alternatives", 3, ex.getPossibleMatches().length); } }
From source file:org.springframework.beans.AbstractPropertyAccessorTests.java
@Test public void setUnknownProperty() { Simple target = new Simple("John", 2); AbstractPropertyAccessor accessor = createAccessor(target); try {//from w w w . j a va2 s . c o m accessor.setPropertyValue("name1", "value"); fail("Should have failed to set an unknown property."); } catch (NotWritablePropertyException e) { assertEquals(Simple.class, e.getBeanClass()); assertEquals("name1", e.getPropertyName()); assertEquals("Invalid number of possible matches", 1, e.getPossibleMatches().length); assertEquals("name", e.getPossibleMatches()[0]); } }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void testPossibleMatches() { TestBean tb = new TestBean(); try {/*from ww w . j a v a 2 s. c om*/ BeanWrapper bw = new BeanWrapperImpl(tb); bw.setPropertyValue("ag", "foobar"); fail("Should throw exception on invalid property"); } catch (NotWritablePropertyException ex) { // expected assertEquals(1, ex.getPossibleMatches().length); assertEquals("age", ex.getPossibleMatches()[0]); } }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void testAlternativesForTypo() { IntelliBean ib = new IntelliBean(); BeanWrapper bw = new BeanWrapperImpl(ib); try {/*from www. j a v a2s . co m*/ bw.setPropertyValue("names", "Alef"); } catch (NotWritablePropertyException ex) { assertNotNull("Possible matches not determined", ex.getPossibleMatches()); assertEquals("Invalid amount of alternatives", 1, ex.getPossibleMatches().length); } }
From source file:org.springframework.beans.BeanWrapperTests.java
@Test public void testAlternativesForTypos() { IntelliBean ib = new IntelliBean(); BeanWrapper bw = new BeanWrapperImpl(ib); try {//from ww w . jav a 2 s.c o m bw.setPropertyValue("mystring", "Arjen"); } catch (NotWritablePropertyException ex) { assertNotNull("Possible matches not determined", ex.getPossibleMatches()); assertEquals("Invalid amount of alternatives", 3, ex.getPossibleMatches().length); } }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testPossibleMatches() { try {// w w w . java2 s .c o m DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("ag", "foobar"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("tb", bd); lbf.getBean("tb"); fail("Should throw exception on invalid property"); } catch (BeanCreationException ex) { assertTrue(ex.getCause() instanceof NotWritablePropertyException); NotWritablePropertyException cause = (NotWritablePropertyException) ex.getCause(); // expected assertEquals(1, cause.getPossibleMatches().length); assertEquals("age", cause.getPossibleMatches()[0]); } }