Package org.apache.commons.configuration.tree

Examples of org.apache.commons.configuration.tree.ConfigurationNode


     * Tests saving a configuration after a node was added. Test for
     * CONFIGURATION-294.
     */
    public void testAddNodesAndSave() throws ConfigurationException
    {
        ConfigurationNode node = new HierarchicalConfiguration.Node("test");
        ConfigurationNode child = new HierarchicalConfiguration.Node("child");
        node.addChild(child);
        ConfigurationNode attr = new HierarchicalConfiguration.Node("attr");
        node.addAttribute(attr);
        ConfigurationNode node2 = conf.createNode("test2");
        Collection nodes = new ArrayList(2);
        nodes.add(node);
        nodes.add(node2);
        conf.addNodes("add.nodes", nodes);
        conf.setFile(testSaveConf);
View Full Code Here


        conf.addProperty("testAddNodes.property(1).value", "value2");
        Collection nodes = new ArrayList();
        nodes.add(new HierarchicalConfiguration.Node("property"));
        conf.addNodes("testAddNodes", nodes);
        nodes.clear();
        ConfigurationNode nd = new HierarchicalConfiguration.Node("name",
                "prop3");
        nd.setAttribute(true);
        nodes.add(nd);
        conf.addNodes("testAddNodes.property(2)", nodes);
        assertEquals("Attribute not added", "prop3", conf
                .getString("testAddNodes.property(2)[@name]"));
    }
View Full Code Here

     * Tests adding an attribute node with the addNodes() method.
     */
    public void testAddNodesAttributeNode()
    {
        Collection nodes = new ArrayList();
        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]"));
    }
View Full Code Here

        config.setRootNode(root);
        config.addProperty("child2", "test2");
        List nodes = config.getExpressionEngine().query(config.getRootNode(),
                "child2");
        assertEquals("Wrong number of result nodes", 1, nodes.size());
        ConfigurationNode child2 = (ConfigurationNode) nodes.get(0);
        assertEquals("Different parent nodes", child1.getParentNode(), child2
                .getParentNode());
    }
View Full Code Here

        DefaultConfigurationNode child1 = new DefaultConfigurationNode(
                "child1", "test1");
        root.addChild(child1);
        config.setRootNode(root);
        config.addProperty("child2", "test2");
        ConfigurationNode oldRoot = config.getRoot();
        assertEquals("Wrong number of children", 2, oldRoot.getChildrenCount());
    }
View Full Code Here

     * @param conf the parent config
     * @return the root node for the subnode config
     */
    protected ConfigurationNode getSubnodeRoot(HierarchicalConfiguration conf)
    {
        ConfigurationNode root = conf.getRoot();
        return root.getChild(0).getChild(0);
    }
View Full Code Here

    {
        List nodes = context.selectNodes(CHILD_NAME1);
        assertEquals("Incorrect number of results", 2, nodes.size());
        for (Iterator it = nodes.iterator(); it.hasNext();)
        {
            ConfigurationNode node = (ConfigurationNode) it.next();
            assertEquals("Incorrect node name", CHILD_NAME1, node.getName());
            assertEquals("Incorrect parent node", root, node.getParentNode());
        }

        nodes = context.selectNodes("/" + CHILD_NAME1);
        assertEquals("Incorrect number of results", 2, nodes.size());
View Full Code Here

        List nodes = context.selectNodes("/" + CHILD_NAME1 + "[1]/*");
        assertEquals("Wrong number of children", CHILD_COUNT, nodes.size());
        int index = 1;
        for (Iterator it = nodes.iterator(); it.hasNext(); index++)
        {
            ConfigurationNode node = (ConfigurationNode) it.next();
            assertEquals("Wrong node value for child " + index, "2." + index,
                    node.getValue());
        }
    }
View Full Code Here

        assertEquals("Incorrect attribute value", "1", context.getValue("/"
                + CHILD_NAME2 + "[1]/@" + ATTR_NAME));

        assertTrue("Found elements with name attribute", context.selectNodes(
                "//" + CHILD_NAME2 + "[@name]").isEmpty());
        ConfigurationNode node = (ConfigurationNode) root.getChild(2).getChild(
                1).getChildren(CHILD_NAME2).get(1);
        node.addAttribute(new DefaultConfigurationNode("name", "testValue"));
        List nodes = context.selectNodes("//" + CHILD_NAME2 + "[@name]");
        assertEquals("Name attribute not found", 1, nodes.size());
        assertEquals("Wrong node returned", node, nodes.get(0));
    }
View Full Code Here

    public void testFollowingSiblingAxis()
    {
        List nodes = context.selectNodes("/" + CHILD_NAME1
                + "[2]/following-sibling::*");
        assertEquals("Wrong number of following siblings", 1, nodes.size());
        ConfigurationNode node = (ConfigurationNode) nodes.get(0);
        assertEquals("Wrong node type", CHILD_NAME2, node.getName());
        assertEquals("Wrong index", String.valueOf(CHILD_COUNT), node
                .getValue());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.tree.ConfigurationNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.