commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r645161 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/flat/ test/java/org/apache/commons/configuration2/flat/
Date Sat, 05 Apr 2008 19:00:43 GMT
Author: oheger
Date: Sat Apr  5 12:00:42 2008
New Revision: 645161

URL: http://svn.apache.org/viewvc?rev=645161&view=rev
Log:
Extracted mock implementation of AbstractFlatConfiguration into a top-level class; minor additions
to AbstractFlatConfiguration

Added:
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
  (with props)
Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java?rev=645161&r1=645160&r2=645161&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/flat/AbstractFlatConfiguration.java
Sat Apr  5 12:00:42 2008
@@ -58,29 +58,72 @@
 public abstract class AbstractFlatConfiguration extends AbstractConfiguration
 {
     /**
+     * Constant for the property change event. This event is triggered by
+     * <code>setPropertyValue()</code> and <code>clearPropertyValue()</code>,
+     * which manipulate a value of a property with multiple values.
+     */
+    public static final int EVENT_PROPERTY_CHANGED = 9;
+    
+    /**
      * Modifies a specific value of a property with multiple values. If a
      * property has multiple values, this method can be used to alter a specific
      * value (identified by its 0-based index) without affecting the other
      * values. If the index is invalid (i.e. less than 0 or greater than the
      * number of existing values), the value will be added to the existing
-     * values of this property.
+     * values of this property. This method takes care of firing the appropriate
+     * events and delegates to <code>setPropertyValueDirect()</code>. It generates
+     * a <code>EVENT_PROPERTY_CHANGED</code> event that contains the key of the
+     * affected property.
      *
      * @param key the key of the property
      * @param index the index of the value to change
      * @param value the new value; this should be a simple object; arrays or
      *        collections won't be treated specially, but directly added
      */
-    public abstract void setPropertyValue(String key, int index, Object value);
+    public void setPropertyValue(String key, int index, Object value)
+    {
+        fireEvent(EVENT_PROPERTY_CHANGED, key, null, true);
+        setPropertyValueDirect(key, index, value);
+        fireEvent(EVENT_PROPERTY_CHANGED, key, null, false);
+    }
 
     /**
      * Removes a specific value of a property with multiple values. If a
      * property has multiple values, this method can be used for removing a
      * single value (identified by its 0-based index). If the index is out of
      * range, no action is performed; in this case <b>false</b> is returned.
+     * This method takes care of firing the appropriate
+     * events and delegates to <code>clearPropertyValueDirect()</code>. It generates
+     * a <code>EVENT_PROPERTY_CHANGED</code> event that contains the key of the
+     * affected property.
      *
      * @param key the key of the property
      * @param index the index of the value to delete
      * @return a flag whether the value could be removed
      */
-    public abstract boolean clearPropertyValue(String key, int index);
+    public boolean clearPropertyValue(String key, int index)
+    {
+        fireEvent(EVENT_PROPERTY_CHANGED, key, null, true);
+        boolean result = clearPropertyValueDirect(key, index);
+        fireEvent(EVENT_PROPERTY_CHANGED, key, null, false);
+        return result;
+    }
+    
+    /**
+     * Performs the actual modification of the specified property value. This
+     * method is called by <code>setPropertyValue()</code>.
+     * @param key the key of the property
+     * @param index the index of the value to change
+     * @param value the new value
+     */
+    protected abstract void setPropertyValueDirect(String key, int index, Object value);
+    
+    /**
+     * Performs the actual remove property value operation. This method is called
+     * by <code>clearPropertyValue()</code>.
+     * @param key the key of the property
+     * @param index the index of the value to delete
+     * @return a flag whether the value could be removed
+     */
+    protected abstract boolean clearPropertyValueDirect(String key, int index);
 }

Added: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java?rev=645161&view=auto
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
(added)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
Sat Apr  5 12:00:42 2008
@@ -0,0 +1,105 @@
+/*
+ * 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.configuration2.flat;
+
+import java.util.Iterator;
+
+/**
+ * A mock implementation of a flat configuration. This mock class is used
+ * for testing whether properties are correctly accessed. Most methods are
+ * simply dummy implementations.
+ *
+ * @author <a href="http://commons.apache.org/configuration/team-list.html">Commons
+ *         Configuration team</a>
+ * @version $Id$
+ */
+class FlatConfigurationMockImpl extends AbstractFlatConfiguration
+{
+    /** Constant for the name of the test property. */
+    public static final String NAME = "testFlatNode";
+
+    /** Stores the value of the test property. */
+    Object property;
+
+    /** Stores the expected index. */
+    int expectedIndex;
+
+    /** A flag whether an add property operation is expected. */
+    boolean expectAdd;
+
+    /** A flag whether clearProperty() was called. */
+    boolean clearProperty;
+
+    @Override
+    public boolean clearPropertyValueDirect(String key, int index)
+    {
+        TestFlatNodes.assertEquals("Wrong property key", NAME, key);
+        clearProperty = true;
+        expectedIndex = index;
+        return true;
+    }
+
+    @Override
+    public void clearPropertyDirect(String key)
+    {
+        clearPropertyValue(key, FlatNode.INDEX_UNDEFINED);
+    }
+
+    @Override
+    public void setPropertyValueDirect(String key, int index, Object value)
+    {
+        TestFlatNodes.assertFalse("Add operation expected", expectAdd);
+        TestFlatNodes.assertEquals("Wrong property key", NAME, key);
+        TestFlatNodes.assertEquals("Wrong index", expectedIndex, index);
+        property = value;
+    }
+
+    @Override
+    public void setProperty(String key, Object value)
+    {
+        setPropertyValue(key, FlatNode.INDEX_UNDEFINED, value);
+    }
+
+    @Override
+    protected void addPropertyDirect(String key, Object value)
+    {
+        TestFlatNodes.assertTrue("Set operation expected", expectAdd);
+        TestFlatNodes.assertEquals("Wrong property key", NAME, key);
+        property = value;
+    }
+
+    public boolean containsKey(String key)
+    {
+        return false;
+    }
+
+    public Iterator<String> getKeys()
+    {
+        return null;
+    }
+
+    public Object getProperty(String key)
+    {
+        TestFlatNodes.assertEquals("Wrong property key", NAME, key);
+        return property;
+    }
+
+    public boolean isEmpty()
+    {
+        return false;
+    }
+}

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/FlatConfigurationMockImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java?rev=645161&r1=645160&r2=645161&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodeHandler.java
Sat Apr  5 12:00:42 2008
@@ -42,7 +42,7 @@
     private FlatNodeHandler handler;
 
     /** The mock configuration associated with the node handler. */
-    private TestFlatNodes.FlatConfigurationMockImpl config;
+    private FlatConfigurationMockImpl config;
 
     /** Stores the internal update flag of the node handler. */
     private Boolean internalUpdate;
@@ -51,7 +51,7 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-        config = new TestFlatNodes.FlatConfigurationMockImpl();
+        config = new FlatConfigurationMockImpl();
         config.clearConfigurationListeners();
         config.addConfigurationListener(new ConfigurationListener()
         {
@@ -191,7 +191,7 @@
     public void testAddChild()
     {
         FlatNode node = setUpTestNode();
-        final String childName = TestFlatNodes.NAME;
+        final String childName = FlatConfigurationMockImpl.NAME;
         FlatNode child = handler.addChild(node, childName);
         assertEquals("Wrong name of child", childName, child.getName());
         config.expectAdd = true;
@@ -206,7 +206,7 @@
     public void testRemoveChild()
     {
         FlatNode node = setUpTestNode();
-        FlatNode child = node.addChild(TestFlatNodes.NAME);
+        FlatNode child = node.addChild(FlatConfigurationMockImpl.NAME);
         handler.removeChild(node, child);
         List<FlatNode> children = node.getChildren();
         assertEquals("No child removed", CHILD_NAMES.length, children.size());
@@ -221,7 +221,7 @@
     public void testSetValue()
     {
         FlatNode node = setUpTestNode();
-        FlatNode child = node.addChild(TestFlatNodes.NAME);
+        FlatNode child = node.addChild(FlatConfigurationMockImpl.NAME);
         config.expectAdd = true;
         handler.setValue(child, TestFlatNodes.VALUE);
         assertEquals("Property not added to config", TestFlatNodes.VALUE,
@@ -235,7 +235,7 @@
     public void testGetValue()
     {
         FlatNode node = setUpTestNode();
-        FlatNode child = node.addChild(TestFlatNodes.NAME);
+        FlatNode child = node.addChild(FlatConfigurationMockImpl.NAME);
         config.property = TestFlatNodes.VALUE;
         assertEquals("Wrong value of node", TestFlatNodes.VALUE, handler
                 .getValue(child));

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java?rev=645161&r1=645160&r2=645161&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestFlatNodes.java
Sat Apr  5 12:00:42 2008
@@ -18,7 +18,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.configuration2.ConfigurationRuntimeException;
@@ -35,7 +34,7 @@
 public class TestFlatNodes extends TestCase
 {
     /** Constant for the name of the test node. */
-    static final String NAME = "testFlatNode";
+    private static final String NAME = FlatConfigurationMockImpl.NAME;
 
     /** Constant for a test value. */
     static final Object VALUE = 42;
@@ -464,86 +463,6 @@
         catch (ConfigurationRuntimeException crex)
         {
             // ok
-        }
-    }
-
-    /**
-     * A mock implementation of a flat configuration. This mock class is used
-     * for testing whether properties are correctly accessed. Most methods are
-     * simply dummy implementations.
-     */
-    static class FlatConfigurationMockImpl extends
-            AbstractFlatConfiguration
-    {
-        /** Stores the value of the test property. */
-        Object property;
-
-        /** Stores the expected index. */
-        int expectedIndex;
-
-        /** A flag whether an add property operation is expected. */
-        boolean expectAdd;
-
-        /** A flag whether clearProperty() was called. */
-        boolean clearProperty;
-
-        @Override
-        public boolean clearPropertyValue(String key, int index)
-        {
-            assertEquals("Wrong property key", NAME, key);
-            clearProperty = true;
-            expectedIndex = index;
-            return true;
-        }
-
-        @Override
-        public void clearPropertyDirect(String key)
-        {
-            clearPropertyValue(key, FlatNode.INDEX_UNDEFINED);
-        }
-
-        @Override
-        public void setPropertyValue(String key, int index, Object value)
-        {
-            assertFalse("Add operation expected", expectAdd);
-            assertEquals("Wrong property key", NAME, key);
-            assertEquals("Wrong index", expectedIndex, index);
-            property = value;
-        }
-
-        @Override
-        public void setProperty(String key, Object value)
-        {
-            setPropertyValue(key, FlatNode.INDEX_UNDEFINED, value);
-        }
-
-        @Override
-        protected void addPropertyDirect(String key, Object value)
-        {
-            assertTrue("Set operation expected", expectAdd);
-            assertEquals("Wrong property key", NAME, key);
-            property = value;
-        }
-
-        public boolean containsKey(String key)
-        {
-            return false;
-        }
-
-        public Iterator<String> getKeys()
-        {
-            return null;
-        }
-
-        public Object getProperty(String key)
-        {
-            assertEquals("Wrong property key", NAME, key);
-            return property;
-        }
-
-        public boolean isEmpty()
-        {
-            return false;
         }
     }
 }



Mime
View raw message