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 2008/03/08 21:43:34 UTC
svn commit: r635082 - in
/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2:
TestInMemoryConfiguration.java TestSubConfiguration.java
Author: oheger
Date: Sat Mar 8 12:43:33 2008
New Revision: 635082
URL: http://svn.apache.org/viewvc?rev=635082&view=rev
Log:
Test classes for hierarchical configurations based on node handlers
Added:
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java
- copied, changed from r632835, commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java
- copied, changed from r632835, commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java
Copied: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java (from r632835, commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java&r1=632835&r2=635082&rev=635082&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestHierarchicalConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestInMemoryConfiguration.java Sat Mar 8 12:43:33 2008
@@ -24,63 +24,71 @@
import java.util.List;
import java.util.Set;
-import org.apache.commons.configuration2.Configuration;
-import org.apache.commons.configuration2.ConfigurationKey;
+import junit.framework.TestCase;
+
import org.apache.commons.configuration2.event.ConfigurationEvent;
import org.apache.commons.configuration2.event.ConfigurationListener;
+import org.apache.commons.configuration2.expr.DefaultExpressionEngine;
+import org.apache.commons.configuration2.expr.ExpressionEngine;
+import org.apache.commons.configuration2.expr.NodeHandler;
+import org.apache.commons.configuration2.expr.NodeVisitorAdapter;
import org.apache.commons.configuration2.tree.ConfigurationNode;
-import org.apache.commons.configuration2.tree.ConfigurationNodeVisitorAdapter;
import org.apache.commons.configuration2.tree.DefaultConfigurationNode;
-import org.apache.commons.configuration2.tree.DefaultExpressionEngine;
-import org.apache.commons.configuration2.tree.ExpressionEngine;
-
-import junit.framework.TestCase;
/**
- * Test class for HierarchicalConfiguration.
+ * Test class for InMemoryConfiguration.
*
* @version $Id$
*/
-public class TestHierarchicalConfiguration extends TestCase
+public class TestInMemoryConfiguration extends TestCase
{
- private static String[] tables = { "users", "documents" };
+ /** An array with the names of the test TABLES.*/
+ private static final String[] TABLES = { "users", "documents" };
- private static String[][] fields =
+ /** An array with the names of the table FIELDS.*/
+ private static final String[][] FIELDS =
{
{ "uid", "uname", "firstName", "lastName", "email" },
{ "docid", "name", "creationDate", "authorID", "version" }
};
- private HierarchicalConfiguration config;
+ /** An array with flags whether the test TABLES are system TABLES.*/
+ private static final Boolean[] SYS_TABLES = { Boolean.TRUE, Boolean.FALSE };
+
+ /** The configuration to be tested.*/
+ private InMemoryConfiguration config;
+ /**
+ * Initializes the configuration with the following structure:
+ *
+ * tables
+ * table
+ * name
+ * fields
+ * field
+ * name
+ * field
+ * name
+ */
+ @Override
protected void setUp() throws Exception
{
- /**
- * Initialize the configuration with the following structure:
- *
- * tables
- * table
- * name
- * fields
- * field
- * name
- * field
- * name
- */
- config = new HierarchicalConfiguration();
+ config = new InMemoryConfiguration();
ConfigurationNode nodeTables = createNode("tables", null);
- for(int i = 0; i < tables.length; i++)
+ for(int i = 0; i < TABLES.length; i++)
{
ConfigurationNode nodeTable = createNode("table", null);
nodeTables.addChild(nodeTable);
- ConfigurationNode nodeName = createNode("name", tables[i]);
+ ConfigurationNode nodeName = createNode("name", TABLES[i]);
nodeTable.addChild(nodeName);
+ ConfigurationNode attrType = createNode("sysTab", SYS_TABLES[i]);
+ nodeTable.addAttribute(attrType);
ConfigurationNode nodeFields = createNode("fields", null);
nodeTable.addChild(nodeFields);
- for (int j = 0; j < fields[i].length; j++)
+ for (int j = 0; j < FIELDS[i].length; j++)
{
- nodeFields.addChild(createFieldNode(fields[i][j]));
+ nodeFields.addChild(createFieldNode(FIELDS[i][j]));
}
}
@@ -109,7 +117,7 @@
public void testIsEmpty()
{
assertFalse(config.isEmpty());
- HierarchicalConfiguration conf2 = new HierarchicalConfiguration();
+ InMemoryConfiguration conf2 = new InMemoryConfiguration();
assertTrue(conf2.isEmpty());
ConfigurationNode child1 = new DefaultConfigurationNode("child1");
ConfigurationNode child2 = new DefaultConfigurationNode("child2");
@@ -120,7 +128,7 @@
public void testGetProperty()
{
- assertNull(config.getProperty("tables.table.resultset"));
+ assertNull(config.getProperty("TABLES.table.resultset"));
assertNull(config.getProperty("tables.table.fields.field"));
Object prop = config.getProperty("tables.table(0).fields.field.name");
@@ -301,9 +309,10 @@
keys.add(it.next().toString());
}
- assertEquals(2, keys.size());
+ assertEquals("Wrong number of keys", 3, keys.size());
assertTrue(keys.contains("tables.table.name"));
assertTrue(keys.contains("tables.table.fields.field.name"));
+ assertTrue(keys.contains("tables.table[@sysTab]"));
// test the order of the keys returned
config.addProperty("order.key1", "value1");
@@ -329,9 +338,10 @@
config.addProperty("connections.connection(-1).param.url", "url2");
config.addProperty("connections.connection(1).param.user", "guest");
- checkKeys("tables.table(1)", new String[] { "name", "fields.field.name" });
+ checkKeys("tables.table(1)", new String[] { "name", "fields.field.name", "tables.table(1)[@sysTab]" });
checkKeys("tables.table(0)",
- new String[] { "name", "fields.field.name", "tables.table(0)[@type]", "size", "fields.field.type", "fields.field.size" });
+ new String[] { "name", "fields.field.name", "tables.table(0)[@type]",
+ "tables.table(0)[@sysTab]", "size", "fields.field.type", "fields.field.size" });
checkKeys("connections.connection(0).param",
new String[] {"url", "user", "pwd" });
checkKeys("connections.connection(1).param",
@@ -413,31 +423,32 @@
{
// test the subset on the first table
Configuration subset = config.subset("tables.table(0)");
- assertEquals(tables[0], subset.getProperty("name"));
+ assertEquals("Wrong table name", TABLES[0], subset.getProperty("name"));
+ assertEquals("Wrong attribute", SYS_TABLES[0].booleanValue(), subset.getBoolean("[@sysTab]"));
Object prop = subset.getProperty("fields.field.name");
assertNotNull(prop);
assertTrue(prop instanceof Collection);
assertEquals(5, ((Collection<?>) prop).size());
- for (int i = 0; i < fields[0].length; i++)
+ for (int i = 0; i < FIELDS[0].length; i++)
{
ConfigurationKey key = new ConfigurationKey();
key.append("fields").append("field").appendIndex(i);
key.append("name");
- assertEquals(fields[0][i], subset.getProperty(key.toString()));
+ assertEquals(FIELDS[0][i], subset.getProperty(key.toString()));
}
// test the subset on the second table
assertTrue("subset is not empty", config.subset("tables.table(2)").isEmpty());
- // test the subset on the fields
+ // test the subset on the FIELDS
subset = config.subset("tables.table.fields.field");
prop = subset.getProperty("name");
assertTrue("prop is not a collection", prop instanceof Collection);
assertEquals(10, ((Collection<?>) prop).size());
- assertEquals(fields[0][0], subset.getProperty("name(0)"));
+ assertEquals(FIELDS[0][0], subset.getProperty("name(0)"));
// test the subset on the field names
subset = config.subset("tables.table.fields.field.name");
@@ -450,11 +461,11 @@
*/
public void testSubsetNodeWithValue()
{
- config.setProperty("tables.table(0).fields", "My fields");
+ config.setProperty("tables.table(0).fields", "My FIELDS");
Configuration subset = config.subset("tables.table(0).fields");
- assertEquals("Wrong field name", fields[0][0], subset
+ assertEquals("Wrong field name", FIELDS[0][0], subset
.getString("field(0).name"));
- assertEquals("Wrong value of root", "My fields", subset.getString(""));
+ assertEquals("Wrong value of root", "My FIELDS", subset.getString(""));
}
/**
@@ -464,29 +475,39 @@
*/
public void testSubsetMultipleNodesWithValues()
{
- config.setProperty("tables.table(0).fields", "My fields");
+ config.setProperty("tables.table(0).fields", "My FIELDS");
Configuration subset = config.subset("tables.table.fields");
- assertEquals("Wrong value of root", "My fields", subset.getString(""));
- config.setProperty("tables.table(1).fields", "My other fields");
+ assertEquals("Wrong value of root", "My FIELDS", subset.getString(""));
+ config.setProperty("tables.table(1).fields", "My other FIELDS");
subset = config.subset("tables.table.fields");
assertNull("Root value is not null though there are multiple values",
subset.getString(""));
}
/**
+ * Tests creating a subset from an attribute property.
+ */
+ public void testSubsetWithAttribute()
+ {
+ Configuration subset = config.subset("tables.table(0)[@sysTab]");
+ assertEquals("Wrong attribute value", SYS_TABLES[0].booleanValue(),
+ subset.getBoolean(null));
+ }
+
+ /**
* Tests the configurationAt() method to obtain a configuration for a sub
* tree.
*/
public void testConfigurationAt()
{
- HierarchicalConfiguration subConfig = config
+ AbstractHierarchicalConfiguration<ConfigurationNode> subConfig = config
.configurationAt("tables.table(1)");
- assertEquals("Wrong table name", tables[1], subConfig.getString("name"));
+ assertEquals("Wrong table name", TABLES[1], subConfig.getString("name"));
List<?> lstFlds = subConfig.getList("fields.field.name");
- assertEquals("Wrong number of fields", fields[1].length, lstFlds.size());
- for (int i = 0; i < fields[1].length; i++)
+ assertEquals("Wrong number of fields", FIELDS[1].length, lstFlds.size());
+ for (int i = 0; i < FIELDS[1].length; i++)
{
- assertEquals("Wrong field at position " + i, fields[1][i], lstFlds
+ assertEquals("Wrong field at position " + i, FIELDS[1][i], lstFlds
.get(i));
}
@@ -536,13 +557,12 @@
*/
public void testConfigurationsAt()
{
- List<?> lstFlds = config.configurationsAt("tables.table(1).fields.field");
- assertEquals("Wrong size of fields", fields[1].length, lstFlds.size());
- for (int i = 0; i < fields[1].length; i++)
- {
- HierarchicalConfiguration sub = (HierarchicalConfiguration) lstFlds
- .get(i);
- assertEquals("Wrong field at position " + i, fields[1][i], sub
+ List<AbstractHierarchicalConfiguration<ConfigurationNode>> lstFlds = config.configurationsAt("tables.table(1).fields.field");
+ assertEquals("Wrong size of FIELDS", FIELDS[1].length, lstFlds.size());
+ for (int i = 0; i < FIELDS[1].length; i++)
+ {
+ AbstractHierarchicalConfiguration<ConfigurationNode> sub = lstFlds.get(i);
+ assertEquals("Wrong field at position " + i, FIELDS[1][i], sub
.getString("name"));
}
}
@@ -560,7 +580,7 @@
public void testClone()
{
Configuration copy = (Configuration) config.clone();
- assertTrue(copy instanceof HierarchicalConfiguration);
+ assertTrue(copy instanceof InMemoryConfiguration);
checkContent(copy);
}
@@ -577,8 +597,7 @@
// just a dummy
}
});
- HierarchicalConfiguration copy = (HierarchicalConfiguration) config
- .clone();
+ InMemoryConfiguration copy = (InMemoryConfiguration) config.clone();
assertTrue("Event listener registered at clone", copy
.getConfigurationListeners().isEmpty());
}
@@ -642,26 +661,35 @@
*/
public void testAddNodesCopy()
{
- HierarchicalConfiguration configDest = new HierarchicalConfiguration();
+ InMemoryConfiguration configDest = new InMemoryConfiguration();
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++)
+ for (int i = 0; i < TABLES.length; i++)
{
String keyTab = "newNodes.tables.table(" + i + ").";
- assertEquals("Table " + i + " not found", tables[i], configDest
+ assertEquals("Table " + i + " not found", TABLES[i], configDest
.getString(keyTab + "name"));
- for (int j = 0; j < fields[i].length; j++)
+ for (int j = 0; j < FIELDS[i].length; j++)
{
assertEquals("Invalid field " + j + " in table " + i,
- fields[i][j], configDest.getString(keyTab
+ FIELDS[i][j], configDest.getString(keyTab
+ "fields.field(" + j + ").name"));
}
}
}
/**
+ * Tests adding a null collection of nodes. This should be a no-op.
+ */
+ public void testAddNodesNull()
+ {
+ config.addNodes("tables", null);
+ checkContent(config);
+ }
+
+ /**
* Tests removing children from a configuration node.
*/
public void testNodeRemove()
@@ -703,7 +731,7 @@
public void testNodeVisitor()
{
CountVisitor v = new CountVisitor();
- config.getRootNode().visit(v);
+ config.visit(config.getRootNode(), v);
assertEquals(28, v.beforeCount);
assertEquals(v.beforeCount, v.afterCount);
}
@@ -716,7 +744,7 @@
{
config.setExpressionEngine(null);
assertNotNull("Expression engine is null", config.getExpressionEngine());
- assertSame("Default engine is not used", HierarchicalConfiguration
+ assertSame("Default engine is not used", AbstractHierarchicalConfiguration
.getDefaultExpressionEngine(), config.getExpressionEngine());
config.setExpressionEngine(createAlternativeExpressionEngine());
@@ -729,11 +757,11 @@
*/
public void testSetDefaultExpressionEngine()
{
- ExpressionEngine engineOld = HierarchicalConfiguration.getDefaultExpressionEngine();
- HierarchicalConfiguration
+ ExpressionEngine engineOld = AbstractHierarchicalConfiguration.getDefaultExpressionEngine();
+ AbstractHierarchicalConfiguration
.setDefaultExpressionEngine(createAlternativeExpressionEngine());
checkAlternativeSyntax();
- HierarchicalConfiguration.setDefaultExpressionEngine(engineOld);
+ AbstractHierarchicalConfiguration.setDefaultExpressionEngine(engineOld);
}
/**
@@ -744,7 +772,7 @@
{
try
{
- HierarchicalConfiguration.setDefaultExpressionEngine(null);
+ InMemoryConfiguration.setDefaultExpressionEngine(null);
fail("Could set default expression engine to null!");
}
catch (IllegalArgumentException iex)
@@ -758,7 +786,7 @@
*/
public void testInitCopy()
{
- HierarchicalConfiguration copy = new HierarchicalConfiguration(config);
+ InMemoryConfiguration copy = new InMemoryConfiguration(config);
checkContent(copy);
}
@@ -768,7 +796,7 @@
*/
public void testInitCopyUpdate()
{
- HierarchicalConfiguration copy = new HierarchicalConfiguration(config);
+ InMemoryConfiguration copy = new InMemoryConfiguration(config);
config.setProperty("tables.table(0).name", "NewTable");
checkContent(copy);
}
@@ -870,7 +898,7 @@
*/
public void testInterpolatedConfiguration()
{
- HierarchicalConfiguration c = (HierarchicalConfiguration) InterpolationTestHelper
+ InMemoryConfiguration c = (InMemoryConfiguration) InterpolationTestHelper
.testInterpolatedConfiguration(config);
// tests whether the hierarchical structure has been maintained
@@ -883,7 +911,7 @@
*/
public void testInitCopyNull()
{
- HierarchicalConfiguration copy = new HierarchicalConfiguration(null);
+ InMemoryConfiguration copy = new InMemoryConfiguration(null);
assertTrue("Configuration not empty", copy.isEmpty());
}
@@ -923,8 +951,8 @@
*/
private void checkAlternativeSyntax()
{
- assertNull(config.getProperty("tables/table/resultset"));
- assertNull(config.getProperty("tables/table/fields/field"));
+ assertNull(config.getProperty("tables.table/resultset"));
+ assertNull(config.getProperty("tables.table/fields/field"));
Object prop = config.getProperty("tables/table[0]/fields/field/name");
assertNotNull(prop);
@@ -950,10 +978,11 @@
{
keys.add(it.next().toString());
}
- assertEquals("Wrong number of defined keys", 2, keys.size());
- assertTrue("Key not found", keys.contains("tables/table/name"));
- assertTrue("Key not found", keys
+ assertEquals("Wrong number of defined keys", 3, keys.size());
+ assertTrue("Key 1 not found", keys.contains("tables/table/name"));
+ assertTrue("Key 2 not found", keys
.contains("tables/table/fields/field/name"));
+ assertTrue("Attr key not found", keys.contains("tables/table[@sysTab]"));
}
/**
@@ -964,15 +993,19 @@
*/
private void checkContent(Configuration c)
{
- for (int i = 0; i < tables.length; i++)
- {
- assertEquals(tables[i], c.getString("tables.table(" + i + ").name"));
- for (int j = 0; j < fields[i].length; j++)
- {
- assertEquals(fields[i][j], c.getString("tables.table(" + i
- + ").fields.field(" + j + ").name"));
- }
- }
+ for (int i = 0; i < TABLES.length; i++)
+ {
+ assertEquals("Wrong table name", TABLES[i], c
+ .getString("tables.table(" + i + ").name"));
+ assertEquals("Wrong system flag", SYS_TABLES[i].booleanValue(), c
+ .getBoolean("tables.table(" + i + ")[@sysTab]"));
+ for (int j = 0; j < FIELDS[i].length; j++)
+ {
+ assertEquals("Wrong field", FIELDS[i][j], c
+ .getString("tables.table(" + i + ").fields.field(" + j
+ + ").name"));
+ }
+ }
}
private ExpressionEngine createAlternativeExpressionEngine()
@@ -1014,23 +1047,23 @@
* A test visitor implementation for checking whether all visitor methods
* are correctly called.
*/
- static class CountVisitor extends ConfigurationNodeVisitorAdapter
+ static class CountVisitor extends NodeVisitorAdapter<ConfigurationNode>
{
public int beforeCount;
public int afterCount;
@Override
- public void visitAfterChildren(ConfigurationNode node)
+ public void visitAfterChildren(ConfigurationNode node, NodeHandler<ConfigurationNode> handler)
{
- super.visitAfterChildren(node);
+ super.visitAfterChildren(node, handler);
afterCount++;
}
@Override
- public void visitBeforeChildren(ConfigurationNode node)
+ public void visitBeforeChildren(ConfigurationNode node, NodeHandler<ConfigurationNode> handler)
{
- super.visitBeforeChildren(node);
+ super.visitBeforeChildren(node, handler);
beforeCount++;
}
}
Copied: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java (from r632835, commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java)
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java?p2=commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java&p1=commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java&r1=632835&r2=635082&rev=635082&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubnodeConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestSubConfiguration.java Sat Mar 8 12:43:33 2008
@@ -23,24 +23,19 @@
import java.util.NoSuchElementException;
import java.util.Set;
-import org.apache.commons.configuration2.Configuration;
-import org.apache.commons.configuration2.ConfigurationException;
-import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.SubnodeConfiguration;
-import org.apache.commons.configuration2.XMLConfiguration;
-import org.apache.commons.configuration2.reloading.FileAlwaysReloadingStrategy;
-import org.apache.commons.configuration2.tree.ConfigurationNode;
-import org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine;
-
import junit.framework.TestCase;
+import org.apache.commons.configuration2.expr.ExpressionEngine;
+import org.apache.commons.configuration2.tree.ConfigurationNode;
+import org.easymock.EasyMock;
+
/**
- * Test case for SubnodeConfiguration.
+ * Test class for SubConfiguration.
*
* @author Oliver Heger
* @version $Id$
*/
-public class TestSubnodeConfiguration extends TestCase
+public class TestSubConfiguration extends TestCase
{
/** An array with names of tables (test data). */
private static final String[] TABLE_NAMES =
@@ -55,21 +50,19 @@
/** Constant for a test output file.*/
private static final File TEST_FILE = new File("target/test.xml");
- /** Constant for an updated table name.*/
- private static final String NEW_TABLE_NAME = "newTable";
+// /** Constant for an updated table name.*/
+// private static final String NEW_TABLE_NAME = "newTable";
/** The parent configuration. */
- HierarchicalConfiguration parent;
+ private InMemoryConfiguration parent;
- /** The subnode configuration to be tested. */
- SubnodeConfiguration config;
-
- /** Stores the root node of the subnode config. */
- ConfigurationNode subnode;
+ /** The sub configuration to be tested. */
+ private SubConfiguration<ConfigurationNode> config;
/** Stores a counter for the created nodes. */
- int nodeCounter;
+ private int nodeCounter;
+ @Override
protected void setUp() throws Exception
{
super.setUp();
@@ -77,6 +70,7 @@
nodeCounter = 0;
}
+ @Override
protected void tearDown() throws Exception
{
// remove the test output file if necessary
@@ -87,7 +81,7 @@
}
/**
- * Tests creation of a subnode config.
+ * Tests the creation of a sub configuration.
*/
public void testInitSubNodeConfig()
{
@@ -98,14 +92,14 @@
}
/**
- * Tests constructing a subnode configuration with a null parent. This
+ * Tests constructing a sub configuration with a null parent. This
* should cause an exception.
*/
public void testInitSubNodeConfigWithNullParent()
{
try
{
- config = new SubnodeConfiguration(null, getSubnodeRoot(parent));
+ config = new SubConfiguration<ConfigurationNode>(null, getSubnodeRoot(parent));
fail("Could set a null parent config!");
}
catch (IllegalArgumentException iex)
@@ -115,14 +109,14 @@
}
/**
- * Tests constructing a subnode configuration with a null root node. This
+ * Tests constructing a sub configuration with a null root node. This
* should cause an exception.
*/
public void testInitSubNodeConfigWithNullNode()
{
try
{
- config = new SubnodeConfiguration(parent, null);
+ config = new SubConfiguration<ConfigurationNode>(parent, null);
fail("Could set a null root node!");
}
catch (IllegalArgumentException iex)
@@ -175,7 +169,6 @@
{
setUpSubnodeConfig();
config.addProperty("[@table-type]", "test");
- assertEquals("parent.createNode() was not called", 1, nodeCounter);
assertEquals("Attribute not set", "test", parent
.getString("tables.table(0)[@table-type]"));
@@ -267,27 +260,28 @@
.getListDelimiter());
}
- /**
- * Tests changing the expression engine.
- */
- public void testSetExpressionEngine()
- {
- parent.setExpressionEngine(new XPathExpressionEngine());
- setUpSubnodeConfig();
- assertEquals("Wrong field name", TABLE_FIELDS[0][1], config
- .getString("fields/field[2]/name"));
- Set<String> keys = new HashSet<String>();
- for (Iterator<?> it = config.getKeys(); it.hasNext();)
- {
- keys.add(it.next().toString());
- }
- assertEquals("Wrong number of keys", 2, keys.size());
- assertTrue("Key 1 not contained", keys.contains("name"));
- assertTrue("Key 2 not contained", keys.contains("fields/field/name"));
- config.setExpressionEngine(null);
- assertTrue("Expression engine reset on parent", parent
- .getExpressionEngine() instanceof XPathExpressionEngine);
- }
+// TODO uncomment when XPathExpressionEngine has been ported
+// /**
+// * Tests changing the expression engine.
+// */
+// public void testSetExpressionEngine()
+// {
+// parent.setExpressionEngine(new XPathExpressionEngine());
+// setUpSubnodeConfig();
+// assertEquals("Wrong field name", TABLE_FIELDS[0][1], config
+// .getString("fields/field[2]/name"));
+// Set<String> keys = new HashSet<String>();
+// for (Iterator<?> it = config.getKeys(); it.hasNext();)
+// {
+// keys.add(it.next().toString());
+// }
+// assertEquals("Wrong number of keys", 2, keys.size());
+// assertTrue("Key 1 not contained", keys.contains("name"));
+// assertTrue("Key 2 not contained", keys.contains("fields/field/name"));
+// config.setExpressionEngine(null);
+// assertTrue("Expression engine reset on parent", parent
+// .getExpressionEngine() instanceof XPathExpressionEngine);
+// }
/**
* Tests the configurationAt() method.
@@ -295,7 +289,7 @@
public void testConfiguarationAt()
{
setUpSubnodeConfig();
- SubnodeConfiguration sub2 = (SubnodeConfiguration) config
+ SubConfiguration<ConfigurationNode> sub2 = (SubConfiguration<ConfigurationNode>) config
.configurationAt("fields.field(1)");
assertEquals("Wrong value of property", TABLE_FIELDS[0][1], sub2
.getString("name"));
@@ -303,7 +297,7 @@
}
/**
- * Tests interpolation features. The subnode config should use its parent
+ * Tests interpolation features. The sub configuration should use its parent
* for interpolation.
*/
public void testInterpolation()
@@ -341,101 +335,102 @@
}
}
- /**
- * Tests a reload operation for the parent configuration when the subnode
- * configuration does not support reloads. Then the new value should not be
- * detected.
- */
- public void testParentReloadNotSupported() throws ConfigurationException
- {
- Configuration c = setUpReloadTest(false);
- assertEquals("Name changed in sub config", TABLE_NAMES[1], config
- .getString("name"));
- assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
- .getString("tables.table(1).name"));
- }
-
- /**
- * Tests a reload operation for the parent configuration when the subnode
- * configuration does support reloads. The new value should be returned.
- */
- public void testParentReloadSupported() throws ConfigurationException
- {
- Configuration c = setUpReloadTest(true);
- assertEquals("Name not changed in sub config", NEW_TABLE_NAME, config
- .getString("name"));
- assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
- .getString("tables.table(1).name"));
- }
-
- /**
- * Tests a reload operation for the parent configuration when the subnode
- * configuration is aware of reloads, and the parent configuration is
- * accessed first. The new value should be returned.
- */
- public void testParentReloadSupportAccessParent()
- throws ConfigurationException
- {
- Configuration c = setUpReloadTest(true);
- assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
- .getString("tables.table(1).name"));
- assertEquals("Name not changed in sub config", NEW_TABLE_NAME, config
- .getString("name"));
- }
-
- /**
- * Tests whether reloads work with sub subnode configurations.
- */
- public void testParentReloadSubSubnode() throws ConfigurationException
- {
- setUpReloadTest(true);
- SubnodeConfiguration sub = config.configurationAt("fields", true);
- assertEquals("Wrong subnode key", "tables.table(1).fields", sub
- .getSubnodeKey());
- assertEquals("Changed field not detected", "newField", sub
- .getString("field(0).name"));
- }
-
- /**
- * Tests creating a sub sub config when the sub config is not aware of
- * changes. Then the sub sub config shouldn't be either.
- */
- public void testParentReloadSubSubnodeNoChangeSupport()
- throws ConfigurationException
- {
- setUpReloadTest(false);
- SubnodeConfiguration sub = config.configurationAt("fields", true);
- assertNull("Sub sub config is attached to parent", sub.getSubnodeKey());
- assertEquals("Changed field name returned", TABLE_FIELDS[1][0], sub
- .getString("field(0).name"));
- }
-
- /**
- * Prepares a test for a reload operation.
- *
- * @param supportReload a flag whether the subnode configuration should
- * support reload operations
- * @return the parent configuration that can be used for testing
- * @throws ConfigurationException if an error occurs
- */
- private XMLConfiguration setUpReloadTest(boolean supportReload)
- throws ConfigurationException
- {
- XMLConfiguration xmlConf = new XMLConfiguration(parent);
- xmlConf.setFile(TEST_FILE);
- xmlConf.save();
- config = xmlConf.configurationAt("tables.table(1)", supportReload);
- assertEquals("Wrong table name", TABLE_NAMES[1], config
- .getString("name"));
- xmlConf.setReloadingStrategy(new FileAlwaysReloadingStrategy());
- // Now change the configuration file
- XMLConfiguration confUpdate = new XMLConfiguration(TEST_FILE);
- confUpdate.setProperty("tables.table(1).name", NEW_TABLE_NAME);
- confUpdate.setProperty("tables.table(1).fields.field(0).name",
- "newField");
- confUpdate.save();
- return xmlConf;
- }
+//TODO uncomment when reloading features are available
+// /**
+// * Tests a reload operation for the parent configuration when the subnode
+// * configuration does not support reloads. Then the new value should not be
+// * detected.
+// */
+// public void testParentReloadNotSupported() throws ConfigurationException
+// {
+// Configuration c = setUpReloadTest(false);
+// assertEquals("Name changed in sub config", TABLE_NAMES[1], config
+// .getString("name"));
+// assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
+// .getString("tables.table(1).name"));
+// }
+//
+// /**
+// * Tests a reload operation for the parent configuration when the subnode
+// * configuration does support reloads. The new value should be returned.
+// */
+// public void testParentReloadSupported() throws ConfigurationException
+// {
+// Configuration c = setUpReloadTest(true);
+// assertEquals("Name not changed in sub config", NEW_TABLE_NAME, config
+// .getString("name"));
+// assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
+// .getString("tables.table(1).name"));
+// }
+//
+// /**
+// * Tests a reload operation for the parent configuration when the subnode
+// * configuration is aware of reloads, and the parent configuration is
+// * accessed first. The new value should be returned.
+// */
+// public void testParentReloadSupportAccessParent()
+// throws ConfigurationException
+// {
+// Configuration c = setUpReloadTest(true);
+// assertEquals("Name not changed in parent", NEW_TABLE_NAME, c
+// .getString("tables.table(1).name"));
+// assertEquals("Name not changed in sub config", NEW_TABLE_NAME, config
+// .getString("name"));
+// }
+//
+// /**
+// * Tests whether reloads work with sub subnode configurations.
+// */
+// public void testParentReloadSubSubnode() throws ConfigurationException
+// {
+// setUpReloadTest(true);
+// SubnodeConfiguration sub = config.configurationAt("fields", true);
+// assertEquals("Wrong subnode key", "tables.table(1).fields", sub
+// .getSubnodeKey());
+// assertEquals("Changed field not detected", "newField", sub
+// .getString("field(0).name"));
+// }
+//
+// /**
+// * Tests creating a sub sub config when the sub config is not aware of
+// * changes. Then the sub sub config shouldn't be either.
+// */
+// public void testParentReloadSubSubnodeNoChangeSupport()
+// throws ConfigurationException
+// {
+// setUpReloadTest(false);
+// SubnodeConfiguration sub = config.configurationAt("fields", true);
+// assertNull("Sub sub config is attached to parent", sub.getSubnodeKey());
+// assertEquals("Changed field name returned", TABLE_FIELDS[1][0], sub
+// .getString("field(0).name"));
+// }
+//
+// /**
+// * Prepares a test for a reload operation.
+// *
+// * @param supportReload a flag whether the subnode configuration should
+// * support reload operations
+// * @return the parent configuration that can be used for testing
+// * @throws ConfigurationException if an error occurs
+// */
+// private XMLConfiguration setUpReloadTest(boolean supportReload)
+// throws ConfigurationException
+// {
+// XMLConfiguration xmlConf = new XMLConfiguration(parent);
+// xmlConf.setFile(TEST_FILE);
+// xmlConf.save();
+// config = xmlConf.configurationAt("tables.table(1)", supportReload);
+// assertEquals("Wrong table name", TABLE_NAMES[1], config
+// .getString("name"));
+// xmlConf.setReloadingStrategy(new FileAlwaysReloadingStrategy());
+// // Now change the configuration file
+// XMLConfiguration confUpdate = new XMLConfiguration(TEST_FILE);
+// confUpdate.setProperty("tables.table(1).name", NEW_TABLE_NAME);
+// confUpdate.setProperty("tables.table(1).fields.field(0).name",
+// "newField");
+// confUpdate.save();
+// return xmlConf;
+// }
/**
* Tests a manipulation of the parent configuration that causes the subnode
@@ -445,7 +440,7 @@
public void testParentChangeDetach()
{
final String key = "tables.table(1)";
- config = parent.configurationAt(key, true);
+ config = (SubConfiguration<ConfigurationNode>) parent.configurationAt(key, true);
assertEquals("Wrong subnode key", key, config.getSubnodeKey());
assertEquals("Wrong table name", TABLE_NAMES[1], config
.getString("name"));
@@ -456,17 +451,21 @@
}
/**
- * Tests detaching a subnode configuration when an exception is thrown
+ * Tests detaching a sub configuration when an exception is thrown
* during reconstruction. This can happen e.g. if the expression engine is
* changed for the parent.
*/
public void testParentChangeDetatchException()
{
- config = parent.configurationAt("tables.table(1)", true);
- parent.setExpressionEngine(new XPathExpressionEngine());
+ ExpressionEngine engine = EasyMock.createMock(ExpressionEngine.class);
+ config = (SubConfiguration<ConfigurationNode>) parent.configurationAt("tables.table(1)", true);
+ EasyMock.expect(engine.query(parent.getRootNode(), config.getSubnodeKey(), parent.getNodeHandler())).andThrow(new ConfigurationRuntimeException("Test exception"));
+ EasyMock.replay(engine);
+ parent.setExpressionEngine(engine);
assertEquals("Wrong name of table", TABLE_NAMES[1], config
.getString("name"));
assertNull("Sub config was not detached", config.getSubnodeKey());
+ EasyMock.verify(engine);
}
/**
@@ -475,18 +474,18 @@
*
* @return the parent configuration
*/
- protected HierarchicalConfiguration setUpParentConfig()
+ protected InMemoryConfiguration setUpParentConfig()
{
@SuppressWarnings("serial")
- HierarchicalConfiguration conf = new HierarchicalConfiguration()
+ InMemoryConfiguration conf = new InMemoryConfiguration()
{
// Provide a special implementation of createNode() to check
// if it is called by the subnode config
@Override
- protected ConfigurationNode createNode(String name)
+ protected ConfigurationNode createNode(ConfigurationNode parent, String name)
{
nodeCounter++;
- return super.createNode(name);
+ return super.createNode(parent, name);
}
};
for (int i = 0; i < TABLE_NAMES.length; i++)
@@ -508,7 +507,7 @@
* @param conf the parent config
* @return the root node for the subnode config
*/
- protected ConfigurationNode getSubnodeRoot(HierarchicalConfiguration conf)
+ protected ConfigurationNode getSubnodeRoot(InMemoryConfiguration conf)
{
ConfigurationNode root = conf.getRootNode();
return root.getChild(0).getChild(0);
@@ -519,6 +518,6 @@
*/
protected void setUpSubnodeConfig()
{
- config = new SubnodeConfiguration(parent, getSubnodeRoot(parent));
+ config = new SubConfiguration<ConfigurationNode>(parent, getSubnodeRoot(parent));
}
}