commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r652317 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/ main/java/org/apache/commons/configuration2/beanutils/ test/java/org/apache/commons/configuration2/beanutils/
Date Wed, 30 Apr 2008 11:01:58 GMT
Author: ebourg
Date: Wed Apr 30 04:01:58 2008
New Revision: 652317

URL: http://svn.apache.org/viewvc?rev=652317&view=rev
Log:
Fixed a bug in ConfigurationDynaBean that prevented to work with indexed properties stored
internally as arrays (CONFIGURATION-322)

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/ConfigurationDynaBean.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestConfigurationDynaBean.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java?rev=652317&r1=652316&r2=652317&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
Wed Apr 30 04:01:58 2008
@@ -21,6 +21,7 @@
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -1149,6 +1150,11 @@
         {
             list = defaultValue;
         }
+        else if (value.getClass().isArray())
+        {
+            T[] array = (T[]) value;
+            return Arrays.asList(array);
+        }
         else
         {
             throw new ConversionException('\'' + key + "' doesn't map to a List object: "
+ value + ", a "

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/ConfigurationDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/ConfigurationDynaBean.java?rev=652317&r1=652316&r2=652317&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/ConfigurationDynaBean.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/beanutils/ConfigurationDynaBean.java
Wed Apr 30 04:01:58 2008
@@ -166,7 +166,7 @@
         }
         catch (ConversionException e)
         {
-            throw new IllegalArgumentException("Property '" + name + "' is not indexed.");
+            throw new IllegalArgumentException("Property '" + name + "' is not indexed.",
e);
         }
     }
 
@@ -210,7 +210,7 @@
             }
             else if (property.getClass().isArray())
             {
-                Array.set(value, index, value);
+                Array.set(property, index, value);
             }
             else if (index == 0)
             {
@@ -223,7 +223,7 @@
         }
         catch (ConversionException e)
         {
-            throw new IllegalArgumentException("Property '" + name + "' is not indexed.");
+            throw new IllegalArgumentException("Property '" + name + "' is not indexed.",
e);
         }
     }
 

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestConfigurationDynaBean.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestConfigurationDynaBean.java?rev=652317&r1=652316&r2=652317&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestConfigurationDynaBean.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/beanutils/TestConfigurationDynaBean.java
Wed Apr 30 04:01:58 2008
@@ -18,12 +18,14 @@
 package org.apache.commons.configuration2.beanutils;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.commons.beanutils.DynaProperty;
 import org.apache.commons.configuration2.Configuration;
+import org.apache.commons.configuration2.MapConfiguration;
 import org.apache.commons.configuration2.flat.BaseConfiguration;
 
 import junit.framework.AssertionFailedError;
@@ -50,7 +52,7 @@
      * <code>getDynaProperties()</code>.  You should update this list
      * when new properties are added to TestBean.
      */
-    String[] properties = {
+    private String[] properties = {
             "booleanProperty",
             "booleanSecond",
             "doubleProperty",
@@ -67,7 +69,7 @@
             "charProperty"
     };
 
-    Object[] values = {
+    private Object[] values = {
             Boolean.TRUE,
             Boolean.TRUE,
             new Double(Double.MAX_VALUE),
@@ -84,15 +86,15 @@
             new Character(Character.MAX_VALUE)
     };
 
-    int[] intArray = {0, 10, 20, 30, 40};
-    boolean[] booleanArray = {true, false, true, false, true};
-    char[] charArray = {'a', 'b', 'c', 'd', 'e'};
-    byte[] byteArray = {0, 10, 20, 30, 40};
-    long[] longArray = {0, 10, 20, 30, 40};
-    short[] shortArray = {0, 10, 20, 30, 40};
-    float[] floatArray = {0, 10, 20, 30, 40};
-    double[] doubleArray = {0.0, 10.0, 20.0, 30.0, 40.0};
-    String[] stringArray = {"String 0", "String 1", "String 2", "String 3", "String 4"};
+    private int[] intArray = {0, 10, 20, 30, 40};
+    private boolean[] booleanArray = {true, false, true, false, true};
+    private char[] charArray = {'a', 'b', 'c', 'd', 'e'};
+    private byte[] byteArray = {0, 10, 20, 30, 40};
+    private long[] longArray = {0, 10, 20, 30, 40};
+    private short[] shortArray = {0, 10, 20, 30, 40};
+    private float[] floatArray = {0, 10, 20, 30, 40};
+    private double[] doubleArray = {0.0, 10.0, 20.0, 30.0, 40.0};
+    private String[] stringArray = {"String 0", "String 1", "String 2", "String 3", "String
4"};
 
 
     /**
@@ -557,6 +559,24 @@
     }
 
     /**
+     * Test the modification of a configuration property stored internally as an array.
+     */
+    public void testSetArrayValue()
+    {
+        MapConfiguration configuration = new MapConfiguration(new HashMap());
+        configuration.getMap().put("objectArray", new Object[] {"value1", "value2", "value3"});
+
+        ConfigurationDynaBean bean = new ConfigurationDynaBean(configuration);
+
+        bean.set("objectArray", 1, "New Value 1");
+        Object value = bean.get("objectArray", 1);
+
+        assertNotNull("Returned new value 1", value);
+        ObjectAssert.assertInstanceOf("Returned String new value 1", String.class,  value);
+        assertEquals("Returned correct new value 1", "New Value 1", (String) value);
+    }
+
+    /**
      * Positive and negative tests on setMappedProperty valid arguments.
      */
     public void testSetMappedValues()



Mime
View raw message