commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r225577 - /jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Date Wed, 27 Jul 2005 19:05:54 GMT
Author: oheger
Date: Wed Jul 27 12:05:46 2005
New Revision: 225577

URL: http://svn.apache.org/viewcvs?rev=225577&view=rev
Log:
New unit test case for HierarchicalConfiguration.addNodes() method

Modified:
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java?rev=225577&r1=225576&r2=225577&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestHierarchicalConfiguration.java
Wed Jul 27 12:05:46 2005
@@ -45,29 +45,18 @@
     protected void setUp() throws Exception
     {
         config = new HierarchicalConfiguration();
-        HierarchicalConfiguration.Node nodeTables =
-        new HierarchicalConfiguration.Node("tables");
+        HierarchicalConfiguration.Node nodeTables = createNode("tables", null);
         for(int i = 0; i < tables.length; i++)
         {
-            HierarchicalConfiguration.Node nodeTable = 
-            new HierarchicalConfiguration.Node("table");
+            HierarchicalConfiguration.Node nodeTable = createNode("table", null); 
             nodeTables.addChild(nodeTable);
-            HierarchicalConfiguration.Node nodeName =
-            new HierarchicalConfiguration.Node("name");
-            nodeName.setValue(tables[i]);
+            HierarchicalConfiguration.Node nodeName = createNode("name", tables[i]);
             nodeTable.addChild(nodeName);
-            HierarchicalConfiguration.Node nodeFields =
-            new HierarchicalConfiguration.Node("fields");
+            HierarchicalConfiguration.Node nodeFields = createNode("fields", null);
             nodeTable.addChild(nodeFields);
             for(int j = 0; j < fields[i].length; j++)
             {
-                HierarchicalConfiguration.Node nodeField =
-                new HierarchicalConfiguration.Node("field");
-                HierarchicalConfiguration.Node nodeFieldName =
-                new HierarchicalConfiguration.Node("name");
-                nodeFieldName.setValue(fields[i][j]);
-                nodeField.addChild(nodeFieldName);
-                nodeFields.addChild(nodeField);
+                nodeFields.addChild(createFieldNode(fields[i][j]));
             }  /* for */
         }  /* for */
         config.getRoot().addChild(nodeTables);
@@ -328,6 +317,19 @@
         }
     }
     
+    public void testAddNodes()
+    {
+        Collection nodes = new ArrayList();
+        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"));
+    }
+    
     /**
      * Helper method for testing the getKeys(String) method.
      * @param prefix the key to pass into getKeys()
@@ -356,5 +358,30 @@
         }
         
         assertTrue("Remaining keys " + values, values.isEmpty());
+    }
+    
+    /**
+     * Helper method for creating a field node with its children.
+     * @param name the name of the field
+     * @return the field node
+     */
+    private static HierarchicalConfiguration.Node createFieldNode(String name)
+    {
+        HierarchicalConfiguration.Node fld = createNode("field", null);
+        fld.addChild(createNode("name", name));
+        return fld;
+    }
+    
+    /**
+     * Helper method for creating a configuration node.
+     * @param name the node's name
+     * @param value the node's value
+     * @return the new node
+     */
+    private static HierarchicalConfiguration.Node createNode(String name, Object value)
+    {
+        HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
+        node.setValue(value);
+        return node;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message