Author: niallp
Date: Sat Jul 14 00:27:18 2007
New Revision: 556237

URL: http://svn.apache.org/viewvc?view=rev&rev=556237
Log:
BEANUTILS-18 PropertyUtils.isReadable() and PropertyUtils.getProperty() not 
consistent - thanks to Maarten Coene

Added:
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java
   (with props)
    
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java
   (with props)
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/TestBean.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=556237&r1=556236&r2=556237
==============================================================================
--- 
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 Jul 14 00:27:18 2007
@@ -462,6 +462,7 @@
         if (descriptor instanceof IndexedPropertyDescriptor) {
             Method readMethod = ((IndexedPropertyDescriptor) descriptor).
                     getIndexedReadMethod();
+            readMethod = MethodUtils.getAccessibleMethod(readMethod);
             if (readMethod != null) {
                 Object[] subscript = new Object[1];
                 subscript[0] = new Integer(index);
@@ -615,6 +616,7 @@
             // Call the keyed getter method if there is one
             Method readMethod = ((MappedPropertyDescriptor) descriptor).
                     getMappedReadMethod();
+            readMethod = MethodUtils.getAccessibleMethod(readMethod);
             if (readMethod != null) {
                 Object[] keyArray = new Object[1];
                 keyArray[0] = key;
@@ -626,7 +628,7 @@
             }
         } else {
           /* means that the result has to be retrieved from a map */
-          Method readMethod = descriptor.getReadMethod();
+          Method readMethod = getReadMethod(descriptor);
           if (readMethod != null) {
             Object invokeResult = invokeMethod(readMethod, bean, new 
Object[0]);
             /* test and fetch from the map */
@@ -1346,13 +1348,14 @@
                 PropertyDescriptor desc =
                     getPropertyDescriptor(bean, name);
                 if (desc != null) {
-                    Method readMethod = desc.getReadMethod();
+                    Method readMethod = getReadMethod(desc);
                     if (readMethod == null) {
                         if (desc instanceof IndexedPropertyDescriptor) {
                             readMethod = ((IndexedPropertyDescriptor) 
desc).getIndexedReadMethod();
                         } else if (desc instanceof MappedPropertyDescriptor) {
                             readMethod = ((MappedPropertyDescriptor) 
desc).getMappedReadMethod();
                         }
+                        readMethod = 
MethodUtils.getAccessibleMethod(readMethod);
                     }
                     return (readMethod != null);
                 } else {
@@ -1411,13 +1414,14 @@
                 PropertyDescriptor desc =
                     getPropertyDescriptor(bean, name);
                 if (desc != null) {
-                    Method writeMethod = desc.getWriteMethod();
+                    Method writeMethod = getWriteMethod(desc);
                     if (writeMethod == null) {
                         if (desc instanceof IndexedPropertyDescriptor) {
                             writeMethod = ((IndexedPropertyDescriptor) 
desc).getIndexedWriteMethod();
                         } else if (desc instanceof MappedPropertyDescriptor) {
                             writeMethod = ((MappedPropertyDescriptor) 
desc).getMappedWriteMethod();
                         }
+                        writeMethod = 
MethodUtils.getAccessibleMethod(writeMethod);
                     }
                     return (writeMethod != null);
                 } else {
@@ -1563,6 +1567,7 @@
         if (descriptor instanceof IndexedPropertyDescriptor) {
             Method writeMethod = ((IndexedPropertyDescriptor) descriptor).
                     getIndexedWriteMethod();
+            writeMethod = MethodUtils.getAccessibleMethod(writeMethod);
             if (writeMethod != null) {
                 Object[] subscript = new Object[2];
                 subscript[0] = new Integer(index);
@@ -1592,7 +1597,7 @@
         }
 
         // Otherwise, the underlying property must be an array or a list
-        Method readMethod = descriptor.getReadMethod();
+        Method readMethod = getReadMethod(descriptor);
         if (readMethod == null) {
             throw new NoSuchMethodException("Property '" + name +
                     "' has no getter method on bean class '" + bean.getClass() 
+ "'");
@@ -1730,6 +1735,7 @@
             Method mappedWriteMethod =
                     ((MappedPropertyDescriptor) descriptor).
                     getMappedWriteMethod();
+            mappedWriteMethod = 
MethodUtils.getAccessibleMethod(mappedWriteMethod);
             if (mappedWriteMethod != null) {
                 Object[] params = new Object[2];
                 params[0] = key;
@@ -1750,7 +1756,7 @@
             }
         } else {
           /* means that the result has to be retrieved from a map */
-          Method readMethod = descriptor.getReadMethod();
+          Method readMethod = getReadMethod(descriptor);
           if (readMethod != null) {
             Object invokeResult = invokeMethod(readMethod, bean, new 
Object[0]);
             /* test and fetch from the map */

Modified: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestBean.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestBean.java?view=diff&rev=556237&r1=556236&r2=556237
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestBean.java
 (original)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/TestBean.java
 Sat Jul 14 00:27:18 2007
@@ -418,7 +418,7 @@
     /*
      * Another nested reference to a bean containing mapp properties
      */
-    class MappedTestBean {
+    public class MappedTestBean {
         public void setValue(String key,String val) { }
         public String getValue(String key) { return "Mapped Value"; }
     }

Added: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java?view=auto&rev=556237
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java
 (added)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java
 Sat Jul 14 00:27:18 2007
@@ -0,0 +1,285 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.beanutils.bugs;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.beanutils.bugs.other.Jira18BeanFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Test case for Jira issue# BEANUTILS-18.
+ * <p />
+ * See https://issues.apache.org/jira/browse/BEANUTILS-18
+ * <p />
+ * 
+ * 
+ * <p />
+ * This test case demonstrates the issue.
+ *
+ * @version $Revision$ $Date$
+ */
+public class Jira18TestCase extends TestCase {
+
+    private Log log = LogFactory.getLog(Jira18TestCase.class);
+    private Object bean;
+
+    /**
+     * Create a test case with the specified name.
+     *
+     * @param name The name of the test
+     */
+    public Jira18TestCase(String name) {
+        super(name);
+    }
+
+    /**
+     * Run the Test.
+     *
+     * @param args Arguments
+     */
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
+
+    /**
+     * Create a test suite for this test.
+     *
+     * @return a test suite
+     */
+    public static Test suite() {
+        return (new TestSuite(Jira18TestCase.class));
+    }
+
+    /**
+     * Set up.
+     *
+     * @throws java.lang.Exception
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        bean = Jira18BeanFactory.createBean();
+    }
+
+    /**
+     * Tear Down.
+     *
+     * @throws java.lang.Exception
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#isReadable(Object, String)}
+     * for simple properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_isReadable() {
+        boolean result = false;
+        try {
+            result = PropertyUtils.isReadable(bean, "simple");
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertFalse("PropertyUtils.isReadable(bean, \"simple\") returned 
true", result);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#isWriteable(Object, String)}
+     * for simple properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_isWriteable() {
+        boolean result = false;
+        try {
+            result = PropertyUtils.isWriteable(bean, "simple");
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertFalse("PropertyUtils.isWriteable(bean, \"simple\") returned 
true", result);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#isReadable(Object, String)}
+     * for indexed properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_isReadable_Indexed() {
+        boolean result = false;
+        try {
+            result = PropertyUtils.isReadable(bean, "indexed");
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertFalse("PropertyUtils.isReadable(bean, \"indexed\") returned 
true", result);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#isWriteable(Object, String)}
+     * for indexed properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_isWriteable_Indexed() {
+        boolean result = false;
+        try {
+            result = PropertyUtils.isWriteable(bean, "indexed");
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertFalse("PropertyUtils.isWriteable(bean, \"indexed\") returned 
true", result);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#isReadable(Object, String)}
+     * for Mapped properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_isReadable_Mapped() {
+        boolean result = false;
+        try {
+            result = PropertyUtils.isReadable(bean, "mapped");
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertFalse("PropertyUtils.isReadable(bean, \"mapped\") returned 
true", result);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#isWriteable(Object, String)}
+     * for Mapped properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_isWriteable_Mapped() {
+        boolean result = false;
+        try {
+            result = PropertyUtils.isWriteable(bean, "mapped");
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertFalse("PropertyUtils.isWriteable(bean, \"mapped\") returned 
true", result);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#getProperty(Object, String)}
+     * for simple properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_getProperty() {
+        boolean threwNoSuchMethodException = false;
+        Object result = null;
+        try {
+            result = PropertyUtils.getProperty(bean, "simple");
+        } catch (NoSuchMethodException ex) {
+            threwNoSuchMethodException = true; // expected result
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertTrue("Expected NoSuchMethodException but returned '" + result + 
"'", threwNoSuchMethodException);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#setProperty(Object, String, 
Object)}
+     * for simple properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_setProperty() {
+        boolean threwNoSuchMethodException = false;
+        try {
+            PropertyUtils.setProperty(bean, "simple", "BAR");
+        } catch (NoSuchMethodException ex) {
+            threwNoSuchMethodException = true; // expected result
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertTrue("Expected NoSuchMethodException", 
threwNoSuchMethodException);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#getProperty(Object, String)}
+     * for indexed properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_getProperty_Indexed() {
+        boolean threwNoSuchMethodException = false;
+        Object result = null;
+        try {
+            result = PropertyUtils.getProperty(bean, "indexed[0]");
+        } catch (NoSuchMethodException ex) {
+            threwNoSuchMethodException = true; // expected result
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertTrue("Expected NoSuchMethodException but returned '" + result + 
"'", threwNoSuchMethodException);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#setProperty(Object, String, 
Object)}
+     * for indexed properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_setProperty_Indexed() {
+        boolean threwNoSuchMethodException = false;
+        try {
+            PropertyUtils.setProperty(bean, "indexed[0]", "BAR");
+        } catch (NoSuchMethodException ex) {
+            threwNoSuchMethodException = true; // expected result
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertTrue("Expected NoSuchMethodException", 
threwNoSuchMethodException);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#getProperty(Object, String)}
+     * for mapped properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_getProperty_Mapped() {
+        boolean threwNoSuchMethodException = false;
+        Object result = null;
+        try {
+            result = PropertyUtils.getProperty(bean, "mapped(foo-key)");
+        } catch (NoSuchMethodException ex) {
+            threwNoSuchMethodException = true; // expected result
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertTrue("Expected NoSuchMethodException but returned '" + result + 
"'", threwNoSuchMethodException);
+    }
+
+    /**
+     * Test [EMAIL PROTECTED] PropertyUtils#setProperty(Object, String, 
Object)}
+     * for mapped properties.
+     */
+    public void testIssue_BEANUTILS_18_PropertyUtils_setProperty_Mapped() {
+        boolean threwNoSuchMethodException = false;
+        try {
+            PropertyUtils.setProperty(bean, "mapped(foo-key)", "BAR");
+        } catch (NoSuchMethodException ex) {
+            threwNoSuchMethodException = true; // expected result
+        } catch (Throwable t) {
+            log.error("ERROR " + t, t);
+            fail("Threw exception: " + t);
+        }
+        assertTrue("Expected NoSuchMethodException", 
threwNoSuchMethodException);
+    }
+}

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/Jira18TestCase.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java?view=auto&rev=556237
==============================================================================
--- 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java
 (added)
+++ 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java
 Sat Jul 14 00:27:18 2007
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.beanutils.bugs.other;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.beanutils.bugs.Jira18TestCase;
+
+/**
+ * Factory whcih creates <i>package</i> scope beans with
+ * public methods for [EMAIL PROTECTED] Jira18TestCase}.
+ * 
+ * @version $Revision$ $Date$
+ */
+public class Jira18BeanFactory {
+
+    /**
+     * Factory method which creates package friendly beans.
+     *
+     * @return The a package friendly bean with public methods
+     */
+    public static Object createBean() {
+        return new PackageFriendlyBean();
+    }
+
+    /* =============== Package Friendly Bean =============== */
+    static class PackageFriendlyBean {
+
+        private String[] indexed = new String[] {"one", "two", "three"};
+        private String simple = "FOO";
+        private Map mapped = new HashMap();
+
+        /** Default Constructor */
+        public PackageFriendlyBean() {
+            mapped.put("foo-key", "foo-value");
+            mapped.put("bar-key", "bar-value");
+        }
+        /**
+         * Return simple property.
+         * 
+         * @return The simple value
+         */
+        public String getSimple() {
+            return simple;
+        }
+
+        /**
+         * Set simple property.
+         * 
+         * @param simple The simple value
+         */
+        public void setSimple(String simple) {
+            this.simple = simple;
+        }
+
+        /**
+         * Return indexed property.
+         * 
+         * @param index The index
+         * @return The indexed value
+         */
+        public String getIndexed(int index) {
+            return indexed[index];
+        }
+
+        /**
+         * Set indexed property.
+         * 
+         * @param index The index
+         * @param value The indexed value
+         */
+        public void setIndexed(int index, String value) {
+            this.indexed[index] = value;
+        }
+
+        /**
+         * Return mapped property.
+         * 
+         * @param key The mapped key
+         * @return The mapped value
+         */
+        public String getMapped(String key) {
+            return (String)mapped.get(key);
+        }
+
+        /**
+         * Set mapped property.
+         * 
+         * @param key The mapped key
+         * @param value The mapped value
+         */
+        public void setMapped(String key, String value) {
+            mapped.put(key, value);
+        }
+
+    }
+
+}

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/bugs/other/Jira18BeanFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to