Author: oheger
Date: Fri Feb  7 20:32:26 2014
New Revision: 1565791

URL: http://svn.apache.org/r1565791
Log:
Reworked AbstractXPathTest.

This base class (which provides common functionality for tests of several
implementation classes of the XPath expression engine) now operates on
ImmutableNode objects which can be accessed by a NodeHandler object.

Modified:
    
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java

Modified: 
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java?rev=1565791&r1=1565790&r2=1565791&view=diff
==============================================================================
--- 
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java
 (original)
+++ 
commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java
 Fri Feb  7 20:32:26 2014
@@ -19,9 +19,11 @@ package org.apache.commons.configuration
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.configuration.tree.ConfigurationNode;
-import org.apache.commons.configuration.tree.DefaultConfigurationNode;
+import org.apache.commons.configuration.tree.ImmutableNode;
+import org.apache.commons.configuration.tree.InMemoryNodeModel;
+import org.apache.commons.configuration.tree.NodeHandler;
 import org.apache.commons.jxpath.ri.model.NodeIterator;
+import org.apache.commons.jxpath.ri.model.NodePointer;
 import org.junit.After;
 import org.junit.Before;
 
@@ -30,9 +32,6 @@ import org.junit.Before;
  * creates a hierarchy of nodes in its setUp() method that can be used for test
  * cases.
  *
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html";>Commons
- * Configuration team</a>
  * @version $Id$
  */
 public abstract class AbstractXPathTest
@@ -53,12 +52,16 @@ public abstract class AbstractXPathTest
     protected static final int LEVEL_COUNT = 3;
 
     /** Stores the root node of the hierarchy. */
-    protected ConfigurationNode root;
+    protected ImmutableNode root;
+
+    /** The node handler. */
+    protected NodeHandler<ImmutableNode> handler;
 
     @Before
     public void setUp() throws Exception
     {
         root = constructHierarchy(LEVEL_COUNT);
+        handler = new InMemoryNodeModel(root);
     }
 
     /**
@@ -80,11 +83,11 @@ public abstract class AbstractXPathTest
      * @param levels the number of levels in the hierarchy
      * @return the root node of the hierarchy
      */
-    protected ConfigurationNode constructHierarchy(int levels)
+    protected ImmutableNode constructHierarchy(int levels)
     {
-        ConfigurationNode result = new DefaultConfigurationNode();
-        createLevel(result, levels);
-        return result;
+        ImmutableNode.Builder resultBuilder = new ImmutableNode.Builder();
+        createLevel(resultBuilder, null, levels);
+        return resultBuilder.create();
     }
 
     /**
@@ -111,19 +114,18 @@ public abstract class AbstractXPathTest
     }
 
     /**
-     * Returns a list with all configuration nodes contained in the specified
-     * iteration. It is assumed that the iteration contains only elements of
-     * this type.
+     * Returns a list with all node pointers contained in the specified
+     * iteration.
      *
      * @param iterator the iterator
-     * @return a list with configuration nodes obtained from the iterator
+     * @return a list with the node pointers obtained from the iterator
      */
-    protected List<ConfigurationNode> iterationElements(NodeIterator iterator)
+    protected List<NodePointer> iterationElements(NodeIterator iterator)
     {
-        List<ConfigurationNode> result = new ArrayList<ConfigurationNode>();
+        List<NodePointer> result = new ArrayList<NodePointer>();
         for (int pos = 1; iterator.setPosition(pos); pos++)
         {
-            result.add((ConfigurationNode) 
iterator.getNodePointer().getNode());
+            result.add(iterator.getNodePointer());
         }
         return result;
     }
@@ -131,25 +133,26 @@ public abstract class AbstractXPathTest
     /**
      * Recursive helper method for creating a level of the node hierarchy.
      *
-     * @param parent the parent node
+     * @param parentBuilder the builder for the parent node
+     * @param value the value of the parent node
      * @param level the level counter
      */
-    private void createLevel(ConfigurationNode parent, int level)
+    private void createLevel(ImmutableNode.Builder parentBuilder, String value,
+            int level)
     {
         if (level >= 0)
         {
-            String prefix = (parent.getValue() == null) ? "" : parent
-                    .getValue()
-                    + ".";
+            String prefix = (value == null) ? "" : value + ".";
             for (int i = 1; i <= CHILD_COUNT; i++)
             {
-                ConfigurationNode child = new DefaultConfigurationNode(
-                        (i % 2 == 0) ? CHILD_NAME1 : CHILD_NAME2, prefix + i);
-                parent.addChild(child);
-                child.addAttribute(new DefaultConfigurationNode(ATTR_NAME,
-                        String.valueOf(i)));
-
-                createLevel(child, level - 1);
+                ImmutableNode.Builder childBuilder =
+                        new ImmutableNode.Builder();
+                childBuilder.name((i % 2 == 0) ? CHILD_NAME1 : CHILD_NAME2);
+                String currentValue = prefix + i;
+                childBuilder.value(currentValue);
+                createLevel(childBuilder, currentValue, level - 1);
+                childBuilder.addAttribute(ATTR_NAME, String.valueOf(i));
+                parentBuilder.addChild(childBuilder.create());
             }
         }
     }


Reply via email to