commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1588831 [10/11] - in /commons/proper/configuration/trunk: ./ src/main/java/org/apache/commons/configuration/ src/main/java/org/apache/commons/configuration/beanutils/ src/main/java/org/apache/commons/configuration/builder/combined/ src/mai...
Date Sun, 20 Apr 2014 19:32:10 GMT
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/AbstractCombinerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/AbstractCombinerTest.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/AbstractCombinerTest.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/AbstractCombinerTest.java Sun Apr 20 19:32:08 2014
@@ -40,10 +40,10 @@ import org.junit.Test;
 public abstract class AbstractCombinerTest
 {
     /** Constant for the first test configuration. */
-    static File CONF1 = ConfigurationAssert.getTestFile("testcombine1.xml");
+    private static final File CONF1 = ConfigurationAssert.getTestFile("testcombine1.xml");
 
     /** Constant for the second test configuration. */
-    static File CONF2 = ConfigurationAssert.getTestFile("testcombine2.xml");
+    private static final File CONF2 = ConfigurationAssert.getTestFile("testcombine2.xml");
 
     /** The combiner to be tested. */
     protected NodeCombiner combiner;
@@ -56,7 +56,7 @@ public abstract class AbstractCombinerTe
 
     /**
      * Creates the combiner to be tested. This method is called by
-     * <code>setUp()</code>. It must be implemented in concrete sub classes.
+     * {@code setUp()}. It must be implemented in concrete sub classes.
      *
      * @return the combiner to be tested
      */
@@ -75,7 +75,7 @@ public abstract class AbstractCombinerTe
         new FileHandler(conf1).load(CONF1);
         XMLConfiguration conf2 = new XMLConfiguration();
         new FileHandler(conf2).load(CONF2);
-        ConfigurationNode cn = combiner.combine(conf1.getRootNode(), conf2
+        ImmutableNode cn = combiner.combine(conf1.getRootNode(), conf2
                 .getRootNode());
 
         BaseHierarchicalConfiguration result = new BaseHierarchicalConfiguration();
@@ -92,7 +92,6 @@ public abstract class AbstractCombinerTe
     {
         assertTrue("Combiner has list nodes", combiner.getListNodes().isEmpty());
         assertFalse("Node is list node", combiner
-                .isListNode(new DefaultConfigurationNode("test")));
+                .isListNode(NodeStructureHelper.createNode("test", null)));
     }
-
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestDefaultExpressionEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestDefaultExpressionEngine.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestDefaultExpressionEngine.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestDefaultExpressionEngine.java Sun Apr 20 19:32:08 2014
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
@@ -51,16 +52,25 @@ public class TestDefaultExpressionEngine
     { "uid", "uname", "firstName", "lastName", "email"},
     { "docid", "name", "creationDate", "authorID", "version"}};
 
+    /** The root of a hierarchy with test nodes. */
+    private static ImmutableNode root;
+
+    /** A node handler for the hierarchy of test nodes. */
+    private static NodeHandler<ImmutableNode> handler;
+
     /** The object to be tested. */
     private DefaultExpressionEngine engine;
 
-    /** The root of a hierarchy with configuration nodes. */
-    private ConfigurationNode root;
+    @BeforeClass
+    public static void setUpBeforeClass()
+    {
+        root = setUpNodes();
+        handler = new InMemoryNodeModel(root).getNodeHandler();
+    }
 
     @Before
     public void setUp() throws Exception
     {
-        root = setUpNodes();
         engine = DefaultExpressionEngine.INSTANCE;
     }
 
@@ -107,7 +117,8 @@ public class TestDefaultExpressionEngine
         for (int i = 0; i < tables.length; i++)
         {
             checkKeyValue("tables.table(" + i + ").name", "name", tables[i]);
-            checkKeyValue("tables.table(" + i + ")[@type]", "type", tabTypes[i]);
+            checkAttributeValue("tables.table(" + i + ")[@type]", "type",
+                    tabTypes[i]);
 
             for (int j = 0; j < fields[i].length; j++)
             {
@@ -130,6 +141,7 @@ public class TestDefaultExpressionEngine
         checkKey("tables.table(0).fields.field(28).name", null, 0);
         checkKey("tables.table(0).fields.field().name", null, 0);
         checkKey("connection.settings.usr.name", null, 0);
+        checkKey("tables.table(0)[@type].additional", null, 0);
     }
 
     /**
@@ -158,21 +170,48 @@ public class TestDefaultExpressionEngine
                         .create();
         engine = new DefaultExpressionEngine(symbols);
         checkKeyValue("tables.table(0).name", "name", tables[0]);
-        checkKeyValue("tables.table(0).type", "type", tabTypes[0]);
+        checkAttributeValue("tables.table(0).type", "type", tabTypes[0]);
         checkKey("tables.table.type", "type", 2);
     }
 
     /**
-     * Tests accessing the root node.
+     * Helper method for testing a query for the root node.
+     *
+     * @param key the key to be used
+     */
+    private void checkQueryRootNode(String key)
+    {
+        List<QueryResult<ImmutableNode>> results = checkKey(key, null, 1);
+        QueryResult<ImmutableNode> result = results.get(0);
+        assertFalse("No node result", result.isAttributeResult());
+        assertSame("Not the root node", root, result.getNode());
+    }
+
+    /**
+     * Tests whether the root node can be retrieved using the null key.
+     */
+    @Test
+    public void testQueryRootNodeNullKey()
+    {
+        checkQueryRootNode(null);
+    }
+
+    /**
+     * Tests whether the root node can be retrieved using the empty key.
+     */
+    @Test
+    public void testQueryRootNodeEmptyKey()
+    {
+        checkQueryRootNode("");
+    }
+
+    /**
+     * Tests whether an attribute of the root node can be queried.
      */
     @Test
-    public void testQueryRootNode()
+    public void testQueryRootAttribute()
     {
-        List<ConfigurationNode> nodes = checkKey(null, null, 1);
-        assertSame("Root node not found", root, nodes.get(0));
-        nodes = checkKey("", null, 1);
-        assertSame("Root node not found", root, nodes.get(0));
-        checkKeyValue("[@test]", "test", "true");
+        checkAttributeValue("[@test]", "test", "true");
     }
 
     /**
@@ -184,8 +223,8 @@ public class TestDefaultExpressionEngine
     {
         setUpAlternativeSyntax();
         checkKeyValue("tables/table[1]/name", "name", tables[1]);
-        checkKeyValue("tables/table[0]@type", "type", tabTypes[0]);
-        checkKeyValue("@test", "test", "true");
+        checkAttributeValue("tables/table[0]@type", "type", tabTypes[0]);
+        checkAttributeValue("@test", "test", "true");
         checkKeyValue("connection.settings/usr.name", "usr.name", "scott");
     }
 
@@ -195,39 +234,56 @@ public class TestDefaultExpressionEngine
     @Test
     public void testNodeKey()
     {
-        ConfigurationNode node = root.getChild(0);
+        ImmutableNode node = root.getChildren().get(0);
         assertEquals("Invalid name for descendant of root", "tables", engine
-                .nodeKey(node, ""));
+                .nodeKey(node, "", handler));
         assertEquals("Parent key not respected", "test.tables", engine.nodeKey(
-                node, "test"));
+                node, "test", handler));
         assertEquals("Full parent key not taken into account",
                 "a.full.parent.key.tables", engine.nodeKey(node,
-                        "a.full.parent.key"));
+                "a.full.parent.key", handler));
     }
 
     /**
-     * Tests obtaining keys when the root node is involved.
+     * Tests obtaining keys if the root node is involved.
      */
     @Test
     public void testNodeKeyWithRoot()
     {
-        assertEquals("Wrong name for root noot", "", engine.nodeKey(root, null));
-        assertEquals("Null name not detected", "test", engine.nodeKey(root,
-                "test"));
+        assertEquals("Wrong name for root node", "",
+                engine.nodeKey(root, null, handler));
+        assertEquals("Null name not detected", "test",
+                engine.nodeKey(root, "test", handler));
     }
 
     /**
      * Tests obtaining keys for attribute nodes.
      */
     @Test
-    public void testNodeKeyWithAttribute()
+    public void testAttributeKey()
     {
-        ConfigurationNode node = root.getChild(0).getChild(0).getAttribute(0);
-        assertEquals("Wrong attribute node", "type", node.getName());
         assertEquals("Wrong attribute key", "tables.table[@type]", engine
-                .nodeKey(node, "tables.table"));
-        assertEquals("Wrong key for root attribute", "[@test]", engine.nodeKey(
-                root.getAttribute(0), ""));
+                .attributeKey("tables.table", "type"));
+    }
+
+    /**
+     * Tests whether an attribute key can be queried if the root node is involved.
+     */
+    @Test
+    public void testAttributeKeyRoot()
+    {
+        assertEquals("Wrong key for root attribute", "[@test]",
+                engine.attributeKey("", "test"));
+    }
+
+    /**
+     * Tests that a null parent key is ignored when constructing an attribute key.
+     */
+    @Test
+    public void testAttributeKeyNoParent()
+    {
+        assertEquals("Wrong key for null parent", "[@test]",
+                engine.attributeKey(null, "test"));
     }
 
     /**
@@ -236,12 +292,14 @@ public class TestDefaultExpressionEngine
     @Test
     public void testNodeKeyWithEscapedDelimiters()
     {
-        ConfigurationNode node = root.getChild(1);
-        assertEquals("Wrong escaped key", "connection..settings", engine
-                .nodeKey(node, ""));
-        assertEquals("Wrong complex escaped key",
-                "connection..settings.usr..name", engine.nodeKey(node
-                        .getChild(0), engine.nodeKey(node, "")));
+        ImmutableNode node = root.getChildren().get(1);
+        assertEquals("Wrong escaped key", "connection..settings",
+                engine.nodeKey(node, "", handler));
+        assertEquals(
+                "Wrong complex escaped key",
+                "connection..settings.usr..name",
+                engine.nodeKey(node.getChildren().get(0),
+                        engine.nodeKey(node, "", handler), handler));
     }
 
     /**
@@ -252,9 +310,19 @@ public class TestDefaultExpressionEngine
     {
         setUpAlternativeSyntax();
         assertEquals("Wrong child key", "tables/table", engine.nodeKey(root
-                .getChild(0).getChild(0), "tables"));
-        assertEquals("Wrong attribute key", "@test", engine.nodeKey(root
-                .getAttribute(0), ""));
+                .getChildren().get(0).getChildren().get(0), "tables", handler));
+    }
+
+    /**
+     * Tests whether a correct attribute key with alternative syntax is
+     * generated.
+     */
+    @Test
+    public void testAttributeKeyWithAlternativeSyntax()
+    {
+        setUpAlternativeSyntax();
+        assertEquals("Wrong attribute key", "@test",
+                engine.attributeKey("", "test"));
     }
 
     /**
@@ -272,7 +340,7 @@ public class TestDefaultExpressionEngine
                         .create();
         engine = new DefaultExpressionEngine(symbols);
         assertEquals("Wrong attribute key", "/test",
-                engine.nodeKey(root.getAttribute(0), ""));
+                engine.attributeKey("", "test"));
     }
 
     /**
@@ -281,43 +349,43 @@ public class TestDefaultExpressionEngine
     @Test
     public void testPrepareAddDirectly()
     {
-        NodeAddData data = engine.prepareAdd(root, "newNode");
+        NodeAddData<ImmutableNode> data = engine.prepareAdd(root, "newNode", handler);
         assertSame("Wrong parent node", root, data.getParent());
         assertTrue("Path nodes available", data.getPathNodes().isEmpty());
         assertEquals("Wrong name of new node", "newNode", data.getNewNodeName());
         assertFalse("New node is an attribute", data.isAttribute());
 
-        data = engine.prepareAdd(root, "tables.table.fields.field.name");
+        data = engine.prepareAdd(root, "tables.table.fields.field.name", handler);
         assertEquals("Wrong name of new node", "name", data.getNewNodeName());
         assertTrue("Path nodes available", data.getPathNodes().isEmpty());
-        assertEquals("Wrong parent node", "field", data.getParent().getName());
-        ConfigurationNode nd = data.getParent().getChild(0);
-        assertEquals("Field has no name node", "name", nd.getName());
+        assertEquals("Wrong parent node", "field", data.getParent().getNodeName());
+        ImmutableNode nd = data.getParent().getChildren().get(0);
+        assertEquals("Field has no name node", "name", nd.getNodeName());
         assertEquals("Incorrect name", "version", nd.getValue());
     }
 
     /**
-     * Tests adding when indices are involved.
+     * Tests adding if indices are involved.
      */
     @Test
     public void testPrepareAddWithIndex()
     {
-        NodeAddData data = engine
-                .prepareAdd(root, "tables.table(0).tableSpace");
+        NodeAddData<ImmutableNode> data = engine
+                .prepareAdd(root, "tables.table(0).tableSpace", handler);
         assertEquals("Wrong name of new node", "tableSpace", data
                 .getNewNodeName());
         assertTrue("Path nodes available", data.getPathNodes().isEmpty());
         assertEquals("Wrong type of parent node", "table", data.getParent()
-                .getName());
-        ConfigurationNode node = data.getParent().getChild(0);
+                .getNodeName());
+        ImmutableNode node = data.getParent().getChildren().get(0);
         assertEquals("Wrong table", tables[0], node.getValue());
 
-        data = engine.prepareAdd(root, "tables.table(1).fields.field(2).alias");
+        data = engine.prepareAdd(root, "tables.table(1).fields.field(2).alias", handler);
         assertEquals("Wrong name of new node", "alias", data.getNewNodeName());
         assertEquals("Wrong type of parent node", "field", data.getParent()
-                .getName());
+                .getNodeName());
         assertEquals("Wrong field node", "creationDate", data.getParent()
-                .getChild(0).getValue());
+                .getChildren().get(0).getValue());
     }
 
     /**
@@ -326,16 +394,23 @@ public class TestDefaultExpressionEngine
     @Test
     public void testPrepareAddAttribute()
     {
-        NodeAddData data = engine.prepareAdd(root,
-                "tables.table(0)[@tableSpace]");
+        NodeAddData<ImmutableNode> data = engine.prepareAdd(root,
+                "tables.table(0)[@tableSpace]", handler);
         assertEquals("Wrong table node", tables[0], data.getParent()
-                .getChild(0).getValue());
+                .getChildren().get(0).getValue());
         assertEquals("Wrong name of new node", "tableSpace", data
                 .getNewNodeName());
         assertTrue("Attribute not detected", data.isAttribute());
         assertTrue("Path nodes available", data.getPathNodes().isEmpty());
+    }
 
-        data = engine.prepareAdd(root, "[@newAttr]");
+    /**
+     * Tests whether an attribute to the root node can be added.
+     */
+    @Test
+    public void testPrepareAddAttributeRoot()
+    {
+        NodeAddData<ImmutableNode> data = engine.prepareAdd(root, "[@newAttr]", handler);
         assertSame("Root node is not parent", root, data.getParent());
         assertEquals("Wrong name of new node", "newAttr", data.getNewNodeName());
         assertTrue("Attribute not detected", data.isAttribute());
@@ -347,25 +422,22 @@ public class TestDefaultExpressionEngine
     @Test
     public void testPrepareAddWithPath()
     {
-        NodeAddData data = engine.prepareAdd(root,
-                "tables.table(1).fields.field(-1).name");
+        NodeAddData<ImmutableNode> data = engine.prepareAdd(root,
+                "tables.table(1).fields.field(-1).name", handler);
         assertEquals("Wrong name of new node", "name", data.getNewNodeName());
-        checkNodePath(data, new String[]
-        { "field"});
+        checkNodePath(data, "field");
         assertEquals("Wrong type of parent node", "fields", data.getParent()
-                .getName());
+                .getNodeName());
 
-        data = engine.prepareAdd(root, "tables.table(-1).name");
+        data = engine.prepareAdd(root, "tables.table(-1).name", handler);
         assertEquals("Wrong name of new node", "name", data.getNewNodeName());
-        checkNodePath(data, new String[]
-        { "table"});
+        checkNodePath(data, "table");
         assertEquals("Wrong type of parent node", "tables", data.getParent()
-                .getName());
+                .getNodeName());
 
-        data = engine.prepareAdd(root, "a.complete.new.path");
+        data = engine.prepareAdd(root, "a.complete.new.path", handler);
         assertEquals("Wrong name of new node", "path", data.getNewNodeName());
-        checkNodePath(data, new String[]
-        { "a", "complete", "new"});
+        checkNodePath(data, "a", "complete", "new");
         assertSame("Root is not parent", root, data.getParent());
     }
 
@@ -385,16 +457,16 @@ public class TestDefaultExpressionEngine
                                         .getPropertyDelimiter()).create();
         engine = new DefaultExpressionEngine(symbols);
 
-        NodeAddData data = engine.prepareAdd(root, "tables.table(0).test");
+        NodeAddData<ImmutableNode> data =
+                engine.prepareAdd(root, "tables.table(0).test", handler);
         assertEquals("Wrong name of new node", "test", data.getNewNodeName());
         assertFalse("New node is an attribute", data.isAttribute());
         assertEquals("Wrong type of parent node", "table", data.getParent()
-                .getName());
+                .getNodeName());
 
-        data = engine.prepareAdd(root, "a.complete.new.path");
+        data = engine.prepareAdd(root, "a.complete.new.path", handler);
         assertFalse("New node is an attribute", data.isAttribute());
-        checkNodePath(data, new String[]
-        { "a", "complete", "new"});
+        checkNodePath(data, "a", "complete", "new");
     }
 
     /**
@@ -404,17 +476,17 @@ public class TestDefaultExpressionEngine
     public void testPrepareAddWithAlternativeSyntax()
     {
         setUpAlternativeSyntax();
-        NodeAddData data = engine.prepareAdd(root, "tables/table[0]/test");
+        NodeAddData<ImmutableNode> data =
+                engine.prepareAdd(root, "tables/table[0]/test", handler);
         assertEquals("Wrong name of new node", "test", data.getNewNodeName());
         assertFalse("New node is attribute", data.isAttribute());
-        assertEquals("Wrong parent node", tables[0], data.getParent().getChild(
-                0).getValue());
+        assertEquals("Wrong parent node", tables[0], data.getParent()
+                .getChildren().get(0).getValue());
 
-        data = engine.prepareAdd(root, "a/complete/new/path@attr");
+        data = engine.prepareAdd(root, "a/complete/new/path@attr", handler);
         assertEquals("Wrong name of new attribute", "attr", data
                 .getNewNodeName());
-        checkNodePath(data, new String[]
-        { "a", "complete", "new", "path"});
+        checkNodePath(data, "a", "complete", "new", "path");
         assertSame("Root is not parent", root, data.getParent());
     }
 
@@ -425,27 +497,88 @@ public class TestDefaultExpressionEngine
     @Test(expected = IllegalArgumentException.class)
     public void testPrepareAddInvalidKey()
     {
-        engine.prepareAdd(root, "tables.table(0)[@type].new");
+        engine.prepareAdd(root, "tables.table(0)[@type].new", handler);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testPrepareAddInvalidKeyAttribute()
     {
-        engine
-        .prepareAdd(root,
-                "a.complete.new.path.with.an[@attribute].at.a.non.allowed[@position]");
+        engine.prepareAdd(
+                root,
+                "a.complete.new.path.with.an[@attribute].at.a.non.allowed[@position]",
+                handler);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testPrepareAddNullKey()
     {
-        engine.prepareAdd(root, null);
+        engine.prepareAdd(root, null, handler);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testPrepareAddEmptyKey()
     {
-        engine.prepareAdd(root, "");
+        engine.prepareAdd(root, "", handler);
+    }
+
+    /**
+     * Tests whether a canonical key can be queried if all child nodes have
+     * different names.
+     */
+    @Test
+    public void testCanonicalKeyNoDuplicates()
+    {
+        ImmutableNode node = fetchNode("tables.table(0).name");
+        assertEquals("Wrong canonical key", "table.name(0)",
+                engine.canonicalKey(node, "table", handler));
+    }
+
+    /**
+     * Tests whether duplicates are correctly resolved when querying for
+     * canonical keys.
+     */
+    @Test
+    public void testCanonicalKeyWithDuplicates()
+    {
+        ImmutableNode tab1 = fetchNode("tables.table(0)");
+        ImmutableNode tab2 = fetchNode("tables.table(1)");
+        assertEquals("Wrong key 1", "tables.table(0)",
+                engine.canonicalKey(tab1, "tables", handler));
+        assertEquals("Wrong key 2", "tables.table(1)",
+                engine.canonicalKey(tab2, "tables", handler));
+    }
+
+    /**
+     * Tests whether the parent key can be undefined when querying a canonical
+     * key.
+     */
+    @Test
+    public void testCanonicalKeyNoParentKey()
+    {
+        ImmutableNode node = fetchNode("tables.table(0).fields.field(1).name");
+        assertEquals("Wrong key", "name(0)",
+                engine.canonicalKey(node, null, handler));
+    }
+
+    /**
+     * Tests whether a canonical key for the parent node can be queried if no
+     * parent key was passed in.
+     */
+    @Test
+    public void testCanonicalKeyRootNoParentKey()
+    {
+        assertEquals("Wrong key", "", engine.canonicalKey(root, null, handler));
+    }
+
+    /**
+     * Tests whether a parent key is evaluated when determining the canonical
+     * key of the root node.
+     */
+    @Test
+    public void testCanonicalKeyRootWithParentKey()
+    {
+        assertEquals("Wrong key", "parent",
+                engine.canonicalKey(root, "parent", handler));
     }
 
     /**
@@ -465,39 +598,41 @@ public class TestDefaultExpressionEngine
      *
      * @return the root of the test node hierarchy
      */
-    protected ConfigurationNode setUpNodes()
+    private static ImmutableNode setUpNodes()
     {
-        DefaultConfigurationNode rootNode = new DefaultConfigurationNode();
-
-        DefaultConfigurationNode nodeTables = new DefaultConfigurationNode(
-                "tables");
-        rootNode.addChild(nodeTables);
+        ImmutableNode.Builder nodeTablesBuilder =
+                new ImmutableNode.Builder(tables.length);
+        nodeTablesBuilder.name("tables");
         for (int i = 0; i < tables.length; i++)
         {
-            DefaultConfigurationNode nodeTable = new DefaultConfigurationNode(
-                    "table");
-            nodeTables.addChild(nodeTable);
-            nodeTable.addChild(new DefaultConfigurationNode("name", tables[i]));
-            nodeTable.addAttribute(new DefaultConfigurationNode("type",
-                    tabTypes[i]));
-            DefaultConfigurationNode nodeFields = new DefaultConfigurationNode(
-                    "fields");
-            nodeTable.addChild(nodeFields);
+            ImmutableNode.Builder nodeTableBuilder =
+                    new ImmutableNode.Builder(2);
+            nodeTableBuilder.name("table");
+            nodeTableBuilder.addChild(new ImmutableNode.Builder().name("name")
+                    .value(tables[i]).create());
+            nodeTableBuilder.addAttribute("type", tabTypes[i]);
 
+            ImmutableNode.Builder nodeFieldsBuilder =
+                    new ImmutableNode.Builder(fields[i].length);
             for (int j = 0; j < fields[i].length; j++)
             {
-                nodeFields.addChild(createFieldNode(fields[i][j]));
+                nodeFieldsBuilder.addChild(createFieldNode(fields[i][j]));
             }
+            nodeTableBuilder
+                    .addChild(nodeFieldsBuilder.name("fields").create());
+            nodeTablesBuilder.addChild(nodeTableBuilder.create());
         }
 
-        DefaultConfigurationNode nodeConn = new DefaultConfigurationNode(
-                "connection.settings");
-        rootNode.addChild(nodeConn);
-        nodeConn.addChild(new DefaultConfigurationNode("usr.name", "scott"));
-        nodeConn.addChild(new DefaultConfigurationNode("usr.pwd", "tiger"));
-        rootNode.addAttribute(new DefaultConfigurationNode("test", "true"));
+        ImmutableNode.Builder rootBuilder = new ImmutableNode.Builder();
+        rootBuilder.addChild(nodeTablesBuilder.create());
+        ImmutableNode.Builder nodeConnBuilder = new ImmutableNode.Builder();
+        nodeConnBuilder.name("connection.settings");
+        nodeConnBuilder.addChild(createNode("usr.name", "scott"));
+        nodeConnBuilder.addChild(createNode("usr.pwd", "tiger"));
+        rootBuilder.addAttribute("test", "true");
+        rootBuilder.addChild(nodeConnBuilder.create());
 
-        return rootNode;
+        return rootBuilder.create();
     }
 
     /**
@@ -522,19 +657,55 @@ public class TestDefaultExpressionEngine
      * @param count the number of expected result nodes
      * @return the list with the results of the query
      */
-    private List<ConfigurationNode> checkKey(String key, String name, int count)
+    private List<QueryResult<ImmutableNode>> checkKey(String key, String name,
+            int count)
     {
-        List<ConfigurationNode> nodes = engine.query(root, key);
-        assertEquals("Wrong number of result nodes for key " + key, count,
-                nodes.size());
-        for (ConfigurationNode configurationNode : nodes) {
-            assertEquals("Wrong result node for key " + key, name,
-                    configurationNode.getName());
+        List<QueryResult<ImmutableNode>> nodes = query(key, count);
+        for (QueryResult<ImmutableNode> result : nodes)
+        {
+            if (result.isAttributeResult())
+            {
+                assertEquals("Wrong attribute name for key " + key, name,
+                        result.getAttributeName());
+            }
+            else
+            {
+                assertEquals("Wrong result node for key " + key, name, result
+                        .getNode().getNodeName());
+            }
         }
         return nodes;
     }
 
     /**
+     * Helper method for querying the test engine for a specific key.
+     *
+     * @param key the key
+     * @param expCount the expected number of result nodes
+     * @return the collection of retrieved nodes
+     */
+    private List<QueryResult<ImmutableNode>> query(String key, int expCount)
+    {
+        List<QueryResult<ImmutableNode>> nodes = engine.query(root, key, handler);
+        assertEquals("Wrong number of result nodes for key " + key, expCount,
+                nodes.size());
+        return nodes;
+    }
+
+    /**
+     * Helper method for fetching a specific node by its key.
+     *
+     * @param key the key
+     * @return the node with this key
+     */
+    private ImmutableNode fetchNode(String key)
+    {
+        QueryResult<ImmutableNode> result = query(key, 1).get(0);
+        assertFalse("An attribute result", result.isAttributeResult());
+        return result.getNode();
+    }
+
+    /**
      * Helper method for checking the value of a node specified by the given
      * key. This method evaluates the key and checks whether the resulting node
      * has the expected value.
@@ -545,9 +716,28 @@ public class TestDefaultExpressionEngine
      */
     private void checkKeyValue(String key, String name, String value)
     {
-        List<ConfigurationNode> nodes = checkKey(key, name, 1);
+        List<QueryResult<ImmutableNode>> results = checkKey(key, name, 1);
+        QueryResult<ImmutableNode> result = results.get(0);
+        assertFalse("No node result", result.isAttributeResult());
         assertEquals("Wrong value for key " + key, value,
-                nodes.get(0).getValue());
+                result.getNode().getValue());
+    }
+
+    /**
+     * Helper method for checking whether an attribute key is correctly
+     * evaluated.
+     *
+     * @param key the attribute key
+     * @param attr the attribute name
+     * @param expValue the expected attribute value
+     */
+    private void checkAttributeValue(String key, String attr, Object expValue)
+    {
+        List<QueryResult<ImmutableNode>> results = checkKey(key, attr, 1);
+        QueryResult<ImmutableNode> result = results.get(0);
+        assertTrue("Not an attribute result", result.isAttributeResult());
+        assertEquals("Wrong attribute value for key " + key, expValue,
+                result.getAttributeValue(handler));
     }
 
     /**
@@ -556,7 +746,8 @@ public class TestDefaultExpressionEngine
      * @param data the add data object
      * @param expected the expected path nodes
      */
-    private void checkNodePath(NodeAddData data, String[] expected)
+    private void checkNodePath(NodeAddData<ImmutableNode> data,
+            String... expected)
     {
         assertEquals("Wrong number of path nodes", expected.length, data
                 .getPathNodes().size());
@@ -574,11 +765,22 @@ public class TestDefaultExpressionEngine
      * @param name the name of the field
      * @return the field node
      */
-    private static ConfigurationNode createFieldNode(String name)
+    private static ImmutableNode createFieldNode(String name)
+    {
+        ImmutableNode.Builder nodeFieldBuilder = new ImmutableNode.Builder(1);
+        nodeFieldBuilder.addChild(createNode("name", name));
+        return nodeFieldBuilder.name("field").create();
+    }
+
+    /**
+     * Convenience method for creating a simple node with a name and a value.
+     *
+     * @param name the node name
+     * @param value the node value
+     * @return the node instance
+     */
+    private static ImmutableNode createNode(String name, Object value)
     {
-        DefaultConfigurationNode nodeField = new DefaultConfigurationNode(
-                "field");
-        nodeField.addChild(new DefaultConfigurationNode("name", name));
-        return nodeField;
+        return new ImmutableNode.Builder().name(name).value(value).create();
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestImmutableNode.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestImmutableNode.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestImmutableNode.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestImmutableNode.java Sun Apr 20 19:32:08 2014
@@ -315,8 +315,21 @@ public class TestImmutableNode
      */
     private ImmutableNode createDefaultNode(Object value)
     {
+        return createDefaultNode(NAME, value);
+    }
+
+    /**
+     * Creates a default node instance with a variable name and value that can
+     * be used by tests for updating properties.
+     *
+     * @param name the name of the node
+     * @param value the value of the node
+     * @return the default node instance
+     */
+    private ImmutableNode createDefaultNode(String name, Object value)
+    {
         ImmutableNode.Builder builder = new ImmutableNode.Builder(1);
-        return builder.name(NAME).addChild(createChild())
+        return builder.name(name).addChild(createChild())
                 .addAttribute("testAttr", "anotherTest").value(value).create();
     }
 
@@ -362,6 +375,21 @@ public class TestImmutableNode
     }
 
     /**
+     * Tests whether the name of a node can be changed for a new instance.
+     */
+    @Test
+    public void testSetName()
+    {
+        ImmutableNode node = createDefaultNode("anotherName", VALUE);
+        ImmutableNode node2 = node.setName(NAME);
+        checkUpdatedNode(node, node2);
+        assertSame("Different children", node.getChildren(),
+                node2.getChildren());
+        assertSame("Different attributes", node.getAttributes(),
+                node2.getAttributes());
+    }
+
+    /**
      * Tests whether a child node can be added.
      */
     @Test
@@ -491,6 +519,70 @@ public class TestImmutableNode
     }
 
     /**
+     * Tests whether multiple attributes can be set.
+     */
+    @Test
+    public void testSetAttributes()
+    {
+        ImmutableNode node = createDefaultNode(VALUE);
+        Map<String, Object> attributes = new HashMap<String, Object>();
+        attributes.put("newAttribute1", "value1");
+        attributes.put("newAttribute2", "value2");
+        ImmutableNode node2 = node.setAttributes(attributes);
+        assertEquals("Wrong number of attributes", attributes.size()
+                + node.getAttributes().size(), node2.getAttributes().size());
+        checkAttributesContained(node2, attributes);
+        checkAttributesContained(node2, node.getAttributes());
+    }
+
+    /**
+     * Helper method for testing whether a node contains all the attributes in
+     * the specified map.
+     *
+     * @param node the node to be checked
+     * @param attributes the map with expected attributes
+     */
+    private static void checkAttributesContained(ImmutableNode node,
+            Map<String, Object> attributes)
+    {
+        for (Map.Entry<String, Object> e : attributes.entrySet())
+        {
+            assertEquals("Wrong attribute value", e.getValue(), node
+                    .getAttributes().get(e.getKey()));
+        }
+    }
+
+    /**
+     * Helper method for testing a setAttributes() operation which has no
+     * effect.
+     *
+     * @param attributes the map with attributes
+     */
+    private void checkSetAttributesNoOp(Map<String, Object> attributes)
+    {
+        ImmutableNode node = createDefaultNode(VALUE);
+        assertSame("Node was changed", node, node.setAttributes(attributes));
+    }
+
+    /**
+     * Tests setAttributes() if an empty map is passed in.
+     */
+    @Test
+    public void testSetAttributesEmpty()
+    {
+        checkSetAttributesNoOp(new HashMap<String, Object>());
+    }
+
+    /**
+     * Tests setAttributes() for null input.
+     */
+    @Test
+    public void testSetAttributesNull()
+    {
+        checkSetAttributesNoOp(null);
+    }
+
+    /**
      * Tests whether an existing attribute can be removed.
      */
     @Test
@@ -513,4 +605,35 @@ public class TestImmutableNode
         ImmutableNode node = createDefaultNode(VALUE);
         assertSame("Got different instance", node, node.removeAttribute(ATTR));
     }
+
+    /**
+     * Tests whether all children can be replaced at once.
+     */
+    @Test
+    public void testReplaceChildren()
+    {
+        final int childCount = 8;
+        Collection<ImmutableNode> newChildren =
+                new ArrayList<ImmutableNode>(childCount);
+        for (int i = 0; i < childCount; i++)
+        {
+            newChildren.add(createChild());
+        }
+        ImmutableNode node = createDefaultNode(VALUE);
+        ImmutableNode node2 = node.replaceChildren(newChildren);
+        checkUpdatedNode(node, node2);
+        checkChildNodes(node2, newChildren);
+    }
+
+    /**
+     * Tests whether a node's children can be replaced by a null collection.
+     */
+    @Test
+    public void testReplaceChildrenNullCollection()
+    {
+        ImmutableNode node = createDefaultNode(VALUE);
+        ImmutableNode node2 = node.replaceChildren(null);
+        checkUpdatedNode(node, node2);
+        checkChildNodes(node2);
+    }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestMergeCombiner.java Sun Apr 20 19:32:08 2014
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNul
 
 import java.util.List;
 
+import org.apache.commons.configuration.BaseHierarchicalConfiguration;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
@@ -51,7 +52,7 @@ public class TestMergeCombiner extends A
     @Test
     public void testSimpleValues() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong number of bgcolors", 0, config
                 .getMaxIndex("gui.bgcolor"));
         assertEquals("Wrong bgcolor", "green", config.getString("gui.bgcolor"));
@@ -67,7 +68,7 @@ public class TestMergeCombiner extends A
     @Test
     public void testAttributes() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong value of min attribute", 1, config
                 .getInt("gui.level[@min]"));
         assertEquals("Wrong value of default attribute", 2, config
@@ -84,7 +85,7 @@ public class TestMergeCombiner extends A
     @Test
     public void testOverrideValues() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong user", "Admin", config
                 .getString("base.services.security.login.user"));
         assertEquals("Wrong user type", "default", config
@@ -101,7 +102,7 @@ public class TestMergeCombiner extends A
     @Test
     public void testListFromFirstStructure() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong number of services", 0, config
                 .getMaxIndex("net.service.url"));
         assertEquals("Wrong service", "http://service1.org", config
@@ -117,7 +118,7 @@ public class TestMergeCombiner extends A
     @Test
     public void testListFromSecondStructure() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong number of servers", 3, config
                 .getMaxIndex("net.server.url"));
         assertEquals("Wrong server", "http://testsvr.com", config
@@ -138,7 +139,7 @@ public class TestMergeCombiner extends A
     public void testMerge() throws ConfigurationException
     {
         //combiner.setDebugStream(System.out);
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         config.setExpressionEngine(new XPathExpressionEngine());
         assertEquals("Wrong number of Channels", 3, config.getMaxIndex("Channels/Channel"));
         assertEquals("Bad Channel 1 Name", "My Channel",
@@ -164,21 +165,25 @@ public class TestMergeCombiner extends A
      * @param config the config
      * @return the node for the table element
      */
-    private ConfigurationNode checkTable(HierarchicalConfiguration config)
+    private ImmutableNode checkTable(
+            HierarchicalConfiguration<ImmutableNode> config)
     {
-        assertEquals("Wrong number of tables", 1, config
-                .getMaxIndex("database.tables.table"));
-        HierarchicalConfiguration c = config
-                .configurationAt("database.tables.table(0)");
+        assertEquals("Wrong number of tables", 1,
+                config.getMaxIndex("database.tables.table"));
+        HierarchicalConfiguration<ImmutableNode> c =
+                config.configurationAt("database.tables.table(0)");
         assertEquals("Wrong table name", "documents", c.getString("name"));
-        assertEquals("Wrong number of fields", 2, c
-                .getMaxIndex("fields.field.name"));
-        assertEquals("Wrong field", "docname", c
-                .getString("fields.field(1).name"));
-
-        List<ConfigurationNode> nds = config.getExpressionEngine().query(config.getRootNode(),
-                "database.tables.table");
+        assertEquals("Wrong number of fields", 2,
+                c.getMaxIndex("fields.field.name"));
+        assertEquals("Wrong field", "docname",
+                c.getString("fields.field(1).name"));
+
+        List<QueryResult<ImmutableNode>> nds =
+                config.getExpressionEngine().query(config.getRootNode(),
+                        "database.tables.table",
+                        config.getNodeModel().getNodeHandler());
         assertFalse("No node found", nds.isEmpty());
-        return nds.get(0);
-    }
-}
\ No newline at end of file
+        assertFalse("Not a node result", nds.get(0).isAttributeResult());
+        return nds.get(0).getNode();
+   }
+}

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestNodeAddData.java Sun Apr 20 19:32:08 2014
@@ -17,91 +17,91 @@
 package org.apache.commons.configuration.tree;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
-import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 /**
  * Test class for NodeAddData.
  *
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
  * @version $Id$
  */
 public class TestNodeAddData
 {
-    /** Constant for the default parent node used for testing. */
-    private static final ConfigurationNode TEST_PARENT = new DefaultConfigurationNode(
-            "parent");
-
     /** Constant for the name of the new node. */
     private static final String TEST_NODENAME = "testNewNode";
 
     /** Constant for the name of a path node. */
     private static final String PATH_NODE_NAME = "PATHNODE";
 
-    /** Constant for the number of path nodes to be added. */
-    private static final int PATH_NODE_COUNT = 10;
-
-    /** The object to be tested. */
-    NodeAddData addData;
+    /** A default parent node. */
+    private static ImmutableNode parentNode;
 
-    @Before
-    public void setUp() throws Exception
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception
     {
-        addData = new NodeAddData(TEST_PARENT, TEST_NODENAME);
+        parentNode = new ImmutableNode.Builder().name("testParent").create();
     }
 
     /**
-     * Tests the default values of an uninitialized instance.
+     * Tests whether the constructor can handle a null collection of path nodes.
      */
     @Test
-    public void testUninitialized()
+    public void testPathNodesNull()
     {
-        addData = new NodeAddData();
-        assertNull("A parent is set", addData.getParent());
-        assertNull("Node has a name", addData.getNewNodeName());
-        assertFalse("Attribute flag is set", addData.isAttribute());
-        assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
+        NodeAddData<ImmutableNode> data =
+                new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+                        false, null);
+        assertTrue("Got path nodes", data.getPathNodes().isEmpty());
     }
 
     /**
-     * Tests the constructor that initializes the most important fields.
+     * Tests whether the collection with path nodes cannot be modified if no
+     * data is available.
      */
-    @Test
-    public void testInitialized()
+    @Test(expected = UnsupportedOperationException.class)
+    public void testPathNodesNullModify()
     {
-        assertSame("Wrong parent", TEST_PARENT, addData.getParent());
-        assertEquals("Wrong node name", TEST_NODENAME, addData.getNewNodeName());
-        assertFalse("Attribute flag is set", addData.isAttribute());
-        assertTrue("Path nodes are not empty", addData.getPathNodes().isEmpty());
+        NodeAddData<ImmutableNode> data =
+                new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+                        false, null);
+        data.getPathNodes().add("test");
     }
 
     /**
-     * Tests adding path nodes.
+     * Tests whether a defensive copy of the collection with path nodes is
+     * created.
      */
     @Test
-    public void testAddPathNode()
+    public void testInitPathNodesDefensiveCopy()
     {
-        for (int i = 0; i < PATH_NODE_COUNT; i++)
-        {
-            addData.addPathNode(PATH_NODE_NAME + i);
-        }
-
-        List<String> nodes = addData.getPathNodes();
-        assertEquals("Incorrect number of path nodes", PATH_NODE_COUNT, nodes
+        List<String> pathNodes = new ArrayList<String>();
+        pathNodes.add(PATH_NODE_NAME);
+        NodeAddData<ImmutableNode> data =
+                new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+                        false, pathNodes);
+        pathNodes.add("anotherNode");
+        assertEquals("Wrong number of path nodes", 1, data.getPathNodes()
                 .size());
-        for (int i = 0; i < PATH_NODE_COUNT; i++)
-        {
-            assertEquals("Wrong path node at position" + i, PATH_NODE_NAME + i,
-                    nodes.get(i));
-        }
+        assertEquals("Wrong path node", PATH_NODE_NAME, data.getPathNodes()
+                .get(0));
+    }
+
+    /**
+     * Tests that the collection with path nodes cannot be modified if data is
+     * available.
+     */
+    @Test(expected = UnsupportedOperationException.class)
+    public void testPathNodesDefinedModify()
+    {
+        NodeAddData<ImmutableNode> data =
+                new NodeAddData<ImmutableNode>(parentNode, TEST_NODENAME,
+                        false, Collections.singleton(PATH_NODE_NAME));
+        data.getPathNodes().add("anotherNode");
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestOverrideCombiner.java Sun Apr 20 19:32:08 2014
@@ -18,10 +18,10 @@ package org.apache.commons.configuration
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
+import org.apache.commons.configuration.BaseHierarchicalConfiguration;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.junit.Test;
@@ -50,7 +50,7 @@ public class TestOverrideCombiner extend
     @Test
     public void testSimpleValues() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong number of bgcolors", 0, config
                 .getMaxIndex("gui.bgcolor"));
         assertEquals("Wrong bgcolor", "green", config.getString("gui.bgcolor"));
@@ -66,7 +66,7 @@ public class TestOverrideCombiner extend
     @Test
     public void testAttributes() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong value of min attribute", 1, config
                 .getInt("gui.level[@min]"));
         assertEquals("Wrong value of default attribute", 2, config
@@ -83,7 +83,7 @@ public class TestOverrideCombiner extend
     @Test
     public void testOverrideValues() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong user", "Admin", config
                 .getString("base.services.security.login.user"));
         assertEquals("Wrong user type", "default", config
@@ -101,7 +101,7 @@ public class TestOverrideCombiner extend
     @Test
     public void testListFromFirstStructure() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong number of services", 0, config
                 .getMaxIndex("net.service.url"));
         assertEquals("Wrong service", "http://service1.org", config
@@ -117,7 +117,7 @@ public class TestOverrideCombiner extend
     @Test
     public void testListFromSecondStructure() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong number of servers", 3, config
                 .getMaxIndex("net.server.url"));
         assertEquals("Wrong server", "http://testsvr.com", config
@@ -128,18 +128,16 @@ public class TestOverrideCombiner extend
      * Tests the combination of the table structure. Because the table node is
      * not declared as a list node the structures will be combined. But this
      * won't make any difference because the values in the first table override
-     * the values in the second table. Only the node for the table element will
-     * be a ViewNode.
+     * the values in the second table.
      */
     @Test
     public void testCombinedTableNoList() throws ConfigurationException
     {
-        ConfigurationNode tabNode = checkTable(createCombinedConfiguration());
-        assertTrue("Node is not a view node", tabNode instanceof ViewNode);
+        checkTable(createCombinedConfiguration());
     }
 
     /**
-     * Tests the combination of the table structure when the table node is
+     * Tests the combination of the table structure if the table node is
      * declared as a list node. In this case the first table structure
      * completely overrides the second and will be directly added to the
      * resulting structure.
@@ -148,8 +146,7 @@ public class TestOverrideCombiner extend
     public void testCombinedTableList() throws ConfigurationException
     {
         combiner.addListNode("table");
-        ConfigurationNode tabNode = checkTable(createCombinedConfiguration());
-        assertFalse("Node is a view node", tabNode instanceof ViewNode);
+        checkTable(createCombinedConfiguration());
     }
 
     /**
@@ -158,11 +155,11 @@ public class TestOverrideCombiner extend
      * @param config the config
      * @return the node for the table element
      */
-    private ConfigurationNode checkTable(HierarchicalConfiguration config)
+    private ImmutableNode checkTable(BaseHierarchicalConfiguration config)
     {
         assertEquals("Wrong number of tables", 0, config
                 .getMaxIndex("database.tables.table"));
-        HierarchicalConfiguration c = config
+        HierarchicalConfiguration<ImmutableNode> c = config
                 .configurationAt("database.tables.table");
         assertEquals("Wrong table name", "documents", c.getString("name"));
         assertEquals("Wrong number of fields", 2, c
@@ -170,9 +167,12 @@ public class TestOverrideCombiner extend
         assertEquals("Wrong field", "docname", c
                 .getString("fields.field(1).name"));
 
-        List<ConfigurationNode> nds = config.getExpressionEngine().query(config.getRootNode(),
-                "database.tables.table");
+        List<QueryResult<ImmutableNode>> nds =
+                config.getExpressionEngine().query(config.getRootNode(),
+                        "database.tables.table",
+                        config.getNodeModel().getNodeHandler());
         assertFalse("No node found", nds.isEmpty());
-        return nds.get(0);
+        assertFalse("An attribute result", nds.get(0).isAttributeResult());
+        return nds.get(0).getNode();
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestUnionCombiner.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestUnionCombiner.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestUnionCombiner.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/TestUnionCombiner.java Sun Apr 20 19:32:08 2014
@@ -19,7 +19,7 @@ package org.apache.commons.configuration
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
-import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.configuration.BaseHierarchicalConfiguration;
 import org.apache.commons.configuration.ex.ConfigurationException;
 import org.junit.Test;
 
@@ -47,7 +47,7 @@ public class TestUnionCombiner extends A
     @Test
     public void testSimpleValues() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Too few bgcolors", 1, config.getMaxIndex("gui.bgcolor"));
         assertEquals("Wrong first color", "green", config
                 .getString("gui.bgcolor(0)"));
@@ -65,7 +65,7 @@ public class TestUnionCombiner extends A
     @Test
     public void testSimpleValuesWithAttributes() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Too few level elements", 1, config
                 .getMaxIndex("gui.level"));
         assertEquals("Wrong value of first element", 1, config
@@ -86,13 +86,11 @@ public class TestUnionCombiner extends A
     @Test
     public void testAttributes() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
-        assertEquals("Too few attributes", 1, config
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
+        assertEquals("Wrong number of attributes", 0, config
                 .getMaxIndex("database.tables.table(0)[@id]"));
-        assertEquals("Wrong value of first attribute", 1, config
+        assertEquals("Wrong value of attribute", 1, config
                 .getInt("database.tables.table(0)[@id](0)"));
-        assertEquals("Wrong value of second attribute", 2, config
-                .getInt("database.tables.table(0)[@id](1)"));
     }
 
     /**
@@ -101,7 +99,7 @@ public class TestUnionCombiner extends A
     @Test
     public void testLists() throws ConfigurationException
     {
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Too few list elements", 2, config
                 .getMaxIndex("net.service.url"));
         assertEquals("Wrong first service", "http://service1.org", config
@@ -123,7 +121,7 @@ public class TestUnionCombiner extends A
     public void testTableList() throws ConfigurationException
     {
         combiner.addListNode("table");
-        HierarchicalConfiguration config = createCombinedConfiguration();
+        BaseHierarchicalConfiguration config = createCombinedConfiguration();
         assertEquals("Wrong name of first table", "documents", config
                 .getString("database.tables.table(0).name"));
         assertEquals("Wrong id of first table", 1, config

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/AbstractXPathTest.java Sun Apr 20 19:32:08 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
@@ -40,6 +39,9 @@ public abstract class AbstractXPathTest
     /** Constant for the name of the counter attribute. */
     protected static final String ATTR_NAME = "counter";
 
+    /** Constant for a name of an attribute of the root node. */
+    protected static final String ATTR_ROOT = "rootAttr";
+
     /** Constant for the name of the first child. */
     protected static final String CHILD_NAME1 = "subNode";
 
@@ -53,12 +55,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).getNodeHandler();
     }
 
     /**
@@ -75,16 +81,18 @@ public abstract class AbstractXPathTest
      * child nodes having the names {@code CHILD_NAME1} or
      * {@code CHILD_NAME2}. Their values are named like their parent
      * node with an additional index. Each node has an attribute with a counter
-     * value.
+     * value. The root node has a special attribute named {@value #ATTR_ROOT}
+     * with the value {@code true}.
      *
      * @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);
+        resultBuilder.addAttribute(ATTR_ROOT, String.valueOf(true));
+        return resultBuilder.create();
     }
 
     /**
@@ -111,19 +119,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 +138,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());
             }
         }
     }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationIteratorAttributes.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationIteratorAttributes.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationIteratorAttributes.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationIteratorAttributes.java Sun Apr 20 19:32:08 2014
@@ -17,23 +17,22 @@
 package org.apache.commons.configuration.tree.xpath;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Set;
 
-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.jxpath.ri.QName;
 import org.apache.commons.jxpath.ri.model.NodePointer;
 import org.junit.Before;
 import org.junit.Test;
 
 /**
- * Test class for ConfigurationIteratorAttributes.
+ * Test class for {@code ConfigurationNodeIteratorAttributes}.
  *
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
  * @version $Id$
  */
 public class TestConfigurationIteratorAttributes extends AbstractXPathTest
@@ -42,7 +41,7 @@ public class TestConfigurationIteratorAt
     private static final String TEST_ATTR = "test";
 
     /** Stores the node pointer of the test node.*/
-    NodePointer pointer;
+    private ConfigurationNodePointer<ImmutableNode> pointer;
 
     @Override
     @Before
@@ -51,9 +50,11 @@ public class TestConfigurationIteratorAt
         super.setUp();
 
         // Adds further attributes to the test node
-        ConfigurationNode testNode = root.getChild(1);
-        testNode.addAttribute(new DefaultConfigurationNode(TEST_ATTR, "yes"));
-        pointer = new ConfigurationNodePointer(testNode, Locale.getDefault());
+        ImmutableNode orgNode = root.getChildren().get(1);
+        ImmutableNode testNode = orgNode.setAttribute(TEST_ATTR, "yes");
+        pointer =
+                new ConfigurationNodePointer<ImmutableNode>(testNode,
+                        Locale.getDefault(), handler);
     }
 
     /**
@@ -62,11 +63,18 @@ public class TestConfigurationIteratorAt
     @Test
     public void testIterateAllAttributes()
     {
-        ConfigurationNodeIteratorAttribute it = new ConfigurationNodeIteratorAttribute(pointer, new QName(null, "*"));
+        ConfigurationNodeIteratorAttribute<ImmutableNode> it =
+                new ConfigurationNodeIteratorAttribute<ImmutableNode>(pointer,
+                        new QName(null, "*"));
         assertEquals("Wrong number of attributes", 2, iteratorSize(it));
-        List<ConfigurationNode> attrs = iterationElements(it);
-        assertEquals("Wrong first attribute", ATTR_NAME, attrs.get(0).getName());
-        assertEquals("Wrong first attribute", TEST_ATTR, attrs.get(1).getName());
+        List<NodePointer> attrs = iterationElements(it);
+        Set<String> attrNames = new HashSet<String>();
+        for (NodePointer np : attrs)
+        {
+            attrNames.add(np.getName().getName());
+        }
+        assertTrue("First attribute not found", attrNames.contains(ATTR_NAME));
+        assertTrue("Second attribute not found", attrNames.contains(TEST_ATTR));
     }
 
     /**
@@ -75,9 +83,12 @@ public class TestConfigurationIteratorAt
     @Test
     public void testIterateSpecificAttribute()
     {
-        ConfigurationNodeIteratorAttribute it = new ConfigurationNodeIteratorAttribute(pointer, new QName(null, TEST_ATTR));
+        ConfigurationNodeIteratorAttribute<ImmutableNode> it =
+                new ConfigurationNodeIteratorAttribute<ImmutableNode>(pointer,
+                        new QName(null, TEST_ATTR));
         assertEquals("Wrong number of attributes", 1, iteratorSize(it));
-        assertEquals("Wrong attribute", TEST_ATTR, iterationElements(it).get(0).getName());
+        assertEquals("Wrong attribute", TEST_ATTR, iterationElements(it).get(0)
+                .getName().getName());
     }
 
     /**
@@ -86,18 +97,22 @@ public class TestConfigurationIteratorAt
     @Test
     public void testIterateUnknownAttribute()
     {
-        ConfigurationNodeIteratorAttribute it = new ConfigurationNodeIteratorAttribute(pointer, new QName(null, "unknown"));
+        ConfigurationNodeIteratorAttribute<ImmutableNode> it =
+                new ConfigurationNodeIteratorAttribute<ImmutableNode>(pointer,
+                        new QName(null, "unknown"));
         assertEquals("Found attributes", 0, iteratorSize(it));
     }
 
     /**
-     * Tests iteration when a namespace is specified. This is not supported, so
+     * Tests iteration if a namespace is specified. This is not supported, so
      * the iteration should be empty.
      */
     @Test
     public void testIterateNamespace()
     {
-        ConfigurationNodeIteratorAttribute it = new ConfigurationNodeIteratorAttribute(pointer, new QName("test", "*"));
+        ConfigurationNodeIteratorAttribute<ImmutableNode> it =
+                new ConfigurationNodeIteratorAttribute<ImmutableNode>(pointer,
+                        new QName("test", "*"));
         assertEquals("Found attributes", 0, iteratorSize(it));
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationNodeIteratorChildren.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationNodeIteratorChildren.java?rev=1588831&r1=1588830&r2=1588831&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationNodeIteratorChildren.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/tree/xpath/TestConfigurationNodeIteratorChildren.java Sun Apr 20 19:32:08 2014
@@ -20,12 +20,10 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
-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.jxpath.ri.Compiler;
 import org.apache.commons.jxpath.ri.QName;
 import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
@@ -40,22 +38,21 @@ import org.junit.Test;
 /**
  * Test class for ConfigurationNodeIteratorChildren.
  *
- * @author <a
- * href="http://commons.apache.org/configuration/team-list.html">Commons
- * Configuration team</a>
  * @version $Id$
  */
 public class TestConfigurationNodeIteratorChildren extends AbstractXPathTest
 {
     /** Stores the node pointer to the root node. */
-    NodePointer rootPointer;
+    private ConfigurationNodePointer<ImmutableNode> rootPointer;
 
     @Override
     @Before
     public void setUp() throws Exception
     {
         super.setUp();
-        rootPointer = new ConfigurationNodePointer(root, Locale.getDefault());
+        rootPointer =
+                new ConfigurationNodePointer<ImmutableNode>(root,
+                        Locale.getDefault(), handler);
     }
 
     /**
@@ -64,11 +61,11 @@ public class TestConfigurationNodeIterat
     @Test
     public void testIterateAllChildren()
     {
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, null, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, null, false, null);
         assertEquals("Wrong number of elements", CHILD_COUNT, iteratorSize(it));
-        checkValues(it, new int[]
-        { 1, 2, 3, 4, 5 });
+        checkValues(it, 1, 2, 3, 4, 5);
     }
 
     /**
@@ -77,11 +74,11 @@ public class TestConfigurationNodeIterat
     @Test
     public void testIterateReverse()
     {
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, null, true, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, null, true, null);
         assertEquals("Wrong number of elements", CHILD_COUNT, iteratorSize(it));
-        checkValues(it, new int[]
-        { 5, 4, 3, 2, 1 });
+        checkValues(it, 5, 4, 3, 2, 1);
     }
 
     /**
@@ -91,8 +88,9 @@ public class TestConfigurationNodeIterat
     public void testIterateWithWildcardTest()
     {
         NodeNameTest test = new NodeNameTest(new QName(null, "*"));
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, test, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, test, false, null);
         assertEquals("Wrong number of elements", CHILD_COUNT, iteratorSize(it));
     }
 
@@ -104,8 +102,9 @@ public class TestConfigurationNodeIterat
     public void testIterateWithPrefixTest()
     {
         NodeNameTest test = new NodeNameTest(new QName("prefix", "*"));
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, test, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, test, false, null);
         assertNull("Undefined node pointer not returned", it.getNodePointer());
         assertEquals("Prefix was not evaluated", 0, iteratorSize(it));
     }
@@ -117,12 +116,13 @@ public class TestConfigurationNodeIterat
     public void testIterateWithNameTest()
     {
         NodeNameTest test = new NodeNameTest(new QName(null, CHILD_NAME2));
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, test, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, test, false, null);
         assertTrue("No children found", iteratorSize(it) > 0);
-        for (ConfigurationNode nd : iterationElements(it))
+        for (NodePointer nd : iterationElements(it))
         {
-            assertEquals("Wrong child element", CHILD_NAME2, nd.getName());
+            assertEquals("Wrong child element", CHILD_NAME2, nd.getName().getName());
         }
     }
 
@@ -134,8 +134,9 @@ public class TestConfigurationNodeIterat
     public void testIterateWithUnknownTest()
     {
         NodeTest test = new ProcessingInstructionTest("test");
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, test, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, test, false, null);
         assertEquals("Unknown test was not evaluated", 0, iteratorSize(it));
     }
 
@@ -146,8 +147,9 @@ public class TestConfigurationNodeIterat
     public void testIterateWithNodeType()
     {
         NodeTypeTest test = new NodeTypeTest(Compiler.NODE_TYPE_NODE);
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, test, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, test, false, null);
         assertEquals("Node type not evaluated", CHILD_COUNT, iteratorSize(it));
     }
 
@@ -159,8 +161,9 @@ public class TestConfigurationNodeIterat
     public void testIterateWithUnknownType()
     {
         NodeTypeTest test = new NodeTypeTest(Compiler.NODE_TYPE_COMMENT);
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, test, false, null);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, test, false, null);
         assertEquals("Unknown node type not evaluated", 0, iteratorSize(it));
     }
 
@@ -170,19 +173,22 @@ public class TestConfigurationNodeIterat
     @Test
     public void testIterateStartsWith()
     {
-        NodePointer childPointer = new ConfigurationNodePointer(rootPointer,
-                root.getChild(2));
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, null, false, childPointer);
+        ConfigurationNodePointer<ImmutableNode> childPointer =
+                new ConfigurationNodePointer<ImmutableNode>(rootPointer, root
+                        .getChildren().get(2), handler);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, null, false, childPointer);
         assertEquals("Wrong start position", 0, it.getPosition());
-        List<ConfigurationNode> nodes = iterationElements(it);
+        List<NodePointer> nodes = iterationElements(it);
         assertEquals("Wrong size of iteration", CHILD_COUNT - 3, nodes.size());
         int index = 4;
-        for (Iterator<ConfigurationNode> it2 = nodes.iterator(); it2.hasNext(); index++)
+        for (NodePointer np : nodes)
         {
-            ConfigurationNode node = it2.next();
-            assertEquals("Wrong node value", String.valueOf(index), node
-                    .getValue());
+            ImmutableNode node = (ImmutableNode) np.getImmediateNode();
+            assertEquals("Wrong node value", String.valueOf(index),
+                    node.getValue());
+            index++;
         }
     }
 
@@ -192,17 +198,18 @@ public class TestConfigurationNodeIterat
     @Test
     public void testIterateStartsWithReverse()
     {
-        NodePointer childPointer = new ConfigurationNodePointer(rootPointer,
-                root.getChild(3));
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, null, true, childPointer);
+        ConfigurationNodePointer<ImmutableNode> childPointer =
+                new ConfigurationNodePointer<ImmutableNode>(rootPointer, root
+                        .getChildren().get(3), handler);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, null, true, childPointer);
         int value = 3;
         for (int index = 1; it.setPosition(index); index++, value--)
         {
-            ConfigurationNode node = (ConfigurationNode) it.getNodePointer()
-                    .getNode();
-            assertEquals("Incorrect value at index " + index, String
-                    .valueOf(value), node.getValue());
+            ImmutableNode node = (ImmutableNode) it.getNodePointer().getNode();
+            assertEquals("Incorrect value at index " + index,
+                    String.valueOf(value), node.getValue());
         }
         assertEquals("Iteration ended not at end node", 0, value);
     }
@@ -214,14 +221,16 @@ public class TestConfigurationNodeIterat
     @Test
     public void testIterateStartsWithInvalid()
     {
-        NodePointer childPointer = new ConfigurationNodePointer(rootPointer,
-                new DefaultConfigurationNode("newNode"));
-        ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
-                rootPointer, null, false, childPointer);
+        ConfigurationNodePointer<ImmutableNode> childPointer =
+                new ConfigurationNodePointer<ImmutableNode>(rootPointer,
+                        new ImmutableNode.Builder().name("newNode").create(),
+                        handler);
+        ConfigurationNodeIteratorChildren<ImmutableNode> it =
+                new ConfigurationNodeIteratorChildren<ImmutableNode>(
+                        rootPointer, null, false, childPointer);
         assertEquals("Wrong size of iteration", CHILD_COUNT, iteratorSize(it));
         it.setPosition(1);
-        ConfigurationNode node = (ConfigurationNode) it.getNodePointer()
-                .getNode();
+        ImmutableNode node = (ImmutableNode) it.getNodePointer().getNode();
         assertEquals("Wrong start node", "1", node.getValue());
     }
 
@@ -234,12 +243,12 @@ public class TestConfigurationNodeIterat
      * @param iterator the iterator
      * @param expectedIndices an array with the expected indices
      */
-    private void checkValues(NodeIterator iterator, int[] expectedIndices)
+    private void checkValues(NodeIterator iterator, int... expectedIndices)
     {
-        List<ConfigurationNode> nodes = iterationElements(iterator);
+        List<NodePointer> nodes = iterationElements(iterator);
         for (int i = 0; i < expectedIndices.length; i++)
         {
-            ConfigurationNode child = nodes.get(i);
+            ImmutableNode child = (ImmutableNode) nodes.get(i).getImmediateNode();
             assertTrue("Wrong index value for child " + i, child.getValue()
                     .toString().endsWith(String.valueOf(expectedIndices[i])));
         }



Mime
View raw message