commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r751505 - in /commons/proper/configuration/branches/configuration2_experimental: src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/ xdocs/
Date Sun, 08 Mar 2009 19:24:59 GMT
Author: oheger
Date: Sun Mar  8 19:24:58 2009
New Revision: 751505

URL: http://svn.apache.org/viewvc?rev=751505&view=rev
Log:
CONFIGURATION-368: Generate change events for SubnodeConfigurations when changes of the parent
configuration are detected. (Ported this change to configuration2 branch.)

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubConfiguration.java?rev=751505&r1=751504&r2=751505&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/SubConfiguration.java
Sun Mar  8 19:24:58 2009
@@ -213,7 +213,9 @@
                     if (currentRoot != rootNode)
                     {
                         // the root node was changed due to a change of the parent
+                        fireEvent(EVENT_SUBNODE_CHANGED, null, null, true);
                         rootNode = currentRoot;
+                        fireEvent(EVENT_SUBNODE_CHANGED, null, null, false);
                     }
                     return currentRoot;
                 }
@@ -329,6 +331,7 @@
      *
      * @param value the value to be interpolated
      */
+    @Override
     protected Object interpolate(Object value)
     {
         return getParent().interpolate(value);

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java?rev=751505&r1=751504&r2=751505&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestCombinedConfiguration.java
Sun Mar  8 19:24:58 2009
@@ -21,25 +21,18 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.Collection;
-import java.util.Set;
 import java.util.List;
+import java.util.Set;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
 
-import org.apache.commons.configuration2.AbstractConfiguration;
-import org.apache.commons.configuration2.CombinedConfiguration;
-import org.apache.commons.configuration2.ConfigurationRuntimeException;
-import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.PropertiesConfiguration;
-import org.apache.commons.configuration2.StrictConfigurationComparator;
-import org.apache.commons.configuration2.XMLConfiguration;
 import org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.commons.configuration2.event.ConfigurationListener;
 import org.apache.commons.configuration2.reloading.FileAlwaysReloadingStrategy;
 import org.apache.commons.configuration2.tree.NodeCombiner;
 import org.apache.commons.configuration2.tree.UnionCombiner;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
 /**
  * Test class for CombinedConfiguration.
  *
@@ -65,6 +58,7 @@
     /** The test event listener. */
     CombinedListener listener;
 
+    @Override
     protected void setUp() throws Exception
     {
         super.setUp();
@@ -605,7 +599,6 @@
         assertTrue("Incorrect configuration", c == pc);
     }
 
-
     public void testGetConfigurationNameList() throws Exception
     {
         config.addConfiguration(setUpTestConfiguration());
@@ -621,6 +614,34 @@
     }
 
     /**
+     * Tests whether changes on a sub node configuration that is part of a
+     * combined configuration are detected. This test is related to
+     * CONFIGURATION-368.
+     */
+    public void testReloadWithSubNodeConfig() throws Exception
+    {
+        final String reloadContent = "<config><default><xmlReload1>%d</xmlReload1></default></config>";
+        File testDir = new File("target");
+        File testXmlFile = new File(testDir, "reload.xml");
+        config.setForceReloadCheck(true);
+        writeFile(testXmlFile, String.format(reloadContent, 0));
+        final String prefix1 = "default";
+        XMLConfiguration c1 = new XMLConfiguration(testXmlFile);
+        SubConfiguration<?> sub1 = c1.configurationAt(prefix1, true);
+        assertEquals("Inital test for sub config 1 failed", 0, sub1
+                .getInt("xmlReload1"));
+        config.addConfiguration(sub1);
+        assertEquals(
+                "Could not get value for sub config 1 from combined config", 0,
+                config.getInt("xmlReload1"));
+        c1.setReloadingStrategy(new FileAlwaysReloadingStrategy());
+        writeFile(testXmlFile, String.format(reloadContent, 1));
+        assertEquals("Reload of sub config 1 not detected", 1, config
+                .getInt("xmlReload1"));
+        assertTrue("XML file cannot be removed", testXmlFile.delete());
+    }
+
+    /**
      * Helper method for writing a file.
      *
      * @param file the file to be written

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java?rev=751505&r1=751504&r2=751505&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java
Sun Mar  8 19:24:58 2009
@@ -17,6 +17,7 @@
 package org.apache.commons.configuration2;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -25,6 +26,8 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.configuration2.event.ConfigurationEvent;
+import org.apache.commons.configuration2.event.ConfigurationListener;
 import org.apache.commons.configuration2.expr.ExpressionEngine;
 import org.apache.commons.configuration2.expr.xpath.XPathExpressionEngine;
 import org.apache.commons.configuration2.reloading.FileAlwaysReloadingStrategy;
@@ -364,6 +367,30 @@
     }
 
     /**
+     * Tests whether events are fired if a change of the parent is detected.
+     */
+    public void testParentReloadEvents() throws ConfigurationException
+    {
+        setUpReloadTest(true);
+        ConfigurationListenerTestImpl l = new ConfigurationListenerTestImpl();
+        config.addConfigurationListener(l);
+        config.getString("name");
+        assertEquals("Wrong number of events", 2, l.events.size());
+        boolean before = true;
+        for (ConfigurationEvent e : l.events)
+        {
+            assertEquals("Wrong configuration", config, e.getSource());
+            assertEquals("Wrong event type",
+                    HierarchicalConfiguration.EVENT_SUBNODE_CHANGED, e
+                            .getType());
+            assertNull("Got a property name", e.getPropertyName());
+            assertNull("Got a property value", e.getPropertyValue());
+            assertEquals("Wrong before flag", before, e.isBeforeUpdate());
+            before = !before;
+        }
+    }
+
+    /**
      * Tests a reload operation for the parent configuration when the subnode
      * configuration is aware of reloads, and the parent configuration is
      * accessed first. The new value should be returned.
@@ -519,4 +546,19 @@
     {
         config = new SubConfiguration<ConfigurationNode>(parent, getSubnodeRoot(parent));
     }
+
+    /**
+     * A specialized configuration listener for testing whether the expected
+     * events are fired.
+     */
+    private static class ConfigurationListenerTestImpl implements ConfigurationListener
+    {
+        /** Stores the events received.*/
+        final List<ConfigurationEvent> events = new ArrayList<ConfigurationEvent>();
+
+        public void configurationChanged(ConfigurationEvent event)
+        {
+            events.add(event);
+        }
+    }
 }

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=751505&r1=751504&r2=751505&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml Sun
Mar  8 19:24:58 2009
@@ -85,6 +85,12 @@
     </release>
 
     <release version="1.7" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-368">
+        SubnodeConfiguration now fires an event of type EVENT_SUBNODE_CHANGED
+        if a structural change of the parent configuration was detected. If the
+        SubnodeConfiguration is contained in a CombinedConfiguration, the
+        CombinedConfiguration receives this event and can update itself.
+      </action>
       <action dev="rgoers" type="fix" issue="CONFIGURATION-361">
         MultiFileHierarchicalConfiguration was not using basepath to
         construct the file url. It also threw an exception if the



Mime
View raw message