You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/03/01 21:12:18 UTC
svn commit: r1573218 -
/commons/proper/configuration/branches/immutableNodes/src/test/java/org/apache/commons/configuration/tree/NodeStructureHelper.java
Author: oheger
Date: Sat Mar 1 20:12:18 2014
New Revision: 1573218
URL: http://svn.apache.org/r1573218
Log:
Added more test data to NodeStructureHelper.
The class now also maintains a tree structure with database tables and their
column names.
Modified:
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/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=1573218&r1=1573217&r2=1573218&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:12:18 2014
@@ -81,6 +81,22 @@ public class NodeStructureHelper
}
};
+ /** An array with table names used for the TABLES tree. */
+ private static final String[] TABLES = {
+ "users", "documents"
+ };
+
+ /**
+ * An array with the names of columns to be used for the TABLES tree.
+ */
+ private static final String[][] FIELDS = {
+ {
+ "uid", "uname", "firstName", "lastName", "email"
+ }, {
+ "docid", "name", "creationDate", "authorID", "version"
+ }
+ };
+
/** Constant for the author attribute. */
public static final String ATTR_AUTHOR = "author";
@@ -96,6 +112,9 @@ public class NodeStructureHelper
/** The root node of the personae tree. */
public static final ImmutableNode ROOT_PERSONAE_TREE = createPersonaeTree();
+ /** The root node of the TABLES tree. */
+ public static final ImmutableNode ROOT_TABLES_TREE = createTablesTree();
+
/**
* Returns the number of authors.
*
@@ -166,6 +185,50 @@ public class NodeStructureHelper
}
/**
+ * Returns the number of tables in the tables tree.
+ *
+ * @return the number of tables
+ */
+ public static int tablesLength()
+ {
+ return TABLES.length;
+ }
+
+ /**
+ * Returns the name of the test table with the given index.
+ *
+ * @param idx the index of the table
+ * @return the name of the test table with this index
+ */
+ public static String table(int idx)
+ {
+ return TABLES[idx];
+ }
+
+ /**
+ * Returns the number of fields in the test table with the given index.
+ *
+ * @param tabIdx the index of the table
+ * @return the number of fields in this table
+ */
+ public static int fieldsLength(int tabIdx)
+ {
+ return FIELDS[tabIdx].length;
+ }
+
+ /**
+ * Returns the name of the specified field in the tables tree.
+ *
+ * @param tabIdx the index of the table
+ * @param fldIdx the index of the field
+ * @return the name of this field
+ */
+ public static String field(int tabIdx, int fldIdx)
+ {
+ return FIELDS[tabIdx][fldIdx];
+ }
+
+ /**
* Appends a component to a node path. The component is added separated by a
* path separator.
*
@@ -240,6 +303,18 @@ public class NodeStructureHelper
}
/**
+ * Helper method for creating an immutable node with a name and a value.
+ *
+ * @param name the node's name
+ * @param value the node's value
+ * @return the new node
+ */
+ public static ImmutableNode createNode(String name, Object value)
+ {
+ return new ImmutableNode.Builder().name(name).value(value).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.
@@ -308,6 +383,54 @@ public class NodeStructureHelper
}
/**
+ * Creates a tree with database table data with the following structure:
+ *
+ * tables
+ * table
+ * name
+ * fields
+ * field
+ * name
+ * field
+ * name
+ */
+ private static ImmutableNode createTablesTree()
+ {
+ ImmutableNode.Builder bldTables =
+ new ImmutableNode.Builder(TABLES.length);
+ bldTables.name("tables");
+ for (int i = 0; i < TABLES.length; i++)
+ {
+ ImmutableNode.Builder bldTable = new ImmutableNode.Builder(2);
+ bldTable.addChild(createNode("name", TABLES[i]));
+ ImmutableNode.Builder bldFields =
+ new ImmutableNode.Builder(FIELDS[i].length);
+ bldFields.name("fields");
+
+ for (int j = 0; j < FIELDS[i].length; j++)
+ {
+ bldFields.addChild(createFieldNode(FIELDS[i][j]));
+ }
+ bldTable.addChild(bldFields.create());
+ bldTables.addChild(bldTable.name("table").create());
+ }
+ return bldTables.create();
+ }
+
+ /**
+ * 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