Package org.apache.commons.configuration2

Examples of org.apache.commons.configuration2.BaseHierarchicalConfiguration$BuilderVisitor


     * Tests whether constructor arguments can be queried.
     */
    @Test
    public void testGetConstructorArgs()
    {
        BaseHierarchicalConfiguration config = prepareNestedBeanDeclarations();
        XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
        Collection<ConstructorArg> args = decl.getConstructorArgs();
        assertEquals("Wrong number of constructor arguments", 2, args.size());
        Iterator<ConstructorArg> it = args.iterator();
        ConstructorArg arg1 = it.next();
View Full Code Here


     * Tests whether a constructor argument with a null value can be defined.
     */
    @Test
    public void testGetConstructorArgsNullArg()
    {
        BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
        config.addProperty(KEY + ".config-constrarg", "");
        XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
        Collection<ConstructorArg> args = decl.getConstructorArgs();
        assertEquals("Wrong number of constructor arguments", 1, args.size());
        ConstructorArg arg = args.iterator().next();
        assertFalse("A bean declaration", arg.isNestedBeanDeclaration());
View Full Code Here

     * Tests whether interpolation is done on constructor arguments.
     */
    @Test
    public void testGetInterpolatedConstructorArgs()
    {
        BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
        String expectedValue = "ctorArg";
        config.addProperty("value", expectedValue);
        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
        config.addProperty(KEY + ".config-constrarg[@config-value]", "${value}");
        XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
        Collection<ConstructorArg> args = decl.getConstructorArgs();
        ConstructorArg arg = args.iterator().next();
        assertEquals("Wrong interpolated value", expectedValue, arg.getValue());
    }
View Full Code Here

     * Tests interpolate() if no ConfigurationInterpolator is available.
     */
    @Test
    public void testInterpolateNoInterpolator()
    {
        BaseHierarchicalConfiguration config = new BaseHierarchicalConfiguration();
        config.addProperty("value", "expectedValue");
        setupBeanDeclaration(config, KEY, TEST_PROPS, TEST_VALUES);
        String value = "${value}";
        config.addProperty(KEY + ".config-constrarg[@config-value]", value);
        config.setInterpolator(null);
        XMLBeanDeclaration decl = new XMLBeanDeclaration(config, KEY);
        Collection<ConstructorArg> args = decl.getConstructorArgs();
        ConstructorArg arg = args.iterator().next();
        assertEquals("Value was changed", value, arg.getValue());
    }
View Full Code Here

     * Tests combination of simple values (no lists).
     */
    @Test
    public void testSimpleValues() throws ConfigurationException
    {
        BaseHierarchicalConfiguration 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.
     */
    @Test
    public void testSimpleValuesWithAttributes() throws ConfigurationException
    {
        BaseHierarchicalConfiguration 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.
     */
    @Test
    public void testAttributes() throws ConfigurationException
    {
        BaseHierarchicalConfiguration config = createCombinedConfiguration();
        assertEquals("Wrong number of attributes", 0, config
                .getMaxIndex("database.tables.table(0)[@id]"));
        assertEquals("Wrong value of attribute", 1, config
                .getInt("database.tables.table(0)[@id](0)"));
    }
View Full Code Here

     * Tests combination of lists.
     */
    @Test
    public void testLists() throws ConfigurationException
    {
        BaseHierarchicalConfiguration 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

     */
    @Test
    public void testTableList() throws ConfigurationException
    {
        combiner.addListNode("table");
        BaseHierarchicalConfiguration 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

     */
    private static ConfigurationDeclaration createDeclaration(
            HierarchicalConfiguration<?> conf)
    {
        HierarchicalConfiguration<?> config =
                (conf != null) ? conf : new BaseHierarchicalConfiguration();
        return new ConfigurationDeclaration(null, config);
    }
View Full Code Here

TOP

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

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.