commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r681802 - in /commons/proper/configuration/branches/configuration2_experimental: src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/ xdocs/
Date Fri, 01 Aug 2008 19:42:54 GMT
Author: oheger
Date: Fri Aug  1 12:42:53 2008
New Revision: 681802

URL: http://svn.apache.org/viewvc?rev=681802&view=rev
Log:
CONFIGURATION-332: DataConfiguration now collaborates better with PropertiesConfiguration.
Ported fix from trunk.

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDataConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java?rev=681802&r1=681801&r2=681802&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/DataConfiguration.java
Fri Aug  1 12:42:53 2008
@@ -128,6 +128,7 @@
         return configuration.getProperty(key);
     }
 
+    @Override
     protected void addPropertyDirect(String key, Object obj)
     {
         if (configuration instanceof AbstractConfiguration)
@@ -140,6 +141,12 @@
         }
     }
 
+    @Override
+    public void addProperty(String key, Object value)
+    {
+        getConfiguration().addProperty(key, value);
+    }
+
     public boolean isEmpty()
     {
         return configuration.isEmpty();
@@ -150,11 +157,18 @@
         return configuration.containsKey(key);
     }
 
+    @Override
     public void clearProperty(String key)
     {
         configuration.clearProperty(key);
     }
 
+    @Override
+    public void setProperty(String key, Object value)
+    {
+        configuration.setProperty(key, value);
+    }
+
     public Iterator<String> getKeys()
     {
         return configuration.getKeys();

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDataConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDataConfiguration.java?rev=681802&r1=681801&r2=681802&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDataConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDataConfiguration.java
Fri Aug  1 12:42:53 2008
@@ -31,22 +31,31 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.NoSuchElementException;
-import javax.mail.internet.InternetAddress;
 
-import org.apache.commons.configuration2.flat.BaseConfiguration;
+import javax.mail.internet.InternetAddress;
 
 import junit.framework.TestCase;
 import junitx.framework.ArrayAssert;
 import junitx.framework.ListAssert;
 
+import org.apache.commons.configuration2.flat.BaseConfiguration;
+import org.easymock.EasyMock;
+
 /**
  * @author Emmanuel Bourg
  * @version $Revision$, $Date$
  */
 public class TestDataConfiguration extends TestCase
 {
+    /** Constant for a test key.*/
+    private static final String KEY = "test.key";
+
+    /** Constant for a test value.*/
+    private static final Object VALUE = 42;
+
     private DataConfiguration conf;
 
+    @Override
     protected void setUp() throws Exception
     {
         conf = new DataConfiguration(new BaseConfiguration());
@@ -2342,4 +2351,24 @@
             // expected
         }
     }
+
+    public void testAddProperty()
+    {
+        Configuration mock = EasyMock.createMock(Configuration.class);
+        mock.addProperty(KEY, VALUE);
+        EasyMock.replay(mock);
+        conf = new DataConfiguration(mock);
+        conf.addProperty(KEY, VALUE);
+        EasyMock.verify(mock);
+    }
+
+    public void testSetProperty()
+    {
+        Configuration mock = EasyMock.createMock(Configuration.class);
+        mock.setProperty(KEY, VALUE);
+        EasyMock.replay(mock);
+        conf = new DataConfiguration(mock);
+        conf.setProperty(KEY, VALUE);
+        EasyMock.verify(mock);
+    }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java?rev=681802&r1=681801&r2=681802&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java
Fri Aug  1 12:42:53 2008
@@ -34,11 +34,11 @@
 import java.util.Iterator;
 import java.util.List;
 
+import junit.framework.TestCase;
+
 import org.apache.commons.configuration2.flat.BaseConfiguration;
 import org.apache.commons.configuration2.reloading.FileChangedReloadingStrategy;
 
-import junit.framework.TestCase;
-
 /**
  * Test for loading and saving properties files.
  *
@@ -55,6 +55,7 @@
     private String testBasePath2 = ConfigurationAssert.TEST_DIR.getAbsoluteFile().getParentFile().getAbsolutePath();
     private File testSavePropertiesFile = ConfigurationAssert.getOutFile("testsave.properties");
 
+    @Override
     protected void setUp() throws Exception
     {
         conf = new PropertiesConfiguration(testProperties);
@@ -239,7 +240,7 @@
     public void testSaveWithBasePath() throws Exception
     {
         conf.setProperty("test", "true");
-        conf.setBasePath(testSavePropertiesFile.getParentFile().toURL().toString());
+        conf.setBasePath(testSavePropertiesFile.getParentFile().toURI().toString());
         conf.setFileName(testSavePropertiesFile.getName());
         conf.save();
         assertTrue(testSavePropertiesFile.exists());
@@ -600,6 +601,7 @@
         conf.setProperty("shouldReload", Boolean.FALSE);
         conf.setReloadingStrategy(new FileChangedReloadingStrategy()
         {
+            @Override
             public boolean reloadingRequired()
             {
                 return configuration.getBoolean("shouldReload");
@@ -793,6 +795,23 @@
     }
 
     /**
+     * Tests adding properties through a DataConfiguration. This is related to
+     * CONFIGURATION-332.
+     */
+    public void testSaveWithDataConfig() throws ConfigurationException
+    {
+        conf = new PropertiesConfiguration(testSavePropertiesFile);
+        DataConfiguration dataConfig = new DataConfiguration(conf);
+        dataConfig.setProperty("foo", "bar");
+        assertEquals("Property not set", "bar", conf.getString("foo"));
+
+        conf.save();
+        PropertiesConfiguration config2 = new PropertiesConfiguration(
+                testSavePropertiesFile);
+        assertEquals("Property not saved", "bar", config2.getString("foo"));
+    }
+
+    /**
      * Creates a configuration that can be used for testing copy operations.
      *
      * @return the configuration to be copied
@@ -843,6 +862,7 @@
             super(config);
         }
 
+        @Override
         public void load(Reader in) throws ConfigurationException
         {
             loadCalls++;
@@ -868,24 +888,29 @@
             outputFile = outFile;
         }
 
+        @Override
         public void disconnect()
         {
         }
 
+        @Override
         public boolean usingProxy()
         {
             return false;
         }
 
+        @Override
         public void connect() throws IOException
         {
         }
 
+        @Override
         public int getResponseCode() throws IOException
         {
             return responseCode;
         }
 
+        @Override
         public OutputStream getOutputStream() throws IOException
         {
             return new FileOutputStream(outputFile);
@@ -917,6 +942,7 @@
             return connection;
         }
 
+        @Override
         protected URLConnection openConnection(URL u) throws IOException
         {
             connection = new MockHttpURLConnection(u, responseCode, outputFile);

Modified: commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml?rev=681802&r1=681801&r2=681802&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml Fri
Aug  1 12:42:53 2008
@@ -85,6 +85,11 @@
     </release>
 
     <release version="1.6" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-332">
+        Properties written through a DataConfiguration to a wrapped
+        PropertiesConfiguration got lost when the PropertiesConfiguration was
+        saved. This has been fixed.
+      </action>
       <action dev="oheger" type="add" issue="CONFIGURATION-331">
         XMLBeanDeclaration now defines a factory method createBeanDeclaration()
         for creating the declarations for complex nested properties. This



Mime
View raw message