Package org.apache.commons.configuration2.io

Examples of org.apache.commons.configuration2.io.FileHandler$Updater


    }

    @Test
    public void testSave() throws Exception
    {
        FileHandler handler = new FileHandler(config);
        handler.setFileName(TEST_FILE3);
        handler.load();
        File saveFile = folder.newFile(TEST_SAVENAME);
        handler.save(saveFile);

        config = new XMLConfiguration();
        FileHandler handler2 = new FileHandler(config);
        handler2.load(saveFile.toURI().toURL());
        assertEquals("value", config.getProperty("element"));
        assertEquals("I'm complex!", config.getProperty("element2.subelement.subsubelement"));
        assertEquals(8, config.getInt("test.short"));
        assertEquals("one", config.getString("list(0).item(0)[@name]"));
        assertEquals("two", config.getString("list(0).item(1)"));
View Full Code Here


        config.addProperty("tables.table(1).fields.field(1).type", "string");
        config.addProperty("tables.table(1).fields.field(1)[@null]", "true");

        config.setRootElementName("myconfig");
        File saveFile = folder.newFile(TEST_SAVENAME);
        FileHandler handler = new FileHandler(config);
        handler.setFile(saveFile);
        handler.save();

        config = new XMLConfiguration();
        handler = new FileHandler(config);
        handler.load(saveFile);
        assertEquals(1, config.getMaxIndex("tables.table.name"));
        assertEquals("tests", config.getString("tables.table(0).name"));
        assertEquals("test_name", config.getString("tables.table(0).fields.field(1).name"));
        assertEquals("int", config.getString("tables.table(1).fields.field(0).type"));
        assertTrue(config.getBoolean("tables.table(1).fields.field(1)[@null]"));
View Full Code Here

     * @throws ConfigurationException if an error occurs
     */
    private static void load(XMLConfiguration config, String fileName)
            throws ConfigurationException
    {
        FileHandler handler = new FileHandler(config);
        handler.setFileName(fileName);
        handler.load();
    }
View Full Code Here

    @Test
    public void testLoadFromStream() throws Exception
    {
        String xml = "<?xml version=\"1.0\"?><config><test>1</test></config>";
        conf = new XMLConfiguration();
        FileHandler handler = new FileHandler(conf);
        handler.load(new ByteArrayInputStream(xml.getBytes()));
        assertEquals(1, conf.getInt("test"));

        conf = new XMLConfiguration();
        handler = new FileHandler(conf);
        handler.load(new ByteArrayInputStream(xml.getBytes()), "UTF8");
        assertEquals(1, conf.getInt("test"));
    }
View Full Code Here

    @Test(expected = ConfigurationException.class)
    public void testLoadInvalidXML() throws Exception
    {
        String xml = "<?xml version=\"1.0\"?><config><test>1</rest></config>";
        conf = new XMLConfiguration();
        FileHandler handler = new FileHandler(conf);
        handler.load(new StringReader(xml));
    }
View Full Code Here

     * Tests saving to a URL.
     */
    @Test
    public void testSaveToURL() throws Exception
    {
        FileHandler handler = new FileHandler(conf);
        handler.save(testSaveConf.toURI().toURL());
        checkSavedConfig(testSaveConf);
    }
View Full Code Here

     */
    @Test
    public void testSaveToStream() throws ConfigurationException, IOException
    {
        FileOutputStream out = null;
        FileHandler handler = new FileHandler(conf);
        try
        {
            out = new FileOutputStream(testSaveConf);
            handler.save(out, "UTF8");
        }
        finally
        {
            if(out != null)
            {
View Full Code Here

     * Tests whether a configuration can be saved to a stream with a specific encoding.
     */
    @Test
    public void testSaveToStreamWithEncoding() throws ConfigurationException, IOException
    {
        FileHandler handler = new FileHandler(conf);
        handler.setEncoding("UTF8");
        FileOutputStream out = null;
        try
        {
            out = new FileOutputStream(testSaveConf);
            handler.save(out);
        }
        finally
        {
            if(out != null)
            {
View Full Code Here

    public void testCloneWithSave() throws ConfigurationException
    {
        XMLConfiguration c = (XMLConfiguration) conf.clone();
        c.addProperty("test.newProperty", Boolean.TRUE);
        conf.addProperty("test.orgProperty", Boolean.TRUE);
        new FileHandler(c).save(testSaveConf);
        XMLConfiguration c2 = new XMLConfiguration();
        load(c2, testSaveConf.getAbsolutePath());
        assertTrue("New property after clone() was not saved", c2
                .getBoolean("test.newProperty"));
        assertFalse("Property of original config was saved", c2
View Full Code Here

        XMLConfiguration config = new XMLConfiguration();
        //config.setExpressionEngine(new XPathExpressionEngine());
        load(config, testFile2);
        config.setProperty("Employee[@attr1]", "3,2,1");
        assertEquals("3,2,1", config.getString("Employee[@attr1]"));
        new FileHandler(config).save(testSaveFile);
        config = new XMLConfiguration();
        //config.setExpressionEngine(new XPathExpressionEngine());
        load(config, testSaveFile.getAbsolutePath());
        config.setProperty("Employee[@attr1]", "1,2,3");
        assertEquals("1,2,3", config.getString("Employee[@attr1]"));
        config.setProperty("Employee[@attr2]", "one, two, three");
        assertEquals("one, two, three", config.getString("Employee[@attr2]"));
        config.setProperty("Employee.text", "a,b,d");
        assertEquals("a,b,d", config.getString("Employee.text"));
        config.setProperty("Employee.Salary", "100,000");
        assertEquals("100,000", config.getString("Employee.Salary"));
        new FileHandler(config).save(testSaveFile);
        XMLConfiguration checkConfig = new XMLConfiguration();
        checkConfig.setExpressionEngine(new XPathExpressionEngine());
        load(checkConfig, testSaveFile.getAbsolutePath());
        assertEquals("1,2,3", checkConfig.getString("Employee/@attr1"));
        assertEquals("one, two, three", checkConfig.getString("Employee/@attr2"));
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration2.io.FileHandler$Updater

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.