commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r552391 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/PropertyUtilsBean.java test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
Date Mon, 02 Jul 2007 03:27:18 GMT
Author: niallp
Date: Sun Jul  1 20:27:17 2007
New Revision: 552391

URL: http://svn.apache.org/viewvc?view=rev&rev=552391
Log:
BEANUTILS-43 - Support Mapped property inside a mapped property

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/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java?view=diff&rev=552391&r1=552390&r2=552391
==============================================================================
--- 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
Sun Jul  1 20:27:17 2007
@@ -780,6 +780,13 @@
         throws IllegalArgumentException, IllegalAccessException, 
         InvocationTargetException, NoSuchMethodException {
 
+        if (resolver.isMapped(propertyName)) {
+            String name = resolver.getProperty(propertyName);
+            if (name == null || name.length() == 0) {
+                propertyName = resolver.getKey(propertyName);
+            }
+        }
+
         if (resolver.isIndexed(propertyName) ||
             resolver.isMapped(propertyName)) {
             throw new IllegalArgumentException(
@@ -1885,6 +1892,13 @@
     protected void setPropertyOfMapBean(Map bean, String propertyName, Object value)
         throws IllegalArgumentException, IllegalAccessException, 
         InvocationTargetException, NoSuchMethodException {
+
+        if (resolver.isMapped(propertyName)) {
+            String name = resolver.getProperty(propertyName);
+            if (name == null || name.length() == 0) {
+                propertyName = resolver.getKey(propertyName);
+            }
+        }
 
         if (resolver.isIndexed(propertyName) ||
             resolver.isMapped(propertyName)) {

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java?view=diff&rev=552391&r1=552390&r2=552391
==============================================================================
--- 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
Sun Jul  1 20:27:17 2007
@@ -1122,6 +1122,25 @@
 
 
     /**
+     * Test getting a value out of a mapped Map
+     */
+    public void testGetMappedMap() {
+        TestBean bean = new TestBean();
+        Map map = new HashMap();
+        map.put("sub-key-1", "sub-value-1");
+        map.put("sub-key-2", "sub-value-2");
+        map.put("sub-key-3", "sub-value-3");
+        bean.getMapProperty().put("mappedMap", map);
+        try {
+            assertEquals("sub-value-1", PropertyUtils.getProperty(bean, "mapProperty(mappedMap)(sub-key-1)"));
+            assertEquals("sub-value-2", PropertyUtils.getProperty(bean, "mapProperty(mappedMap)(sub-key-2)"));
+            assertEquals("sub-value-3", PropertyUtils.getProperty(bean, "mapProperty(mappedMap)(sub-key-3)"));
+        } catch (Throwable t) {
+            fail("Threw " + t + "");
+        }
+    }
+
+    /**
      * Test getting mapped values with periods in the key.
      */
     public void testGetMappedPeriods() {
@@ -2804,6 +2823,26 @@
 
     }
 
+
+    /**
+     * Test setting a value out of a mapped Map
+     */
+    public void testSetMappedMap() {
+        TestBean bean = new TestBean();
+        Map map = new HashMap();
+        map.put("sub-key-1", "sub-value-1");
+        map.put("sub-key-2", "sub-value-2");
+        map.put("sub-key-3", "sub-value-3");
+        bean.getMapProperty().put("mappedMap", map);
+
+        assertEquals("BEFORE", "sub-value-3", ((Map)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
+        try {
+            PropertyUtils.setProperty(bean, "mapProperty(mappedMap)(sub-key-3)", "SUB-KEY-3-UPDATED");
+        } catch (Throwable t) {
+            fail("Threw " + t + "");
+        }
+        assertEquals("AFTER", "SUB-KEY-3-UPDATED", ((Map)bean.getMapProperty().get("mappedMap")).get("sub-key-3"));
+    }
 
     /**
      * Positive and negative tests on setMappedProperty valid arguments.



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


Mime
View raw message