commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1573222 - in /commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration: TestAbstractHierarchicalConfiguration.java tree/NodeStructureHelper.java
Date Sat, 01 Mar 2014 20:18:37 GMT
Author: oheger
Date: Sat Mar  1 20:18:36 2014
New Revision: 1573222

URL: http://svn.apache.org/r1573222
Log:
Reworked tests for addNodes().

The tests now create ImmutableNode objects to be added to the configuration.
A test that does not make sense any longer was removed. All tests for
addNodes() are now successful.

Modified:
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestAbstractHierarchicalConfiguration.java
    commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/NodeStructureHelper.java

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestAbstractHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestAbstractHierarchicalConfiguration.java?rev=1573222&r1=1573221&r2=1573222&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestAbstractHierarchicalConfiguration.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/TestAbstractHierarchicalConfiguration.java
Sat Mar  1 20:18:36 2014
@@ -45,7 +45,6 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.tree.NodeModel;
 import org.apache.commons.configuration.tree.NodeStructureHelper;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -554,37 +553,38 @@ public class TestAbstractHierarchicalCon
                 clone.getString(keyAnswer));
     }
 
-    @Test @Ignore
+    @Test
     public void testAddNodes()
     {
-        //TODO rework
-//        Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
-//        nodes.add(createFieldNode("birthDate"));
-//        nodes.add(createFieldNode("lastLogin"));
-//        nodes.add(createFieldNode("language"));
-//        config.addNodes("tables.table(0).fields", nodes);
-//        assertEquals(7, config.getMaxIndex("tables.table(0).fields.field"));
-//        assertEquals("birthDate", config.getString("tables.table(0).fields.field(5).name"));
-//        assertEquals("lastLogin", config.getString("tables.table(0).fields.field(6).name"));
-//        assertEquals("language", config.getString("tables.table(0).fields.field(7).name"));
+        Collection<ImmutableNode> nodes = new ArrayList<ImmutableNode>();
+        nodes.add(NodeStructureHelper.createFieldNode("birthDate"));
+        nodes.add(NodeStructureHelper.createFieldNode("lastLogin"));
+        nodes.add(NodeStructureHelper.createFieldNode("language"));
+        config.addNodes("tables.table(0).fields", nodes);
+        assertEquals(7, config.getMaxIndex("tables.table(0).fields.field"));
+        assertEquals("birthDate", config.getString("tables.table(0).fields.field(5).name"));
+        assertEquals("lastLogin", config.getString("tables.table(0).fields.field(6).name"));
+        assertEquals("language", config.getString("tables.table(0).fields.field(7).name"));
     }
 
     /**
-     * Tests the addNodes() method when the provided key does not exist. In
-     * this case, a new node (or even a complete new branch) will be created.
+     * Tests the addNodes() method if the provided key does not exist. In
+     * this case, a new node (or even a completely new branch) is created.
      */
-    @Test @Ignore
+    @Test
     public void testAddNodesForNonExistingKey()
     {
-//        Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
-//        nodes.add(createNode("usr", "scott"));
-//        ConfigurationNode nd = createNode("pwd", "tiger");
-//        nd.setAttribute(true);
-//        nodes.add(nd);
-//        config.addNodes("database.connection.settings", nodes);
-//
-//        assertEquals("Usr node not found", "scott", config.getString("database.connection.settings.usr"));
-//        assertEquals("Pwd node not found", "tiger", config.getString("database.connection.settings[@pwd]"));
+        Collection<ImmutableNode> nodes = new ArrayList<ImmutableNode>();
+        ImmutableNode newNode =
+                new ImmutableNode.Builder().name("usr").value("scott")
+                        .addAttribute("pwd", "tiger").create();
+        nodes.add(newNode);
+        config.addNodes("database.connection.settings", nodes);
+
+        assertEquals("Usr node not found", "scott",
+                config.getString("database.connection.settings.usr"));
+        assertEquals("Pwd node not found", "tiger",
+                config.getString("database.connection.settings.usr[@pwd]"));
     }
 
     /**
@@ -602,41 +602,31 @@ public class TestAbstractHierarchicalCon
     /**
      * Tests copying nodes from one configuration to another one.
      */
-    @Test @Ignore
+    @Test
     public void testAddNodesCopy()
     {
-//        BaseHierarchicalConfiguration configDest = new BaseHierarchicalConfiguration();
-//        configDest.addProperty("test", "TEST");
-//        Collection<ConfigurationNode> nodes = config.getRootNode().getChildren();
-//        assertEquals("Wrong number of children", 1, nodes.size());
-//        configDest.addNodes("newNodes", nodes);
-//        for (int i = 0; i < tables.length; i++)
-//        {
-//            String keyTab = "newNodes.tables.table(" + i + ").";
-//            assertEquals("Table " + i + " not found", tables[i], configDest
-//                    .getString(keyTab + "name"));
-//            for (int j = 0; j < fields[i].length; j++)
-//            {
-//                assertEquals("Invalid field " + j + " in table " + i,
-//                        fields[i][j], configDest.getString(keyTab
-//                                + "fields.field(" + j + ").name"));
-//            }
-//        }
-    }
-
-    /**
-     * Tests adding an attribute node with the addNodes() method.
-     */
-    @Test @Ignore
-    public void testAddNodesAttributeNode()
-    {
-//        Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
-//        ConfigurationNode nd = createNode("length", "10");
-//        nd.setAttribute(true);
-//        nodes.add(nd);
-//        config.addNodes("tables.table(0).fields.field(1)", nodes);
-//        assertEquals("Attribute was not added", "10", config
-//                .getString("tables.table(0).fields.field(1)[@length]"));
+        AbstractHierarchicalConfigurationTestImpl configDest =
+                new AbstractHierarchicalConfigurationTestImpl(
+                        new InMemoryNodeModel());
+        configDest.addProperty("test", "TEST");
+        Collection<ImmutableNode> nodes = config.getRootNode().getChildren();
+        assertEquals("Wrong number of children", 1, nodes.size());
+        configDest.addNodes("newNodes", nodes);
+        for (int i = 0; i < NodeStructureHelper.tablesLength(); i++)
+        {
+            String keyTab = "newNodes.tables.table(" + i + ").";
+            assertEquals("Table " + i + " not found",
+                    NodeStructureHelper.table(i),
+                    configDest.getString(keyTab + "name"));
+            for (int j = 0; j < NodeStructureHelper.fieldsLength(i); j++)
+            {
+                assertEquals(
+                        "Invalid field " + j + " in table " + i,
+                        NodeStructureHelper.field(i, j),
+                        configDest.getString(keyTab + "fields.field(" + j
+                                + ").name"));
+            }
+        }
     }
 
     /**
@@ -665,7 +655,6 @@ public class TestAbstractHierarchicalCon
         config.addProperty("test.absolute.dir.dir1", "${base.dir}/path1");
         config.addProperty("test.absolute.dir.dir2", "${base.dir}/path2");
         config.addProperty("test.absolute.dir.dir3", "${base.dir}/path3");
-        //TODO check
         Configuration sub = config.subset("test.absolute.dir");
         for (int i = 1; i < 4; i++)
         {

Modified: commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/NodeStructureHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/NodeStructureHelper.java?rev=1573222&r1=1573221&r2=1573222&view=diff
==============================================================================
--- commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/NodeStructureHelper.java
(original)
+++ commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/NodeStructureHelper.java
Sat Mar  1 20:18:36 2014
@@ -315,6 +315,21 @@ public class NodeStructureHelper
     }
 
     /**
+     * Helper method for creating a field node with its children. Nodes of this
+     * type are used within the tables tree. They define a single column of a
+     * table.
+     *
+     * @param name the name of the field
+     * @return the field node
+     */
+    public static ImmutableNode createFieldNode(String name)
+    {
+        ImmutableNode.Builder fldBuilder = new ImmutableNode.Builder(1);
+        fldBuilder.addChild(createNode("name", name));
+        return fldBuilder.name("field").create();
+    }
+
+    /**
      * Creates a tree with a root node whose children are the test authors. Each
      * other has his works as child nodes. Each work has its personae as
      * children.
@@ -418,19 +433,6 @@ public class NodeStructureHelper
     }
 
     /**
-     * Helper method for creating a field node with its children.
-     *
-     * @param name the name of the field
-     * @return the field node
-     */
-    private static ImmutableNode createFieldNode(String name)
-    {
-        ImmutableNode.Builder fldBuilder = new ImmutableNode.Builder(1);
-        fldBuilder.addChild(createNode("name", name));
-        return fldBuilder.name("field").create();
-    }
-
-    /**
      * Helper method for evaluating a single component of a node key.
      *
      * @param parent the current parent node



Mime
View raw message