commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestConfigurationUtils.java
Date Tue, 19 Oct 2004 13:41:44 GMT
ebourg      2004/10/19 06:41:44

  Modified:    configuration/xdocs changes.xml
               configuration/src/java/org/apache/commons/configuration
                        ConfigurationUtils.java
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationUtils.java
  Log:
  Added copy() and append() in ConfigurationUtils
  
  Revision  Changes    Path
  1.66      +5 -0      jakarta-commons/configuration/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- changes.xml	19 Oct 2004 11:44:31 -0000	1.65
  +++ changes.xml	19 Oct 2004 13:41:44 -0000	1.66
  @@ -8,6 +8,11 @@
     <body>
   
       <release version="1.1-dev" date="in CVS">
  +      <action dev="ebourg" type="add">
  +        Added two methods copy(Configuration, Configuration) and
  +        append(Configuration, Configuration) in ConfigurationUtils to copy
  +        properties between configurations.
  +      </action>
         <action dev="ebourg" type="update">
           Moved the constructors implementations from PropertiesConfiguration and
           XMLConfiguration to AbstractFileConfiguration.
  
  
  
  1.10      +39 -1     jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java
  
  Index: ConfigurationUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ConfigurationUtils.java	23 Sep 2004 11:42:00 -0000	1.9
  +++ ConfigurationUtils.java	19 Oct 2004 13:41:44 -0000	1.10
  @@ -98,6 +98,44 @@
       }
   
       /**
  +     * Copy all properties from the source configuration to the target
  +     * configuration. Properties in the target configuration are replaced with
  +     * the properties with the same key in the source configuration.
  +     *
  +     * @param source the source configuration
  +     * @param target the target configuration
  +     * @since 1.1
  +     */
  +    public static void copy(Configuration source, Configuration target)
  +    {
  +        Iterator keys = source.getKeys();
  +        while (keys.hasNext())
  +        {
  +            String key = (String) keys.next();
  +            target.setProperty(key, source.getProperty(key));
  +        }
  +    }
  +
  +    /**
  +     * Append all properties from the source configuration to the target
  +     * configuration. Properties in the source configuration are appended to
  +     * the properties with the same key in the target configuration.
  +     *
  +     * @param source the source configuration
  +     * @param target the target configuration
  +     * @since 1.1
  +     */
  +    public static void append(Configuration source, Configuration target)
  +    {
  +        Iterator keys = source.getKeys();
  +        while (keys.hasNext())
  +        {
  +            String key = (String) keys.next();
  +            target.addProperty(key, source.getProperty(key));
  +        }
  +    }
  +
  +    /**
        * Constructs a URL from a base path and a file name. The file name can
        * be absolute, relative or a full URL. If necessary the base path URL is
        * applied.
  
  
  
  1.8       +50 -2     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
  
  Index: TestConfigurationUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestConfigurationUtils.java	23 Sep 2004 11:42:00 -0000	1.7
  +++ TestConfigurationUtils.java	19 Oct 2004 13:41:44 -0000	1.8
  @@ -1,5 +1,3 @@
  -package org.apache.commons.configuration;
  -
   /*
    * Copyright 2001-2004 The Apache Software Foundation.
    *
  @@ -16,14 +14,20 @@
    * limitations under the License.
    */
   
  +package org.apache.commons.configuration;
  +
   import java.io.File;
   import java.net.URL;
  +import java.util.ArrayList;
  +import java.util.List;
   
   import junit.framework.TestCase;
  +import junitx.framework.ListAssert;
   
   /**
    * Tests the ConfigurationUtils class
    *
  + * @version $Revision$, $Date$
    */
   public class TestConfigurationUtils extends TestCase
   {
  @@ -123,4 +127,48 @@
           assertEquals("file name for a valid URL " + url, "bar.xml", ConfigurationUtils.getFileName(url));
       }
   
  +    public void testCopy()
  +    {
  +        // create the source configuration
  +        Configuration conf1 = new BaseConfiguration();
  +        conf1.addProperty("key1", "value1");
  +        conf1.addProperty("key2", "value2");
  +
  +        // create the target configuration
  +        Configuration conf2 = new BaseConfiguration();
  +        conf2.addProperty("key1", "value3");
  +        conf2.addProperty("key2", "value4");
  +
  +        // copy the source configuration into the target configuration
  +        ConfigurationUtils.copy(conf1, conf2);
  +
  +        assertEquals("'key1' property", "value1", conf2.getProperty("key1"));
  +        assertEquals("'key2' property", "value2", conf2.getProperty("key2"));
  +    }
  +
  +    public void testAppend()
  +    {
  +        // create the source configuration
  +        Configuration conf1 = new BaseConfiguration();
  +        conf1.addProperty("key1", "value1");
  +        conf1.addProperty("key2", "value2");
  +
  +        // create the target configuration
  +        Configuration conf2 = new BaseConfiguration();
  +        conf2.addProperty("key1", "value3");
  +        conf2.addProperty("key2", "value4");
  +
  +        // append the source configuration to the target configuration
  +        ConfigurationUtils.append(conf1, conf2);
  +
  +        List expected = new ArrayList();
  +        expected.add("value3");
  +        expected.add("value1");
  +        ListAssert.assertEquals("'key1' property", expected, conf2.getList("key1"));
  +
  +        expected = new ArrayList();
  +        expected.add("value4");
  +        expected.add("value2");
  +        ListAssert.assertEquals("'key2' property", expected, conf2.getList("key2"));
  +    }
   }
  
  
  

---------------------------------------------------------------------
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