Package org.apache.commons.configuration.tree

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


    /**
     * Tests nodeKey() for an attribute node.
     */
    public void testNodeKeyAttribute()
    {
        ConfigurationNode node = new DefaultConfigurationNode("attr");
        node.setAttribute(true);
        assertEquals("Wrong attribute key", "node/@attr", engine.nodeKey(node,
                "node"));
    }
View Full Code Here


    /**
     * Tests node key() for direct children of the root node.
     */
    public void testNodeKeyForRootChild()
    {
        ConfigurationNode node = new DefaultConfigurationNode("child");
        assertEquals("Wrong key for root child node", "child", engine.nodeKey(
                node, ""));
        node.setAttribute(true);
        assertEquals("Wrong key for root attribute", "@child", engine.nodeKey(
                node, ""));
    }
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

    public void testInitCopy() throws ConfigurationException
    {
        XMLConfiguration copy = new XMLConfiguration(conf);
        assertEquals("value", copy.getProperty("element"));
        assertNull("Document was copied, too", copy.getDocument());
        ConfigurationNode root = copy.getRootNode();
        for (ConfigurationNode node : root.getChildren())
        {
            assertNull("Reference was not cleared", node.getReference());
        }

        removeTestFile();
View Full Code Here

     * CONFIGURATION-294.
     */
    @Test
    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<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(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<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
        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

    public void testAddNodesToSubnodeConfiguration()
            throws ConfigurationException
    {
        SubnodeConfiguration sub = conf.configurationAt("element2");
        sub.addProperty("newKey", "newvalue");
        ConfigurationNode root = conf.getRootNode();
        ConfigurationNode elem = root.getChildren("element2").get(0);
        ConfigurationNode newNode = elem.getChildren("newKey").get(0);
        assertTrue("Wrong node type: " + newNode,
                newNode instanceof XMLConfiguration.XMLNode);
    }
View Full Code Here

        List list = config.configurationsAt("colors/*");
        Iterator iter = list.iterator();
        while (iter.hasNext())
        {
            SubnodeConfiguration sub = (SubnodeConfiguration)iter.next();
            ConfigurationNode node = sub.getRootNode();
            String value = (node.getValue() == null) ? "null" : node.getValue().toString();
            if (map.containsKey(node.getName()))
            {
                assertEquals(map.get(node.getName()), value);
            }
        }

    }
View Full Code Here

        List<HierarchicalConfiguration> list = config.configurationsAt("colors/*");
        Iterator<HierarchicalConfiguration> iter = list.iterator();
        while (iter.hasNext())
        {
            SubnodeConfiguration sub = (SubnodeConfiguration)iter.next();
            ConfigurationNode node = sub.getRootNode();
            String value = (node.getValue() == null) ? "null" : node.getValue().toString();
            if (map.containsKey(node.getName()))
            {
                assertEquals(map.get(node.getName()), value);
            }
        }

    }
View Full Code Here

    public void testInitCopy() throws ConfigurationException
    {
        XMLConfiguration copy = new XMLConfiguration(conf);
        assertEquals("value", copy.getProperty("element"));
        assertNull("Document was copied, too", copy.getDocument());
        ConfigurationNode root = copy.getRootNode();
        for(Iterator it = root.getChildren().iterator(); it.hasNext();)
        {
            ConfigurationNode node = (ConfigurationNode) it.next();
            assertNull("Reference was not cleared", node.getReference());
        }

        removeTestFile();
        copy.setFile(testSaveConf);
        copy.save();
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.