Package org.apache.commons.configuration2.io

Examples of org.apache.commons.configuration2.io.FileHandler.save()


        File file = folder.newFile("sys.properties");
        PropertiesConfiguration pconfig = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(pconfig);
        pconfig.addProperty("fromFile", Boolean.TRUE);
        handler.setFile(file);
        handler.save();
        SystemConfiguration.setSystemProperties(handler.getBasePath(),
                handler.getFileName());
        SystemConfiguration sconf = new SystemConfiguration();
        assertTrue("Property from file not found", sconf.getBoolean("fromFile"));
    }
View Full Code Here


    {
        String encoding = "UTF-8";
        FileHandler handler = new FileHandler(config);
        handler.setEncoding(encoding);
        StringWriter writer = new StringWriter();
        handler.save(writer);
        assertTrue(
                "Encoding not found",
                writer.toString()
                        .indexOf(
                                "<?xml version=\"1.0\" encoding=\"" + encoding
View Full Code Here

        config.setProperty("mean", "now it's simple");
        config.addProperty("[@topattr]", "available");
        config.addProperty("[@topattr_other]", "successfull");

        File saveFile = folder.newFile(TEST_SAVENAME);
        handler.save(saveFile);
        config = new XMLConfiguration();
        handler = new FileHandler(config);
        handler.load(saveFile.getAbsolutePath());
        assertFalse(config.containsKey("test.entity[@name]"));
        assertEquals("1<2", config.getProperty("test.entity"));
View Full Code Here

    public void testSaveToCustomURL() throws Exception
    {
        // save the configuration to a custom URL
        URL url = new URL("foo", "", 0, "./target/testsave-custom-url.properties", new FileURLStreamHandler());
        FileHandler handlerSave = new FileHandler(conf);
        handlerSave.save(url);

        // reload the configuration
        PropertiesConfiguration config2 = new PropertiesConfiguration();
        FileHandler handlerLoad = new FileHandler(config2);
        handlerLoad.load(url);
View Full Code Here

    @Test(expected = ConfigurationException.class)
    public void testSaveMissingFilename() throws ConfigurationException
    {
        FileHandler handler = new FileHandler(conf);
        handler.save();
    }

    /**
     * Tests if the base path is taken into account by the save() method.
     */
 
View Full Code Here

        conf.setProperty("test", "true");
        FileHandler handler = new FileHandler(conf);
        handler.setBasePath(testSavePropertiesFile.getParentFile().toURI().toURL()
                .toString());
        handler.setFileName(testSavePropertiesFile.getName());
        handler.save();
        assertTrue(testSavePropertiesFile.exists());
    }

    /**
     * Tests whether the escape character for list delimiters can be itself
View Full Code Here

        PropertiesConfiguration conf = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(conf);
        handler.setFile(file);
        handler.load();
        handler.save();

        assertTrue("Missing file " + file, file.exists());
    }

    /**
 
View Full Code Here

        final String testProperty = "test.successfull";
        conf = new PropertiesConfiguration();
        FileHandler handler = new FileHandler(conf);
        handler.setFile(testSavePropertiesFile);
        conf.addProperty(testProperty, "true");
        handler.save();
        checkSavedConfig();
    }

    /**
     * Tests copying another configuration into the test configuration. This
View Full Code Here

        handler.setFile(testSavePropertiesFile);
        DataConfiguration dataConfig = new DataConfiguration(conf);
        dataConfig.setProperty("foo", "bar");
        assertEquals("Property not set", "bar", conf.getString("foo"));

        handler.save();
        PropertiesConfiguration config2 = new PropertiesConfiguration();
        load(config2, testSavePropertiesFile.getAbsolutePath());
        assertEquals("Property not saved", "bar", config2.getString("foo"));
    }
View Full Code Here

     * @throws ConfigurationException if an error occurs
     */
    private void saveTestConfig() throws ConfigurationException
    {
        FileHandler handler = new FileHandler(conf);
        handler.save(testSavePropertiesFile);
    }

    /**
     * A dummy layout implementation for checking whether certain methods are
     * correctly called by the configuration.
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.