You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2005/05/29 07:45:30 UTC

svn commit: r178928 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/PropertyUtilsBean.java test/org/apache/commons/beanutils/PropertyUtilsTestCase.java

Author: skitching
Date: Sat May 28 22:45:27 2005
New Revision: 178928

URL: http://svn.apache.org/viewcvs?rev=178928&view=rev
Log:
* replace test case PropertyUtilsTestCase.testSetMapExtension with test case
  testMapExtensionDefault. This new test case verifies that a class that extends 
  Map will have any simple properties ignored in favour of Map.set/Map.get. This 
  behaviour has been agreed as per discussion on bugzilla #23815. With this 
  updated test case, the old PropertyUtilsBean code now fails - ie this change
  breaks backward compatibility.

* fixes PropertyUtilsBean.setNestedProperty so it no longer checks for
  the existence of a simple property before using Map methods; Map
  methods are always used on a Map object. This backs out the change made
  in bugzilla#14440.

* temporarily removes test PropertyUtilsTestCase.testBeanImplementingMap.
  I'll add it (or a variant thereof) back soon.

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java?rev=178928&r1=178927&r2=178928&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java (original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java Sat May 28 22:45:27 2005
@@ -1705,16 +1705,7 @@
         indexOfMAPPED_DELIM = name.indexOf(PropertyUtils.MAPPED_DELIM);
 
         if (bean instanceof Map) {
-            // check to see if the class has a standard property 
-            PropertyDescriptor descriptor = 
-                getPropertyDescriptor(bean, name);
-            if (descriptor == null) {
-                // no - then put the value into the map
-                ((Map) bean).put(name, value);
-            } else {
-                // yes - use that instead
-                setSimpleProperty(bean, name, value);
-            }
+            ((Map) bean).put(name, value);
         } else if (indexOfMAPPED_DELIM >= 0) {
             setMappedProperty(bean, name, value);
         } else if (indexOfINDEXED_DELIM >= 0) {

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java?rev=178928&r1=178927&r2=178928&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java (original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java Sat May 28 22:45:27 2005
@@ -3647,31 +3647,6 @@
     }
     
     /**
-     * There was a bug in setNestedProperty/getNestedProperty when the
-     * target bean is a map. This test case ensures that the problem is
-     * fixed.
-     */
-    public void testBeanImplementingMap() throws Exception {
-        HashMap map = new HashMap();
-        HashMap submap = new HashMap();
-        BetaBean betaBean1 = new BetaBean("test1");
-        BetaBean betaBean2 = new BetaBean("test2");
-        
-        // map.put("submap", submap)
-        PropertyUtils.setNestedProperty(map, "submap", submap);
-        
-        // map.get("submap").put("beta1", betaBean1)
-        PropertyUtils.setNestedProperty(map, "submap.beta1", betaBean1);
-        assertEquals("Unexpected keys in map", "submap", keysToString(map));
-        assertEquals("Unexpected keys in submap", "beta1", keysToString(submap));
-
-        // map.get("submap").put("beta2", betaBean2)
-        PropertyUtils.setNestedProperty(map, "submap(beta2)", betaBean2);
-        assertEquals("Unexpected keys in map", "submap", keysToString(map));
-        assertEquals("Unexpected keys in submap", "beta1, beta2", keysToString(submap));
-    }
-
-    /**
      * Returns a single string containing all the keys in the map,
      * sorted in alphabetical order and separated by ", ".
      * <p>
@@ -3690,19 +3665,39 @@
     }
 
     /** 
-     * This tests to see that classes that implement Map can have 
-     * their standard properties set.
+     * This tests to see that classes that implement Map always have their
+     * custom properties ignored.
+     * <p>
+     * Note that this behaviour has changed several times over past releases
+     * of beanutils, breaking backwards compatibility each time. Here's hoping
+     * that the current 1.7.1 release is the last time this behaviour changes! 
      */
-    public void testSetMapExtension() throws Exception {
+    public void testMapExtensionDefault() throws Exception {
         ExtendMapBean bean = new ExtendMapBean();
-        
+
+        // setting property direct should work, and not affect map
         bean.setUnusuallyNamedProperty("bean value");
         assertEquals("Set property direct failed", "bean value", bean.getUnusuallyNamedProperty());
+        assertNull("Get on unset map property failed", 
+                PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"));
         
+        // setting simple property should call the setter method only, and not
+        // affect the map.
         PropertyUtils.setSimpleProperty(bean, "unusuallyNamedProperty", "new value");
         assertEquals("Set property on map failed (1)", "new value", bean.getUnusuallyNamedProperty());
-        
+        assertNull("Get on unset map property failed", 
+                PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"));
+
+        // setting via setNestedProperty should affect the map only, and not
+        // call the setter method.
         PropertyUtils.setProperty(bean, "unusuallyNamedProperty", "next value");
-        assertEquals("Set property on map failed (2)", "next value", bean.getUnusuallyNamedProperty());
+        assertEquals(
+                "setNestedProperty on map not visible to getNestedProperty", 
+                "next value", 
+                PropertyUtils.getNestedProperty(bean, "unusuallyNamedProperty"));
+        assertEquals(
+            "Set nested property on map unexpected affected simple property", 
+            "new value", 
+            bean.getUnusuallyNamedProperty());
     }
 }



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