Package org.apache.commons.configuration

Examples of org.apache.commons.configuration.HierarchicalConfiguration


    /**
     * Tests events generated by the clearTree() method.
     */
    public void testClearTreeEvent()
    {
        HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
        String key = EXIST_PROPERTY.substring(0, EXIST_PROPERTY.indexOf('.'));
        Collection nodes = hc.getExpressionEngine()
                .query(hc.getRootNode(), key);
        hc.clearTree(key);
        l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key, null,
                true);
        l.checkEvent(HierarchicalConfiguration.EVENT_CLEAR_TREE, key, nodes,
                false);
        l.done();
View Full Code Here


    /**
     * Tests events generated by the addNodes() method.
     */
    public void testAddNodesEvent()
    {
        HierarchicalConfiguration hc = (HierarchicalConfiguration) config;
        Collection nodes = new ArrayList(1);
        nodes.add(new DefaultConfigurationNode("a_key", TEST_PROPVALUE));
        hc.addNodes(TEST_PROPNAME, nodes);
        l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES, TEST_PROPNAME,
                nodes, true);
        l.checkEvent(HierarchicalConfiguration.EVENT_ADD_NODES, TEST_PROPNAME,
                nodes, false);
        l.done();
View Full Code Here

    /**
     * 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"));
    }
View Full Code Here

    /**
     * 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)[@default]"));
        assertFalse("Found wrong attribute", config
                .containsKey("gui.level(0)[@min]"));
        assertEquals("Wrong value of second attribute", 1, config
                .getInt("gui.level(1)[@min]"));
    }
View Full Code Here

    /**
     * Tests combination of attributes.
     */
    public void testAttributes() throws ConfigurationException
    {
        HierarchicalConfiguration config = createCombinedConfiguration();
        assertEquals("Too few attributes", 1, config
                .getMaxIndex("database.tables.table(0)[@id]"));
        assertEquals("Wrong value of first attribute", 1, config
                .getInt("database.tables.table(0)[@id](0)"));
        assertEquals("Wrong value of second attribute", 2, config
                .getInt("database.tables.table(0)[@id](1)"));
    }
View Full Code Here

    /**
     * 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)[@type]"));
        assertEquals("Wrong number of server elements", 3, config
                .getMaxIndex("net.server.url"));
    }
View Full Code Here

     * 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)[@id]"));
        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)[@id]"));
    }
View Full Code Here

     */
    public void testInitFromNullNode()
    {
        try
        {
            decl = new XMLBeanDeclaration(new HierarchicalConfiguration().configurationAt(null),
                    (ConfigurationNode) null);
            fail("Could init declaration with null node!");
        }
        catch (IllegalArgumentException iex)
        {
View Full Code Here

     */
    public void testInitFromNullConfigurationAndNode()
    {
        try
        {
            decl = new XMLBeanDeclaration(null, new HierarchicalConfiguration()
                    .getRoot());
            fail("Could init declaration with null configuration and node!");
        }
        catch (IllegalArgumentException iex)
        {
View Full Code Here

    /**
     * Tests fetching the bean's class name.
     */
    public void testGetBeanClassName()
    {
        HierarchicalConfiguration config = new HierarchicalConfiguration();
        config.addProperty(KEY + "[@config-class]", getClass().getName());
        decl = new XMLBeanDeclaration(config, KEY);
        assertEquals("Wrong class name", getClass().getName(), decl
                .getBeanClassName());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.HierarchicalConfiguration

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.