Package org.apache.commons.configuration2

Examples of org.apache.commons.configuration2.BaseHierarchicalConfiguration


     * Tests events generated by the addNodes() method.
     */
    @Test
    public void testAddNodesEvent()
    {
        BaseHierarchicalConfiguration hc = (BaseHierarchicalConfiguration) config;
        Collection<ImmutableNode> nodes = new ArrayList<ImmutableNode>(1);
        nodes.add(NodeStructureHelper.createNode("a_key", TEST_PROPVALUE));
        hc.addNodes(TEST_PROPNAME, nodes);
        listener.checkEvent(ConfigurationEvent.ADD_NODES, TEST_PROPNAME,
                nodes, true);
        listener.checkEvent(ConfigurationEvent.ADD_NODES, TEST_PROPNAME,
                nodes, false);
        listener.done();
View Full Code Here


            // If we reach this block, the key does not have exactly one value
            if (!optional || config.getMaxIndex(key) > 0)
            {
                throw iex;
            }
            tmpconfiguration = new BaseHierarchicalConfiguration();
        }
        this.node = createNodeDataFromConfiguration(tmpconfiguration);
        this.configuration = tmpconfiguration;
        defaultBeanClassName = defBeanClsName;
        initSubnodeConfiguration(getConfiguration());
View Full Code Here

     * Tests combination of simple elements.
     */
    @Test
    public void testSimpleValues() throws ConfigurationException
    {
        BaseHierarchicalConfiguration 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"));
    }
View Full Code Here

     * Tests combination of attributes.
     */
    @Test
    public void testAttributes() throws ConfigurationException
    {
        BaseHierarchicalConfiguration config = createCombinedConfiguration();
        assertEquals("Wrong value of min attribute", 1, config
                .getInt("gui.level[@min]"));
        assertEquals("Wrong value of default attribute", 2, config
                .getInt("gui.level[@default]"));
        assertEquals("Wrong number of id attributes", 0, config
                .getMaxIndex("database.tables.table(0)[@id]"));
        assertEquals("Wrong value of table id", 1, config
                .getInt("database.tables.table(0)[@id]"));
    }
View Full Code Here

     * Tests whether property values are correctly overridden.
     */
    @Test
    public void testOverrideValues() throws ConfigurationException
    {
        BaseHierarchicalConfiguration config = createCombinedConfiguration();
        assertEquals("Wrong user", "Admin", config
                .getString("base.services.security.login.user"));
        assertEquals("Wrong user type", "default", config
                .getString("base.services.security.login.user[@type]"));
        assertEquals("Wrong password", "BeamMeUp", config
                .getString("base.services.security.login.passwd"));
        assertEquals("Wrong password type", "secret", config
                .getString("base.services.security.login.passwd[@type]"));
    }
View Full Code Here

     * second structure.
     */
    @Test
    public void testListFromFirstStructure() throws ConfigurationException
    {
        BaseHierarchicalConfiguration 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("net.service.url[@type]"));
    }
View Full Code Here

     * in the first structure.
     */
    @Test
    public void testListFromSecondStructure() throws ConfigurationException
    {
        BaseHierarchicalConfiguration 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)"));
    }
View Full Code Here

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

     * Tests fetching the bean's class name if it is undefined.
     */
    @Test
    public void testGetBeanClassNameUndefined()
    {
        XMLBeanDeclaration decl = new XMLBeanDeclaration(new BaseHierarchicalConfiguration());
        assertNull(decl.getBeanClassName());
    }
View Full Code Here

     * Tests that a missing bean class name does not cause an exception.
     */
    @Test
    public void testGetBeanClassNameUndefinedWithEx()
    {
        BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
        config.setThrowExceptionOnMissing(true);
        XMLBeanDeclaration decl = new XMLBeanDeclaration(config);
        assertNull("Got a bean class name", decl.getBeanClassName());
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration2.BaseHierarchicalConfiguration

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.