commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r829639 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/flat/ test/java/org/apache/commons/configuration2/flat/
Date Sun, 25 Oct 2009 20:33:23 GMT
Author: oheger
Date: Sun Oct 25 20:33:22 2009
New Revision: 829639

URL: http://svn.apache.org/viewvc?rev=829639&view=rev
Log:
AbstractFlatConfiguration now sets an expression engine per default that does not use the
dot as property delimiter. This makes it more compatible with property keys that contain dots
(which is a common pattern).

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/TestAbstractFlatConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestBaseConfiguration.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=829639&r1=829638&r2=829639&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
Sun Oct 25 20:33:22 2009
@@ -24,6 +24,7 @@
 import org.apache.commons.configuration2.AbstractHierarchicalConfiguration;
 import org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.commons.configuration2.event.ConfigurationListener;
+import org.apache.commons.configuration2.expr.def.DefaultExpressionEngine;
 
 /**
  * <p>
@@ -64,6 +65,9 @@
  */
 public abstract class AbstractFlatConfiguration extends AbstractHierarchicalConfiguration<FlatNode>
 {
+    /** Constant for the default property delimiter. */
+    private static final String DEF_PROPERTY_DELIMITER = "|";
+
     /** Stores the root node of this configuration. */
     private FlatNode rootNode;
 
@@ -78,6 +82,7 @@
         super(null);
         lockRoot = new ReentrantLock();
         initNodeHandler();
+        initExpressionEngine();
         registerChangeListener();
     }
 
@@ -248,6 +253,20 @@
     }
 
     /**
+     * Initializes the expression engine of this configuration. Per default an
+     * expression engine is used with a special property delimiter that does not
+     * interfere with the dot character (which frequently appears in
+     * configuration keys).
+     */
+    private void initExpressionEngine()
+    {
+        DefaultExpressionEngine expr = new DefaultExpressionEngine();
+        expr.setPropertyDelimiter(DEF_PROPERTY_DELIMITER);
+        expr.setEscapedDelimiter(DEF_PROPERTY_DELIMITER + DEF_PROPERTY_DELIMITER);
+        setExpressionEngine(expr);
+    }
+
+    /**
      * Registers a change listener at this configuration that causes the node
      * structure to be invalidated whenever the content is changed.
      */

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestAbstractFlatConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestAbstractFlatConfiguration.java?rev=829639&r1=829638&r2=829639&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestAbstractFlatConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestAbstractFlatConfiguration.java
Sun Oct 25 20:33:22 2009
@@ -16,11 +16,18 @@
  */
 package org.apache.commons.configuration2.flat;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
-import junit.framework.TestCase;
+import org.apache.commons.configuration2.expr.def.DefaultExpressionEngine;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * A test class for the basic functionality of flat configuration classes.
@@ -29,7 +36,7 @@
  *         Configuration team</a>
  * @version $Id$
  */
-public class TestAbstractFlatConfiguration extends TestCase
+public class TestAbstractFlatConfiguration
 {
     /** An array with the keys of the test configuration. */
     private static final String[] KEYS = {
@@ -49,10 +56,9 @@
     /** The configuration to be tested. */
     private FlatConfigurationMockImpl config;
 
-    @Override
-    protected void setUp() throws Exception
+    @Before
+    public void setUp() throws Exception
     {
-        super.setUp();
         config = new FlatConfigurationMockImpl();
     }
 
@@ -150,6 +156,7 @@
     /**
      * Tests querying the node handler of the flat configuration.
      */
+    @Test
     public void testGetNodeHandler()
     {
         assertNotNull("No node handler", config.getNodeHandler());
@@ -158,6 +165,7 @@
     /**
      * Tests querying the root node of a flat configuration.
      */
+    @Test
     public void testGetRootNode()
     {
         prepareGetRootNode(1);
@@ -169,6 +177,7 @@
      * Tests an external update of the configuration. This should cause the node
      * structure to be invalidated.
      */
+    @Test
     public void testGetRootNodeExternalUpdate()
     {
         prepareGetRootNode(2);
@@ -184,6 +193,7 @@
      * Tests an internal update of the node structure. This should not cause the
      * node structure to be re-created.
      */
+    @Test
     public void testGetRootNodeInternalUpdate()
     {
         prepareGetRootNode(1);
@@ -202,6 +212,7 @@
      * Tests cloning a flat configuration. We have to check whether the event
      * listeners are correctly registered.
      */
+    @Test
     public void testClone() throws CloneNotSupportedException
     {
         prepareGetRootNode(1);
@@ -215,4 +226,16 @@
         copy.clearProperty(FlatConfigurationMockImpl.NAME);
         assertNotSame("Structure was not re-created", root, copy.getRootNode());
     }
+
+    /**
+     * Tests whether a correct expression engine is set.
+     */
+    @Test
+    public void testExpressionEngine()
+    {
+        DefaultExpressionEngine expr = (DefaultExpressionEngine) config
+                .getExpressionEngine();
+        assertEquals("Wrong default property delimiter", "|", expr
+                .getPropertyDelimiter());
+    }
 }

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestBaseConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestBaseConfiguration.java?rev=829639&r1=829638&r2=829639&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestBaseConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/flat/TestBaseConfiguration.java
Sun Oct 25 20:33:22 2009
@@ -36,6 +36,7 @@
 import org.apache.commons.configuration2.InterpolationTestHelper;
 import org.apache.commons.configuration2.event.ConfigurationEvent;
 import org.apache.commons.configuration2.event.ConfigurationListener;
+import org.apache.commons.configuration2.expr.NodeList;
 
 /**
  * Tests some basic functions of the BaseConfiguration class. Missing keys will
@@ -809,4 +810,17 @@
         assertEquals("Wrong max index for multiple values", count - 1, config
                 .getMaxIndex(TEST_KEY));
     }
+
+    /**
+     * Tests whether a query using the expression engine can be issued.
+     */
+    public void testQueryExpressionEngine()
+    {
+        config.getStore().put("test.key", 42);
+        NodeList<FlatNode> list = config.getExpressionEngine().query(
+                config.getRootNode(), "test.key", config.getNodeHandler());
+        assertEquals("Wrong number of nodes", 1, list.size());
+        assertEquals("Wrong value", 42, list.getValue(0, config
+                .getNodeHandler()));
+    }
 }



Mime
View raw message