commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils BetaBean.java PropertyUtilsTestCase.java
Date Thu, 21 Nov 2002 22:21:02 GMT
rdonkin     2002/11/21 14:21:01

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        MappedPropertyDescriptor.java
               beanutils/src/test/org/apache/commons/beanutils
                        BetaBean.java PropertyUtilsTestCase.java
  Log:
  Fixed bug #10167. Now PropertyUtils should be able to find mapped properties with setters
but no getters.
  
  Revision  Changes    Path
  1.12      +11 -6     jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
  
  Index: MappedPropertyDescriptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MappedPropertyDescriptor.java	24 Mar 2002 09:59:30 -0000	1.11
  +++ MappedPropertyDescriptor.java	21 Nov 2002 22:21:01 -0000	1.12
  @@ -143,8 +143,8 @@
   
           setName(propertyName);
           String base = capitalize(propertyName);
  -
  -        // Look for mapped get and set methods
  +        
  +        // Look for mapped read method and matching write method
           try {
               mappedReadMethod = findMethod(beanClass, "get" + base, 1,
                       stringClassArray);
  @@ -152,6 +152,11 @@
               mappedWriteMethod = findMethod(beanClass, "set" + base, 2,  params);
           } catch (IntrospectionException e) {
               ;
  +        }
  +        
  +        // If there's no read method, then look for just a write method 
  +        if (mappedReadMethod == null) {
  +            mappedWriteMethod = findMethod(beanClass, "set" + base, 2);
           }
   
           if ((mappedReadMethod == null) && (mappedWriteMethod == null)) {
  
  
  
  1.2       +14 -0     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BetaBean.java
  
  Index: BetaBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BetaBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BetaBean.java	6 Mar 2002 20:21:24 -0000	1.1
  +++ BetaBean.java	21 Nov 2002 22:21:01 -0000	1.2
  @@ -59,6 +59,20 @@
   
   public class BetaBean extends AbstractChild {
       
  +    private String secret = "utah";
  +    
  +    public String getSecret() {
  +        return secret;
  +    }
  +    
  +    public void setNoGetterProperty(String secret) {
  +        this.secret = secret;
  +    }
  +    
  +    public void setNoGetterMappedProperty(String secret, String key) {
  +        this.secret = "MAP:" + secret;
  +    }
  +    
       public BetaBean(String name) {
           setName(name);
       }
  
  
  
  1.28      +27 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
  
  Index: PropertyUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- PropertyUtilsTestCase.java	29 Oct 2002 20:27:53 -0000	1.27
  +++ PropertyUtilsTestCase.java	21 Nov 2002 22:21:01 -0000	1.28
  @@ -3623,4 +3623,27 @@
                   "abcd", 
                   bean.getName()); 
       }
  +    
  +    public void testSetNoGetter() throws Exception
  +    {
  +        BetaBean bean = new BetaBean("Cedric");
  +        
  +        // test standard no getter
  +        bean.setNoGetterProperty("Sigma");
  +        assertEquals("BetaBean test failed", "Sigma", bean.getSecret());
  +        
  +        assertNotNull("Descriptor is null", PropertyUtils.getPropertyDescriptor(bean, "noGetterProperty"));
  +        
  +        BeanUtils.setProperty(bean, "noGetterProperty",  "Omega");
  +        assertEquals("Cannot set no-getter property", "Omega", bean.getSecret());
  +        
  +        // test mapped no getter descriptor
  +        MappedPropertyDescriptor descriptor 
  +            = new MappedPropertyDescriptor("noGetterMappedProperty", BetaBean.class);
  +        
  +        assertNotNull("Map Descriptor is null", PropertyUtils.getPropertyDescriptor(bean,
"noGetterMappedProperty"));
  +        
  +        PropertyUtils.setMappedProperty(bean, "noGetterMappedProperty",  "Epsilon", "Epsilon");
  +        assertEquals("Cannot set mapped no-getter property", "MAP:Epsilon", bean.getSecret());
  +    }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message