Author: oheger Date: Sun Apr 16 10:32:02 2006 New Revision: 394521 URL: http://svn.apache.org/viewcvs?rev=394521&view=rev Log: Added tests for NodeCombiner classes
Added: jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml (with props) jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml (with props) jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java (with props) jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java (with props) jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java (with props) jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java (with props) Modified: jakarta/commons/proper/configuration/trunk/build.xml jakarta/commons/proper/configuration/trunk/project.xml Modified: jakarta/commons/proper/configuration/trunk/build.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/build.xml?rev=394521&r1=394520&r2=394521&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/build.xml (original) +++ jakarta/commons/proper/configuration/trunk/build.xml Sun Apr 16 10:32:02 2006 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - Copyright 2004-2005 The Apache Software Foundation + Copyright 2004-2006 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -147,6 +147,7 @@ </exclude> <exclude name="**/XPathTest.java"> </exclude> + <exclude name="**/AbstractCombinerTest.java"/> </fileset> </batchtest> </junit> Added: jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml?rev=394521&view=auto ============================================================================== --- jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml (added) +++ jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml Sun Apr 16 10:32:02 2006 @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> + +<config> + <gui> + <bgcolor>green</bgcolor> + <selcolor>yellow</selcolor> + <level default="2">1</level> + </gui> + <net> + <proxy> + <url>http://www.url1.org</url> + <url>http://www.url2.org</url> + <url>http://www.url3.org</url> + </proxy> + <service> + <url>http://service1.org</url> + </service> + <server> + </server> + </net> + <base> + <services> + <security> + <login> + <user>Admin</user> + <passwd type="secret"/> + </login> + </security> + </services> + </base> + <database> + <tables> + <table id="1"> + <name>documents</name> + <fields> + <field> + <name>docid</name> + <type>long</type> + </field> + <field> + <name>docname</name> + <type>varchar</type> + </field> + <field> + <name>authorID</name> + <type>int</type> + </field> + </fields> + </table> + </tables> + </database> +</config> Propchange: jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/commons/proper/configuration/trunk/conf/testcombine1.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml?rev=394521&view=auto ============================================================================== --- jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml (added) +++ jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml Sun Apr 16 10:32:02 2006 @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> + +<config> + <base> + <services> + <security> + <login> + <user type="default">scotty</user> + <passwd>BeamMeUp</passwd> + </login> + </security> + </services> + </base> + <gui> + <bgcolor>black</bgcolor> + <fgcolor>blue</fgcolor> + <level min="1">4</level> + </gui> + <net> + <server> + <url>http://appsvr1.com</url> + <url>http://appsvr2.com</url> + <url>http://testsvr.com</url> + <url>http://backupsvr.com</url> + </server> + <service> + <url type="2">http://service2.org</url> + <url type="2">http://service3.org</url> + </service> + </net> + <database> + <tables> + <table id="2"> + <name>tasks</name> + <fields> + <field> + <name>taskid</name> + <type>long</type> + </field> + <field> + <name>taskname</name> + <type>varchar</type> + </field> + </fields> + </table> + </tables> + </database> +</config> Propchange: jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/commons/proper/configuration/trunk/conf/testcombine2.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Modified: jakarta/commons/proper/configuration/trunk/project.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/project.xml?rev=394521&r1=394520&r2=394521&view=diff ============================================================================== --- jakarta/commons/proper/configuration/trunk/project.xml (original) +++ jakarta/commons/proper/configuration/trunk/project.xml Sun Apr 16 10:32:02 2006 @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="iso-8859-1"?> <!-- - Copyright 2001-2005 The Apache Software Foundation + Copyright 2001-2006 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -430,6 +430,7 @@ <exclude>**/NonStringTestHolder.java</exclude> <exclude>**/TestAbstractConfiguration.java</exclude> <exclude>**/XPathTest.java</exclude> + <exclude>**/AbstractCombinerTest.java</exclude> </excludes> <resources> <resource> Added: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java?rev=394521&view=auto ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java (added) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java Sun Apr 16 10:32:02 2006 @@ -0,0 +1,89 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.tree; + +import java.io.File; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.configuration.XMLConfiguration; + +import junit.framework.TestCase; + +/** + * A base class for testing combiner implementations. This base class provides + * some functionality for loading the test configurations, which are to be + * combined. Concrete sub classes only need to create the correct combiner + * object. + * + * @version $Id$ + */ +public abstract class AbstractCombinerTest extends TestCase +{ + /** Constant for the first test configuration. */ + static File CONF1 = new File("conf/testcombine1.xml"); + + /** Constant for the second test configuration. */ + static File CONF2 = new File("conf/testcombine2.xml"); + + /** The combiner to be tested. */ + protected NodeCombiner combiner; + + protected void setUp() throws Exception + { + super.setUp(); + combiner = createCombiner(); + } + + /** + * Creates the combiner to be tested. This method is called by + * <code>setUp()</code>. It must be implemented in concrete sub classes. + * + * @return the combiner to be tested + */ + protected abstract NodeCombiner createCombiner(); + + /** + * Constructs a union configuration based on the source configurations. + * + * @return the union configuration + * @throws ConfigurationException if an error occurs + */ + protected HierarchicalConfiguration createCombinedConfiguration() + throws ConfigurationException + { + XMLConfiguration conf1 = new XMLConfiguration(CONF1); + XMLConfiguration conf2 = new XMLConfiguration(CONF2); + ConfigurationNode cn = combiner.combine(conf1.getRootNode(), conf2 + .getRootNode()); + + HierarchicalConfiguration result = new HierarchicalConfiguration(); + result.setRootNode(cn); + + return result; + } + + /** + * Tests a newly created combiner. + */ + public void testInit() + { + assertTrue("Combiner has list nodes", combiner.getListNodes().isEmpty()); + assertFalse("Node is list node", combiner + .isListNode(new DefaultConfigurationNode("test"))); + } + +} Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/AbstractCombinerTest.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java?rev=394521&view=auto ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java (added) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java Sun Apr 16 10:32:02 2006 @@ -0,0 +1,164 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.tree; + +import java.util.List; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; + +/** + * Test class for OverrideCombiner. + * + * @version $Id$ + */ +public class TestOverrideCombiner extends AbstractCombinerTest +{ + /** + * Creates the combiner. + * + * @return the combiner + */ + protected NodeCombiner createCombiner() + { + return new OverrideCombiner(); + } + + /** + * Tests combination of simple elements. + */ + public void testSimpleValues() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Wrong number of bgcolors", 0, config + .getMaxIndex("gui.bgcolor")); + assertEquals("Wrong bgcolor", "green", config.getString("gui.bgcolor")); + assertEquals("Wrong selcolor", "yellow", config + .getString("gui.selcolor")); + assertEquals("Wrong fgcolor", "blue", config.getString("gui.fgcolor")); + assertEquals("Wrong level", 1, config.getInt("gui.level")); + } + + /** + * Tests combination of attributes. + */ + public void testAttributes() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Wrong value of min attribute", 1, config + .getInt("[EMAIL PROTECTED]")); + assertEquals("Wrong value of default attribute", 2, config + .getInt("[EMAIL PROTECTED]")); + assertEquals("Wrong number of id attributes", 0, config + .getMaxIndex("database.tables.table(0)[EMAIL PROTECTED]")); + assertEquals("Wrong value of table id", 1, config + .getInt("database.tables.table(0)[EMAIL PROTECTED]")); + } + + /** + * Tests whether property values are correctly overridden. + */ + public void testOverrideValues() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Wrong user", "Admin", config + .getString("base.services.security.login.user")); + assertEquals("Wrong user type", "default", config + .getString("[EMAIL PROTECTED]")); + assertEquals("Wrong password", "BeamMeUp", config + .getString("base.services.security.login.passwd")); + assertEquals("Wrong password type", "secret", config + .getString("[EMAIL PROTECTED]")); + } + + /** + * Tests if a list from the first node structure overrides a list in the + * second structure. + */ + public void testListFromFirstStructure() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Wrong number of services", 0, config + .getMaxIndex("net.service.url")); + assertEquals("Wrong service", "http://service1.org", config + .getString("net.service.url")); + assertFalse("Type attribute available", config + .containsKey("[EMAIL PROTECTED]")); + } + + /** + * Tests if a list from the second structure is added if it is not defined + * in the first structure. + */ + public void testListFromSecondStructure() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Wrong number of servers", 3, config + .getMaxIndex("net.server.url")); + assertEquals("Wrong server", "http://testsvr.com", config + .getString("net.server.url(2)")); + } + + /** + * 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. + */ + public void testCombinedTableNoList() throws ConfigurationException + { + ConfigurationNode tabNode = checkTable(createCombinedConfiguration()); + assertTrue("Node is not a view node", tabNode instanceof ViewNode); + } + + /** + * Tests the combination of the table structure when 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. + */ + public void testCombinedTableList() throws ConfigurationException + { + combiner.addListNode("table"); + ConfigurationNode tabNode = checkTable(createCombinedConfiguration()); + assertFalse("Node is a view node", tabNode instanceof ViewNode); + } + + /** + * Helper method for checking the combined table structure. + * + * @param config the config + * @return the node for the table element + */ + private ConfigurationNode checkTable(HierarchicalConfiguration config) + { + assertEquals("Wrong number of tables", 0, config + .getMaxIndex("database.tables.table")); + HierarchicalConfiguration c = config + .configurationAt("database.tables.table"); + 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 nds = config.getExpressionEngine().query(config.getRoot(), + "database.tables.table"); + assertFalse("No node found", nds.isEmpty()); + return (ConfigurationNode) nds.get(0); + } +} Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java?rev=394521&view=auto ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java (added) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java Sun Apr 16 10:32:02 2006 @@ -0,0 +1,125 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.tree; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; + +/** + * Test class for UnionCombiner. + * + * @version $Id$ + */ +public class TestUnionCombiner extends AbstractCombinerTest +{ + /** + * Creates the combiner. + * + * @return the combiner + */ + protected NodeCombiner createCombiner() + { + return new UnionCombiner(); + } + + /** + * Tests combination of simple values (no lists). + */ + public void testSimpleValues() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Too few bgcolors", 1, config.getMaxIndex("gui.bgcolor")); + assertEquals("Wrong first color", "green", config + .getString("gui.bgcolor(0)")); + assertEquals("Wrong second color", "black", config + .getString("gui.bgcolor(1)")); + assertEquals("Wrong number of selcolors", 0, config + .getMaxIndex("gui.selcolor")); + assertEquals("Wrong selcolor", "yellow", config + .getString("gui.selcolor")); + } + + /** + * Tests combinations of elements with attributes. + */ + public void testSimpleValuesWithAttributes() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Too few level elements", 1, config + .getMaxIndex("gui.level")); + assertEquals("Wrong value of first element", 1, config + .getInt("gui.level(0)")); + assertEquals("Wrong value of second element", 4, config + .getInt("gui.level(1)")); + assertEquals("Wrong value of first attribute", 2, config + .getInt("gui.level(0)[EMAIL PROTECTED]")); + assertFalse("Found wrong attribute", config + .containsKey("gui.level(0)[EMAIL PROTECTED]")); + assertEquals("Wrong value of second attribute", 1, config + .getInt("gui.level(1)[EMAIL PROTECTED]")); + } + + /** + * Tests combination of attributes. + */ + public void testAttributes() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Too few attributes", 1, config + .getMaxIndex("database.tables.table(0)[EMAIL PROTECTED]")); + assertEquals("Wrong value of first attribute", 1, config + .getInt("database.tables.table(0)[EMAIL PROTECTED](0)")); + assertEquals("Wrong value of second attribute", 2, config + .getInt("database.tables.table(0)[EMAIL PROTECTED](1)")); + } + + /** + * Tests combination of lists. + */ + public void testLists() throws ConfigurationException + { + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Too few list elements", 2, config + .getMaxIndex("net.service.url")); + assertEquals("Wrong first service", "http://service1.org", config + .getString("net.service.url(0)")); + assertEquals("Wrong second service", "http://service2.org", config + .getString("net.service.url(1)")); + assertEquals("Wrong service attribute", 2, config + .getInt("net.service.url(2)[EMAIL PROTECTED]")); + assertEquals("Wrong number of server elements", 3, config + .getMaxIndex("net.server.url")); + } + + /** + * Tests combining a list of tables. Per default the table elements will be + * combined. But if they are defined as list elements, the resulting tree + * should contain two table nodes. + */ + public void testTableList() throws ConfigurationException + { + combiner.addListNode("table"); + HierarchicalConfiguration config = createCombinedConfiguration(); + assertEquals("Wrong name of first table", "documents", config + .getString("database.tables.table(0).name")); + assertEquals("Wrong id of first table", 1, config + .getInt("database.tables.table(0)[EMAIL PROTECTED]")); + assertEquals("Wrong name of second table", "tasks", config + .getString("database.tables.table(1).name")); + assertEquals("Wrong id of second table", 2, config + .getInt("database.tables.table(1)[EMAIL PROTECTED]")); + } +} Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestUnionCombiner.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java?rev=394521&view=auto ============================================================================== --- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java (added) +++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java Sun Apr 16 10:32:02 2006 @@ -0,0 +1,148 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.configuration.tree; + +import junit.framework.TestCase; + +/** + * Test class for ViewNode. + * + * @version $Id$ + */ +public class TestViewNode extends TestCase +{ + /** Stores the view node to be tested. */ + ViewNode viewNode; + + /** Stores a regular node. */ + ConfigurationNode node; + + /** A child node of the regular node. */ + ConfigurationNode child; + + /** An attribute node of the regular node. */ + ConfigurationNode attr; + + protected void setUp() throws Exception + { + super.setUp(); + node = new DefaultConfigurationNode(); + child = new DefaultConfigurationNode("child"); + attr = new DefaultConfigurationNode("attr"); + node.addChild(child); + node.addAttribute(attr); + viewNode = new ViewNode(); + } + + /** + * Tests adding a child to the view node. + */ + public void testAddChild() + { + viewNode.addChild(child); + assertEquals("Parent was changed", node, child.getParentNode()); + assertEquals("Child was not added", 1, viewNode.getChildrenCount()); + } + + /** + * Tests adding a null child to the view node. This should throw an + * exception. + */ + public void testAddNullChild() + { + try + { + viewNode.addChild(null); + fail("Could add null child!"); + } + catch (IllegalArgumentException iex) + { + // ok + } + } + + /** + * Tests adding an attribute to the view node. + */ + public void testAddAttribute() + { + viewNode.addAttribute(attr); + assertEquals("Parent was changed", node, attr.getParentNode()); + assertEquals("Attribute was not added", 1, viewNode.getAttributeCount()); + } + + /** + * Tests adding a null attribute to the view node. This should cause an + * exception. + */ + public void testAddNullAttribute() + { + try + { + viewNode.addAttribute(null); + fail("Could add null attribute"); + } + catch (IllegalArgumentException iex) + { + // ok + } + } + + /** + * Tests appending all children to a view node. + */ + public void testAppendChildren() + { + viewNode.addChild(new DefaultConfigurationNode("testNode")); + viewNode.appendChildren(node); + assertEquals("Wrong number of children", 2, viewNode.getChildrenCount()); + assertEquals("Cannot find child", child, viewNode.getChild(1)); + assertEquals("Parent was changed", node, ((ConfigurationNode) viewNode + .getChild(1)).getParentNode()); + } + + /** + * Tests appending children from a null source. This should be a noop. + */ + public void testAppendNullChildren() + { + viewNode.appendChildren(null); + assertEquals("Wrong number of children", 0, viewNode.getChildrenCount()); + } + + /** + * tests appending all attributes to a view node. + */ + public void testAppendAttributes() + { + viewNode.appendAttributes(node); + assertEquals("Wrong number of attributes", 1, viewNode + .getAttributeCount()); + assertEquals("Cannot find attribute", attr, viewNode.getAttribute(0)); + assertEquals("Parent was changed", node, ((ConfigurationNode) viewNode + .getAttribute(0)).getParentNode()); + } + + /** + * Tests appending attributes from a null source. This should be a noop. + */ + public void testAppendNullAttributes() + { + viewNode.appendAttributes(null); + assertEquals("Wrong number of attributes", 0, viewNode + .getAttributeCount()); + } +} Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestViewNode.java ------------------------------------------------------------------------------ svn:mime-type = text/plain --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]